Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.d @ 85:6be48cf9f95c
Work on databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Apr 2009 13:54:50 +0200 |
parents | 383ce7bd736b |
children | 9e0ab372d5d8 |
comparison
equal
deleted
inserted
replaced
84:fcf926c91ca4 | 85:6be48cf9f95c |
---|---|
11 | 11 |
12 module org.eclipse.core.internal.databinding.conversion.StringToShortConverter; | 12 module org.eclipse.core.internal.databinding.conversion.StringToShortConverter; |
13 import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; | 13 import org.eclipse.core.internal.databinding.conversion.StringToNumberParser; |
14 | 14 |
15 import java.lang.all; | 15 import java.lang.all; |
16 import java.nonstandard.RuntimeTraits; | |
16 | 17 |
17 import org.eclipse.core.internal.databinding.conversion.StringToNumberParser.ParseResult; | |
18 import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; | 18 import org.eclipse.core.internal.databinding.validation.NumberFormatConverter; |
19 | 19 |
20 import com.ibm.icu.text.NumberFormat; | 20 import com.ibm.icu.text.NumberFormat; |
21 | 21 |
22 /** | 22 /** |
29 private String outOfRangeMessage; | 29 private String outOfRangeMessage; |
30 | 30 |
31 /** | 31 /** |
32 * Constructs a new instance. | 32 * Constructs a new instance. |
33 */ | 33 */ |
34 private this(NumberFormat numberFormat, ClassInfo toType) { | 34 private this(NumberFormat numberFormat, TypeInfo toType) { |
35 super(String.classinfo, toType, numberFormat); | 35 super(typeid(String), toType, numberFormat); |
36 this.numberFormat = numberFormat; | 36 this.numberFormat = numberFormat; |
37 primitive = toType.isPrimitive(); | 37 primitive = isJavaPrimitive(toType); |
38 } | 38 } |
39 | 39 |
40 /* | 40 /* |
41 * (non-Javadoc) | 41 * (non-Javadoc) |
42 * | 42 * |
43 * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) | 43 * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) |
44 */ | 44 */ |
45 public Object convert(Object fromObject) { | 45 public Object convert(Object fromObject) { |
46 ParseResult result = StringToNumberParser.parse(fromObject, | 46 StringToNumberParser.ParseResult result = StringToNumberParser.parse(fromObject, |
47 numberFormat, primitive); | 47 numberFormat, primitive); |
48 | 48 |
49 if (result.getPosition() !is null) { | 49 if (result.getPosition() !is null) { |
50 // this shouldn't happen in the pipeline as validation should catch | 50 // this shouldn't happen in the pipeline as validation should catch |
51 // it but anyone can call convert so we should return a properly | 51 // it but anyone can call convert so we should return a properly |
52 // formatted message in an exception | 52 // formatted message in an exception |
53 throw new IllegalArgumentException(StringToNumberParser | 53 throw new IllegalArgumentException(StringToNumberParser |
54 .createParseErrorMessage(cast(String) fromObject, result | 54 .createParseErrorMessage(stringcast( fromObject), result |
55 .getPosition())); | 55 .getPosition())); |
56 } else if (result.getNumber() is null) { | 56 } else if (result.getNumber() is null) { |
57 // if an error didn't occur and the number is null then it's a boxed | 57 // if an error didn't occur and the number is null then it's a boxed |
58 // type and null should be returned | 58 // type and null should be returned |
59 return null; | 59 return null; |
64 } | 64 } |
65 | 65 |
66 synchronized (this) { | 66 synchronized (this) { |
67 if (outOfRangeMessage is null) { | 67 if (outOfRangeMessage is null) { |
68 outOfRangeMessage = StringToNumberParser | 68 outOfRangeMessage = StringToNumberParser |
69 .createOutOfRangeMessage(new Shortcast(Short.MIN_VALUE), new Shortcast(Short.MAX_VALUE), numberFormat); | 69 .createOutOfRangeMessage(new Short(Short.MIN_VALUE), new Short(Short.MAX_VALUE), numberFormat); |
70 } | 70 } |
71 | 71 |
72 throw new IllegalArgumentException(outOfRangeMessage); | 72 throw new IllegalArgumentException(outOfRangeMessage); |
73 } | 73 } |
74 } | 74 } |
88 * @return to Short converter with the provided numberFormat | 88 * @return to Short converter with the provided numberFormat |
89 */ | 89 */ |
90 public static StringToShortConverter toShort(NumberFormat numberFormat, | 90 public static StringToShortConverter toShort(NumberFormat numberFormat, |
91 bool primitive) { | 91 bool primitive) { |
92 return new StringToShortConverter(numberFormat, | 92 return new StringToShortConverter(numberFormat, |
93 (primitive) ? Short.TYPE : Short.classinfo); | 93 (primitive) ? Short.TYPE : typeid(Short)); |
94 } | 94 } |
95 } | 95 } |