Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.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.StringToByteConverter; | 12 module org.eclipse.core.internal.databinding.conversion.StringToByteConverter; |
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 | 29 |
30 /** | 30 /** |
31 * @param numberFormat | 31 * @param numberFormat |
32 * @param toType | 32 * @param toType |
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(StringCls), toType, numberFormat); |
36 primitive = toType.isPrimitive(); | 36 primitive = isJavaPrimitive(cast(TypeInfo)toType); |
37 this.numberFormat = numberFormat; | 37 this.numberFormat = numberFormat; |
38 } | 38 } |
39 | 39 |
40 /** | 40 /** |
41 * @param numberFormat | 41 * @param numberFormat |
42 * @param primitive | 42 * @param primitive |
43 * @return converter | 43 * @return converter |
44 */ | 44 */ |
45 public static StringToByteConverter toByte(NumberFormat numberFormat, | 45 public static StringToByteConverter toByte(NumberFormat numberFormat, |
46 bool primitive) { | 46 bool primitive) { |
47 return new StringToByteConverter(numberFormat, (primitive) ? Byte.TYPE : Byte.classinfo); | 47 return new StringToByteConverter(numberFormat, (primitive) ? Byte.TYPE : typeid(Byte)); |
48 } | 48 } |
49 | 49 |
50 /** | 50 /** |
51 * @param primitive | 51 * @param primitive |
52 * @return converter | 52 * @return converter |
57 | 57 |
58 /* (non-Javadoc) | 58 /* (non-Javadoc) |
59 * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) | 59 * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object) |
60 */ | 60 */ |
61 public Object convert(Object fromObject) { | 61 public Object convert(Object fromObject) { |
62 ParseResult result = StringToNumberParser.parse(fromObject, | 62 StringToNumberParser.ParseResult result = StringToNumberParser.parse(fromObject, |
63 numberFormat, primitive); | 63 numberFormat, primitive); |
64 | 64 |
65 if (result.getPosition() !is null) { | 65 if (result.getPosition() !is null) { |
66 // this shouldn't happen in the pipeline as validation should catch | 66 // this shouldn't happen in the pipeline as validation should catch |
67 // it but anyone can call convert so we should return a properly | 67 // it but anyone can call convert so we should return a properly |
68 // formatted message in an exception | 68 // formatted message in an exception |
69 throw new IllegalArgumentException(StringToNumberParser | 69 throw new IllegalArgumentException(StringToNumberParser |
70 .createParseErrorMessage(cast(String) fromObject, result | 70 .createParseErrorMessage(stringcast(fromObject), result |
71 .getPosition())); | 71 .getPosition())); |
72 } else if (result.getNumber() is null) { | 72 } else if (result.getNumber() is null) { |
73 // if an error didn't occur and the number is null then it's a boxed | 73 // if an error didn't occur and the number is null then it's a boxed |
74 // type and null should be returned | 74 // type and null should be returned |
75 return null; | 75 return null; |
80 } | 80 } |
81 | 81 |
82 synchronized (this) { | 82 synchronized (this) { |
83 if (outOfRangeMessage is null) { | 83 if (outOfRangeMessage is null) { |
84 outOfRangeMessage = StringToNumberParser | 84 outOfRangeMessage = StringToNumberParser |
85 .createOutOfRangeMessage(new Bytecast(Byte.MIN_VALUE), new Bytecast(Byte.MAX_VALUE), numberFormat); | 85 .createOutOfRangeMessage(new Byte(Byte.MIN_VALUE), new Byte(Byte.MAX_VALUE), numberFormat); |
86 } | 86 } |
87 | 87 |
88 throw new IllegalArgumentException(outOfRangeMessage); | 88 throw new IllegalArgumentException(outOfRangeMessage); |
89 } | 89 } |
90 } | 90 } |