Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.d @ 88:9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 19 Apr 2009 11:10:09 +0200 |
parents | 6be48cf9f95c |
children |
comparison
equal
deleted
inserted
replaced
87:8594250b1d1c | 88:9e0ab372d5d8 |
---|---|
11 *******************************************************************************/ | 11 *******************************************************************************/ |
12 | 12 |
13 module org.eclipse.core.internal.databinding.validation.ObjectToPrimitiveValidator; | 13 module org.eclipse.core.internal.databinding.validation.ObjectToPrimitiveValidator; |
14 | 14 |
15 import java.lang.all; | 15 import java.lang.all; |
16 import java.nonstandard.RuntimeTraits; | |
17 | 16 |
18 import org.eclipse.core.databinding.validation.IValidator; | 17 import org.eclipse.core.databinding.validation.IValidator; |
19 import org.eclipse.core.databinding.validation.ValidationStatus; | 18 import org.eclipse.core.databinding.validation.ValidationStatus; |
20 import org.eclipse.core.internal.databinding.BindingMessages; | 19 import org.eclipse.core.internal.databinding.BindingMessages; |
21 import org.eclipse.core.runtime.IStatus; | 20 import org.eclipse.core.runtime.IStatus; |
25 * @since 3.2 | 24 * @since 3.2 |
26 * | 25 * |
27 */ | 26 */ |
28 public class ObjectToPrimitiveValidator : IValidator { | 27 public class ObjectToPrimitiveValidator : IValidator { |
29 | 28 |
30 private TypeInfo toType; | 29 private Class toType; |
31 | 30 |
32 private static TypeInfo[][] primitiveMap; | 31 private static Class[][] primitiveMap; |
33 static this(){ | 32 static this(){ |
34 primitiveMap = [ | 33 primitiveMap = [ |
35 [ Integer.TYPE, typeid(Integer) ], [ Short.TYPE, typeid(Short) ], | 34 [ Integer.TYPE, Class.fromType!(Integer) ], [ Short.TYPE, Class.fromType!(Short) ], |
36 [ Long.TYPE, typeid(Long) ], [ Double.TYPE, typeid(Double) ], | 35 [ Long.TYPE, Class.fromType!(Long) ], [ Double.TYPE, Class.fromType!(Double) ], |
37 [ Byte.TYPE, typeid(Byte) ], [ Float.TYPE, typeid(Float) ], | 36 [ Byte.TYPE, Class.fromType!(Byte) ], [ Float.TYPE, Class.fromType!(Float) ], |
38 [ Boolean.TYPE, typeid(Boolean) ], | 37 [ Boolean.TYPE, Class.fromType!(Boolean) ], |
39 [ Character.TYPE, typeid(Character) ] ]; | 38 [ Character.TYPE, Class.fromType!(Character) ] ]; |
40 } | 39 } |
41 | 40 |
42 /** | 41 /** |
43 * @param toType | 42 * @param toType |
44 */ | 43 */ |
45 public this(TypeInfo toType) { | 44 public this(Class toType) { |
46 this.toType = toType; | 45 this.toType = toType; |
47 } | 46 } |
48 | 47 |
49 protected TypeInfo getToType() { | 48 protected Class getToType() { |
50 return this.toType; | 49 return this.toType; |
51 } | 50 } |
52 | 51 |
53 public IStatus validate(Object value) { | 52 public IStatus validate(Object value) { |
54 return doValidate(value); | 53 return doValidate(value); |
55 } | 54 } |
56 | 55 |
57 private IStatus doValidate(Object value) { | 56 private IStatus doValidate(Object value) { |
58 if (value !is null) { | 57 if (value !is null) { |
59 if (!mapContainsValues(toType, getTypeInfo(value.classinfo))) { | 58 if (!mapContainsValues(toType, Class.fromObject(value))) { |
60 return ValidationStatus.error(getClassHint()); | 59 return ValidationStatus.error(getClassHint()); |
61 } | 60 } |
62 return Status.OK_STATUS; | 61 return Status.OK_STATUS; |
63 } | 62 } |
64 return ValidationStatus.error(getNullHint()); | 63 return ValidationStatus.error(getNullHint()); |
65 } | 64 } |
66 | 65 |
67 private bool mapContainsValues(TypeInfo toType, TypeInfo fromType) { | 66 private bool mapContainsValues(Class toType, Class fromType) { |
68 for (int i = 0; i < primitiveMap.length; i++) { | 67 for (int i = 0; i < primitiveMap.length; i++) { |
69 if ((primitiveMap[i][0] == toType ) | 68 if ((primitiveMap[i][0] == toType ) |
70 && (primitiveMap[i][1] == fromType )) { | 69 && (primitiveMap[i][1] == fromType )) { |
71 return true; | 70 return true; |
72 } | 71 } |