Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.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 | 0ca1aee7decf |
comparison
equal
deleted
inserted
replaced
87:8594250b1d1c | 88:9e0ab372d5d8 |
---|---|
10 ******************************************************************************/ | 10 ******************************************************************************/ |
11 | 11 |
12 module org.eclipse.core.internal.databinding.conversion.IntegerToStringConverter; | 12 module org.eclipse.core.internal.databinding.conversion.IntegerToStringConverter; |
13 | 13 |
14 import java.lang.all; | 14 import java.lang.all; |
15 import java.nonstandard.RuntimeTraits; | |
16 | 15 |
17 import org.eclipse.core.databinding.conversion.Converter; | 16 import org.eclipse.core.databinding.conversion.Converter; |
18 | 17 |
19 import com.ibm.icu.text.NumberFormat; | 18 import com.ibm.icu.text.NumberFormat; |
20 | 19 |
29 * @since 1.0 | 28 * @since 1.0 |
30 */ | 29 */ |
31 public class IntegerToStringConverter : Converter { | 30 public class IntegerToStringConverter : Converter { |
32 private final bool primitive; | 31 private final bool primitive; |
33 private final NumberFormat numberFormat; | 32 private final NumberFormat numberFormat; |
34 private final TypeInfo boxedType; | 33 private final Class boxedType; |
35 | 34 |
36 /** | 35 /** |
37 * @param numberFormat | 36 * @param numberFormat |
38 * @param fromType | 37 * @param fromType |
39 * @param boxedType | 38 * @param boxedType |
40 */ | 39 */ |
41 private this(NumberFormat numberFormat, TypeInfo fromType, | 40 private this(NumberFormat numberFormat, Class fromType, |
42 TypeInfo boxedType) { | 41 Class boxedType) { |
43 super(fromType, typeid(StringCls)); | 42 super(fromType, Class.fromType!(StringCls)); |
44 this.primitive = isJavaPrimitive(fromType); | 43 this.primitive = fromType.isPrimitive(); |
45 this.numberFormat = numberFormat; | 44 this.numberFormat = numberFormat; |
46 this.boxedType = boxedType; | 45 this.boxedType = boxedType; |
47 } | 46 } |
48 | 47 |
49 /* | 48 /* |
55 // Null is allowed when the type is not primitve. | 54 // Null is allowed when the type is not primitve. |
56 if (fromObject is null && !primitive) { | 55 if (fromObject is null && !primitive) { |
57 return stringcast(""); //$NON-NLS-1$ | 56 return stringcast(""); //$NON-NLS-1$ |
58 } | 57 } |
59 | 58 |
60 if (!isImplicitly(fromObject.classinfo, boxedType.classinfo)) { | 59 //FIXME check with org |
60 if (!Class.fromObject(boxedType).isAssignableFrom(Class.fromObject(fromObject))) { | |
61 throw new IllegalArgumentException( | 61 throw new IllegalArgumentException( |
62 Format("'fromObject' is not of type [{}].", boxedType)); //$NON-NLS-1$//$NON-NLS-2$ | 62 Format("'fromObject' is not of type [{}].", boxedType)); //$NON-NLS-1$//$NON-NLS-2$ |
63 } | 63 } |
64 | 64 |
65 return stringcast(numberFormat.format((cast(Number) fromObject).longValue())); | 65 return stringcast(numberFormat.format((cast(Number) fromObject).longValue())); |
79 * @return converter | 79 * @return converter |
80 */ | 80 */ |
81 public static IntegerToStringConverter fromShort(NumberFormat numberFormat, | 81 public static IntegerToStringConverter fromShort(NumberFormat numberFormat, |
82 bool primitive) { | 82 bool primitive) { |
83 return new IntegerToStringConverter(numberFormat, | 83 return new IntegerToStringConverter(numberFormat, |
84 primitive ? Short.TYPE : typeid(Short), typeid(Short)); | 84 primitive ? Short.TYPE : Class.fromType!(Short), Class.fromType!(Short)); |
85 } | 85 } |
86 | 86 |
87 /** | 87 /** |
88 * @param primitive | 88 * @param primitive |
89 * @return converter | 89 * @return converter |
98 * @return converter | 98 * @return converter |
99 */ | 99 */ |
100 public static IntegerToStringConverter fromByte(NumberFormat numberFormat, | 100 public static IntegerToStringConverter fromByte(NumberFormat numberFormat, |
101 bool primitive) { | 101 bool primitive) { |
102 return new IntegerToStringConverter(numberFormat, primitive ? Byte.TYPE | 102 return new IntegerToStringConverter(numberFormat, primitive ? Byte.TYPE |
103 : typeid(Byte), typeid(Byte)); | 103 : Class.fromType!(Byte), Class.fromType!(Byte)); |
104 } | 104 } |
105 } | 105 } |