comparison org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.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
13 13
14 module org.eclipse.core.databinding.UpdateStrategy; 14 module org.eclipse.core.databinding.UpdateStrategy;
15 import org.eclipse.core.databinding.BindingException; 15 import org.eclipse.core.databinding.BindingException;
16 16
17 import java.lang.all; 17 import java.lang.all;
18 import java.nonstandard.RuntimeTraits;
19 18
20 import java.math.BigDecimal; 19 import java.math.BigDecimal;
21 import java.math.BigInteger; 20 import java.math.BigInteger;
22 import java.util.HashMap; 21 import java.util.HashMap;
23 import java.util.Map; 22 import java.util.Map;
70 69
71 private static final String CHARACTER_TYPE = "java.lang.Character.TYPE"; //$NON-NLS-1$ 70 private static final String CHARACTER_TYPE = "java.lang.Character.TYPE"; //$NON-NLS-1$
72 71
73 private static Map converterMap; 72 private static Map converterMap;
74 73
75 private static TypeInfo autoboxed(TypeInfo clazz) { 74 private static Class autoboxed(Class clazz) {
76 if (clazz is Float.TYPE) 75 if (clazz is Float.TYPE)
77 return typeid(Float); 76 return Class.fromType!(Float);
78 else if (clazz is Double.TYPE) 77 else if (clazz is Double.TYPE)
79 return typeid(Double); 78 return Class.fromType!(Double);
80 else if (clazz is Short.TYPE) 79 else if (clazz is Short.TYPE)
81 return typeid(Short); 80 return Class.fromType!(Short);
82 else if (clazz is Integer.TYPE) 81 else if (clazz is Integer.TYPE)
83 return typeid(Integer); 82 return Class.fromType!(Integer);
84 else if (clazz is Long.TYPE) 83 else if (clazz is Long.TYPE)
85 return typeid(Long); 84 return Class.fromType!(Long);
86 else if (clazz is Byte.TYPE) 85 else if (clazz is Byte.TYPE)
87 return typeid(Byte); 86 return Class.fromType!(Byte);
88 else if (clazz is Boolean.TYPE) 87 else if (clazz is Boolean.TYPE)
89 return typeid(Boolean); 88 return Class.fromType!(Boolean);
90 else if (clazz is Character.TYPE) 89 else if (clazz is Character.TYPE)
91 return typeid(Character); 90 return Class.fromType!(Character);
92 return clazz; 91 return clazz;
93 } 92 }
94 93
95 final protected void checkAssignable(Object toType, Object fromType, 94 final protected void checkAssignable(Object toType, Object fromType,
96 String errorString) { 95 String errorString) {
112 * @param fromType 111 * @param fromType
113 * @param toType 112 * @param toType
114 * @return an IConverter, or <code>null</code> if unsuccessful 113 * @return an IConverter, or <code>null</code> if unsuccessful
115 */ 114 */
116 protected IConverter createConverter(Object fromType, Object toType) { 115 protected IConverter createConverter(Object fromType, Object toType) {
117 if (!( null !is cast(TypeInfo)fromType ) || !( null !is cast(TypeInfo)toType )) { 116 if (!( null !is cast(Class)fromType ) || !( null !is cast(Class)toType )) {
118 return new DefaultConverter(fromType, toType); 117 return new DefaultConverter(fromType, toType);
119 } 118 }
120 TypeInfo toClass = cast(TypeInfo) toType; 119 Class toClass = cast(Class) toType;
121 TypeInfo originalToClass = toClass; 120 Class originalToClass = toClass;
122 if (isJavaPrimitive(toClass)) { 121 if (toClass.isPrimitive()) {
123 toClass = autoboxed(toClass); 122 toClass = autoboxed(toClass);
124 } 123 }
125 TypeInfo fromClass = cast(TypeInfo) fromType; 124 Class fromClass = cast(Class) fromType;
126 TypeInfo originalFromClass = fromClass; 125 Class originalFromClass = fromClass;
127 if (isJavaPrimitive(fromClass)) { 126 if (fromClass.isPrimitive()) {
128 fromClass = autoboxed(fromClass); 127 fromClass = autoboxed(fromClass);
129 } 128 }
130 if (!isJavaPrimitive(cast(TypeInfo) toType) 129 if (!(cast(Class) toType).isPrimitive()
131 && isImplicitly(fromClass, toClass)) { 130 && toClass.isAssignableFrom(fromClass)) {
132 return new IdentityConverter(originalFromClass, originalToClass); 131 return new IdentityConverter(originalFromClass, originalToClass);
133 } 132 }
134 if (isJavaPrimitive(cast(TypeInfo) fromType) && isJavaPrimitive(cast(TypeInfo) toType) 133 if ((cast(Class) fromType).isPrimitive() && (cast(Class) toType).isPrimitive()
135 && fromType.opEquals(toType)) { 134 && fromType.opEquals(toType)) {
136 return new IdentityConverter(originalFromClass, originalToClass); 135 return new IdentityConverter(originalFromClass, originalToClass);
137 } 136 }
138 Map converterMap = getConverterMap(); 137 Map converterMap = getConverterMap();
139 TypeInfo[] supertypeHierarchyFlattened = ClassLookupSupport 138 Class[] supertypeHierarchyFlattened = ClassLookupSupport
140 .getTypeHierarchyFlattened(fromClass); 139 .getTypeHierarchyFlattened(fromClass);
141 for (int i = 0; i < supertypeHierarchyFlattened.length; i++) { 140 for (int i = 0; i < supertypeHierarchyFlattened.length; i++) {
142 TypeInfo currentFromClass = supertypeHierarchyFlattened[i]; 141 Class currentFromClass = supertypeHierarchyFlattened[i];
143 if (currentFromClass is toType) { 142 if (currentFromClass is toType) {
144 // converting to toType is just a widening 143 // converting to toType is just a widening
145 return new IdentityConverter(fromClass, toClass); 144 return new IdentityConverter(fromClass, toClass);
146 } 145 }
147 Pair key = new Pair(stringcast(getKeyForClass(fromType, currentFromClass)), 146 Pair key = new Pair(stringcast(getKeyForClass(fromType, currentFromClass)),
149 Object converterOrClassname = converterMap.get(key); 148 Object converterOrClassname = converterMap.get(key);
150 if ( null !is cast(IConverter)converterOrClassname ) { 149 if ( null !is cast(IConverter)converterOrClassname ) {
151 return cast(IConverter) converterOrClassname; 150 return cast(IConverter) converterOrClassname;
152 } else if ( null !is cast(ArrayWrapperString)converterOrClassname ) { 151 } else if ( null !is cast(ArrayWrapperString)converterOrClassname ) {
153 String classname = stringcast( converterOrClassname); 152 String classname = stringcast( converterOrClassname);
154 ClassInfo converterClass; 153 Class converterClass;
155 try { 154 try {
156 converterClass = ClassInfo.find(classname); 155 converterClass = Class.forName(classname);
157 IConverter result = cast(IConverter) converterClass 156 IConverter result = cast(IConverter) converterClass
158 .create(); 157 .newInstance();
159 converterMap.put(stringcast(key), cast(Object)result); 158 converterMap.put(stringcast(key), cast(Object)result);
160 return result; 159 return result;
161 } catch (Exception e) { 160 } catch (Exception e) {
162 Policy 161 Policy
163 .getLog() 162 .getLog()
171 } 170 }
172 } 171 }
173 // Since we found no converter yet, try a "downcast" converter; 172 // Since we found no converter yet, try a "downcast" converter;
174 // the IdentityConverter will automatically check the actual types at 173 // the IdentityConverter will automatically check the actual types at
175 // runtime. 174 // runtime.
176 if (isImplicitly(toClass, fromClass)) { 175 if (fromClass.isAssignableFrom(toClass)) {
177 return new IdentityConverter(originalFromClass, originalToClass); 176 return new IdentityConverter(originalFromClass, originalToClass);
178 } 177 }
179 return new DefaultConverter(fromType, toType); 178 return new DefaultConverter(fromType, toType);
180 } 179 }
181 180
257 converterMap 256 converterMap
258 .put( 257 .put(
259 new Pair("java.lang.String", INTEGER_TYPE), StringToNumberConverter.toInteger(integerFormat, true)); //$NON-NLS-1$ 258 new Pair("java.lang.String", INTEGER_TYPE), StringToNumberConverter.toInteger(integerFormat, true)); //$NON-NLS-1$
260 converterMap 259 converterMap
261 .put( 260 .put(
262 new Pair(INTEGER_TYPE, "java.lang.Integer"), new IdentityConverter(Integer.TYPE, typeid(Integer))); //$NON-NLS-1$ 261 new Pair(INTEGER_TYPE, "java.lang.Integer"), new IdentityConverter(Integer.TYPE, Class.fromType!(Integer))); //$NON-NLS-1$
263 converterMap 262 converterMap
264 .put( 263 .put(
265 new Pair(INTEGER_TYPE, "java.lang.Object"), new IdentityConverter(Integer.TYPE, typeid(Object))); //$NON-NLS-1$ 264 new Pair(INTEGER_TYPE, "java.lang.Object"), new IdentityConverter(Integer.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
266 converterMap 265 converterMap
267 .put( 266 .put(
268 new Pair(INTEGER_TYPE, "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, true)); //$NON-NLS-1$ 267 new Pair(INTEGER_TYPE, "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, true)); //$NON-NLS-1$
269 268
270 // Byte.TYPE 269 // Byte.TYPE
271 converterMap 270 converterMap
272 .put( 271 .put(
273 new Pair("java.lang.String", BYTE_TYPE), StringToByteConverter.toByte(integerFormat, true)); //$NON-NLS-1$ 272 new Pair("java.lang.String", BYTE_TYPE), StringToByteConverter.toByte(integerFormat, true)); //$NON-NLS-1$
274 converterMap 273 converterMap
275 .put( 274 .put(
276 new Pair(BYTE_TYPE, "java.lang.Byte"), new IdentityConverter(Byte.TYPE, typeid(Byte))); //$NON-NLS-1$ 275 new Pair(BYTE_TYPE, "java.lang.Byte"), new IdentityConverter(Byte.TYPE, Class.fromType!(Byte))); //$NON-NLS-1$
277 converterMap 276 converterMap
278 .put( 277 .put(
279 new Pair(BYTE_TYPE, "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, true)); //$NON-NLS-1$ 278 new Pair(BYTE_TYPE, "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, true)); //$NON-NLS-1$
280 converterMap 279 converterMap
281 .put( 280 .put(
282 new Pair(BYTE_TYPE, "java.lang.Object"), new IdentityConverter(Byte.TYPE, typeid(Object))); //$NON-NLS-1$ 281 new Pair(BYTE_TYPE, "java.lang.Object"), new IdentityConverter(Byte.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
283 282
284 // Double.TYPE 283 // Double.TYPE
285 converterMap 284 converterMap
286 .put( 285 .put(
287 new Pair("java.lang.String", DOUBLE_TYPE), StringToNumberConverter.toDouble(numberFormat, true)); //$NON-NLS-1$ 286 new Pair("java.lang.String", DOUBLE_TYPE), StringToNumberConverter.toDouble(numberFormat, true)); //$NON-NLS-1$
289 .put( 288 .put(
290 new Pair(DOUBLE_TYPE, "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, true)); //$NON-NLS-1$ 289 new Pair(DOUBLE_TYPE, "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, true)); //$NON-NLS-1$
291 290
292 converterMap 291 converterMap
293 .put( 292 .put(
294 new Pair(DOUBLE_TYPE, "java.lang.Double"), new IdentityConverter(Double.TYPE, typeid(Double))); //$NON-NLS-1$ 293 new Pair(DOUBLE_TYPE, "java.lang.Double"), new IdentityConverter(Double.TYPE, Class.fromType!(Double))); //$NON-NLS-1$
295 converterMap 294 converterMap
296 .put( 295 .put(
297 new Pair(DOUBLE_TYPE, "java.lang.Object"), new IdentityConverter(Double.TYPE, typeid(Object))); //$NON-NLS-1$ 296 new Pair(DOUBLE_TYPE, "java.lang.Object"), new IdentityConverter(Double.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
298 297
299 // Boolean.TYPE 298 // Boolean.TYPE
300 converterMap 299 converterMap
301 .put( 300 .put(
302 new Pair("java.lang.String", BOOLEAN_TYPE), "org.eclipse.core.internal.databinding.conversion.StringToBooleanPrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$ 301 new Pair("java.lang.String", BOOLEAN_TYPE), "org.eclipse.core.internal.databinding.conversion.StringToBooleanPrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$
303 converterMap 302 converterMap
304 .put( 303 .put(
305 new Pair(BOOLEAN_TYPE, "java.lang.Boolean"), new IdentityConverter(Boolean.TYPE, typeid(Boolean))); //$NON-NLS-1$ 304 new Pair(BOOLEAN_TYPE, "java.lang.Boolean"), new IdentityConverter(Boolean.TYPE, Class.fromType!(Boolean))); //$NON-NLS-1$
306 converterMap 305 converterMap
307 .put( 306 .put(
308 new Pair(BOOLEAN_TYPE, "java.lang.String"), new ObjectToStringConverter(Boolean.TYPE)); //$NON-NLS-1$ 307 new Pair(BOOLEAN_TYPE, "java.lang.String"), new ObjectToStringConverter(Boolean.TYPE)); //$NON-NLS-1$
309 converterMap 308 converterMap
310 .put( 309 .put(
311 new Pair(BOOLEAN_TYPE, "java.lang.Object"), new IdentityConverter(Boolean.TYPE, typeid(Object))); //$NON-NLS-1$ 310 new Pair(BOOLEAN_TYPE, "java.lang.Object"), new IdentityConverter(Boolean.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
312 311
313 // Float.TYPE 312 // Float.TYPE
314 converterMap 313 converterMap
315 .put( 314 .put(
316 new Pair("java.lang.String", FLOAT_TYPE), StringToNumberConverter.toFloat(numberFormat, true)); //$NON-NLS-1$ 315 new Pair("java.lang.String", FLOAT_TYPE), StringToNumberConverter.toFloat(numberFormat, true)); //$NON-NLS-1$
317 converterMap 316 converterMap
318 .put( 317 .put(
319 new Pair(FLOAT_TYPE, "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, true)); //$NON-NLS-1$ 318 new Pair(FLOAT_TYPE, "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, true)); //$NON-NLS-1$
320 converterMap 319 converterMap
321 .put( 320 .put(
322 new Pair(FLOAT_TYPE, "java.lang.Float"), new IdentityConverter(Float.TYPE, typeid(Float))); //$NON-NLS-1$ 321 new Pair(FLOAT_TYPE, "java.lang.Float"), new IdentityConverter(Float.TYPE, Class.fromType!(Float))); //$NON-NLS-1$
323 converterMap 322 converterMap
324 .put( 323 .put(
325 new Pair(FLOAT_TYPE, "java.lang.Object"), new IdentityConverter(Float.TYPE, typeid(Object))); //$NON-NLS-1$ 324 new Pair(FLOAT_TYPE, "java.lang.Object"), new IdentityConverter(Float.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
326 325
327 // Short.TYPE 326 // Short.TYPE
328 converterMap 327 converterMap
329 .put( 328 .put(
330 new Pair("java.lang.String", SHORT_TYPE), StringToShortConverter.toShort(integerFormat, true)); //$NON-NLS-1$ 329 new Pair("java.lang.String", SHORT_TYPE), StringToShortConverter.toShort(integerFormat, true)); //$NON-NLS-1$
331 converterMap 330 converterMap
332 .put( 331 .put(
333 new Pair(SHORT_TYPE, "java.lang.Short"), new IdentityConverter(Short.TYPE, typeid(Short))); //$NON-NLS-1$ 332 new Pair(SHORT_TYPE, "java.lang.Short"), new IdentityConverter(Short.TYPE, Class.fromType!(Short))); //$NON-NLS-1$
334 converterMap 333 converterMap
335 .put( 334 .put(
336 new Pair(SHORT_TYPE, "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, true)); //$NON-NLS-1$ 335 new Pair(SHORT_TYPE, "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, true)); //$NON-NLS-1$
337 converterMap 336 converterMap
338 .put( 337 .put(
339 new Pair(SHORT_TYPE, "java.lang.Object"), new IdentityConverter(Short.TYPE, typeid(Object))); //$NON-NLS-1$ 338 new Pair(SHORT_TYPE, "java.lang.Object"), new IdentityConverter(Short.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
340 339
341 // Long.TYPE 340 // Long.TYPE
342 converterMap 341 converterMap
343 .put( 342 .put(
344 new Pair("java.lang.String", LONG_TYPE), StringToNumberConverter.toLong(integerFormat, true)); //$NON-NLS-1$ 343 new Pair("java.lang.String", LONG_TYPE), StringToNumberConverter.toLong(integerFormat, true)); //$NON-NLS-1$
345 converterMap 344 converterMap
346 .put( 345 .put(
347 new Pair(LONG_TYPE, "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, true)); //$NON-NLS-1$ 346 new Pair(LONG_TYPE, "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, true)); //$NON-NLS-1$
348 converterMap 347 converterMap
349 .put( 348 .put(
350 new Pair(LONG_TYPE, "java.lang.Long"), new IdentityConverter(Long.TYPE, typeid(Long))); //$NON-NLS-1$ 349 new Pair(LONG_TYPE, "java.lang.Long"), new IdentityConverter(Long.TYPE, Class.fromType!(Long))); //$NON-NLS-1$
351 converterMap 350 converterMap
352 .put( 351 .put(
353 new Pair(LONG_TYPE, "java.lang.Object"), new IdentityConverter(Long.TYPE, typeid(Object))); //$NON-NLS-1$ 352 new Pair(LONG_TYPE, "java.lang.Object"), new IdentityConverter(Long.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
354 353
355 // Character.TYPE 354 // Character.TYPE
356 converterMap 355 converterMap
357 .put( 356 .put(
358 new Pair("java.lang.String", CHARACTER_TYPE), StringToCharacterConverter.toCharacter(true)); //$NON-NLS-1$ 357 new Pair("java.lang.String", CHARACTER_TYPE), StringToCharacterConverter.toCharacter(true)); //$NON-NLS-1$
359 converterMap 358 converterMap
360 .put( 359 .put(
361 new Pair(CHARACTER_TYPE, "java.lang.Character"), new IdentityConverter(Character.TYPE, typeid(Character))); //$NON-NLS-1$ 360 new Pair(CHARACTER_TYPE, "java.lang.Character"), new IdentityConverter(Character.TYPE, Class.fromType!(Character))); //$NON-NLS-1$
362 converterMap 361 converterMap
363 .put( 362 .put(
364 new Pair(CHARACTER_TYPE, "java.lang.String"), CharacterToStringConverter.fromCharacter(true)); //$NON-NLS-1$ 363 new Pair(CHARACTER_TYPE, "java.lang.String"), CharacterToStringConverter.fromCharacter(true)); //$NON-NLS-1$
365 converterMap 364 converterMap
366 .put( 365 .put(
367 new Pair(CHARACTER_TYPE, "java.lang.Object"), new IdentityConverter(Character.TYPE, typeid(Object))); //$NON-NLS-1$ 366 new Pair(CHARACTER_TYPE, "java.lang.Object"), new IdentityConverter(Character.TYPE, Class.fromType!(Object))); //$NON-NLS-1$
368 367
369 // Miscellaneous 368 // Miscellaneous
370 converterMap 369 converterMap
371 .put( 370 .put(
372 new Pair( 371 new Pair(
410 } 409 }
411 410
412 return converterMap; 411 return converterMap;
413 } 412 }
414 413
415 private static TypeInfo[] integerClasses; 414 private static Class[] integerClasses;
416 private static TypeInfo[] floatClasses; 415 private static Class[] floatClasses;
417 static this(){ 416 static this(){
418 integerClasses = [ Byte.TYPE, 417 integerClasses = [ Byte.TYPE,
419 typeid(Byte), Short.TYPE, typeid(Short), Integer.TYPE, typeid(Integer), 418 Class.fromType!(Byte), Short.TYPE, Class.fromType!(Short), Integer.TYPE, Class.fromType!(Integer),
420 Long.TYPE, typeid(Long), typeid(BigInteger) ]; 419 Long.TYPE, Class.fromType!(Long), Class.fromType!(BigInteger) ];
421 floatClasses = [ Float.TYPE, 420 floatClasses = [ Float.TYPE,
422 typeid(Float), Double.TYPE, typeid(Double), typeid(BigDecimal) ]; 421 Class.fromType!(Float), Double.TYPE, Class.fromType!(Double), Class.fromType!(BigDecimal) ];
423 } 422 }
424 423
425 424
426 /** 425 /**
427 * Registers converters to boxed and unboxed types from a list of from 426 * Registers converters to boxed and unboxed types from a list of from
430 * @param map 429 * @param map
431 * @param numberFormat 430 * @param numberFormat
432 * @param fromTypes 431 * @param fromTypes
433 */ 432 */
434 private static void addNumberToByteConverters(Map map, 433 private static void addNumberToByteConverters(Map map,
435 NumberFormat numberFormat, TypeInfo[] fromTypes) { 434 NumberFormat numberFormat, Class[] fromTypes) {
436 435
437 for (int i = 0; i < fromTypes.length; i++) { 436 for (int i = 0; i < fromTypes.length; i++) {
438 TypeInfo fromType = fromTypes[i]; 437 Class fromType = fromTypes[i];
439 if (fromType != typeid(Byte) && fromType != Byte.TYPE) { 438 if (fromType != Class.fromType!(Byte) && fromType != Byte.TYPE) {
440 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 439 String fromName = fromType.isPrimitive() ? getKeyForClass(
441 fromType, null) : .getName(fromType); 440 fromType, null) : fromType.getName();
442 441
443 map 442 map
444 .put(new Pair(fromName, BYTE_TYPE), 443 .put(new Pair(fromName, BYTE_TYPE),
445 new NumberToByteConverter(numberFormat, 444 new NumberToByteConverter(numberFormat,
446 fromType, true)); 445 fromType, true));
447 map 446 map
448 .put(new Pair(fromName, .getName(Byte.classinfo)), 447 .put(new Pair(fromName, Class.fromType!(Byte).getName()),
449 new NumberToByteConverter(numberFormat, 448 new NumberToByteConverter(numberFormat,
450 fromType, false)); 449 fromType, false));
451 } 450 }
452 } 451 }
453 } 452 }
459 * @param map 458 * @param map
460 * @param numberFormat 459 * @param numberFormat
461 * @param fromTypes 460 * @param fromTypes
462 */ 461 */
463 private static void addNumberToShortConverters(Map map, 462 private static void addNumberToShortConverters(Map map,
464 NumberFormat numberFormat, TypeInfo[] fromTypes) { 463 NumberFormat numberFormat, Class[] fromTypes) {
465 for (int i = 0; i < fromTypes.length; i++) { 464 for (int i = 0; i < fromTypes.length; i++) {
466 TypeInfo fromType = fromTypes[i]; 465 Class fromType = fromTypes[i];
467 if (fromType != typeid(Short) && fromType != Short.TYPE) { 466 if (fromType != Class.fromType!(Short) && fromType != Short.TYPE) {
468 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 467 String fromName = fromType.isPrimitive() ? getKeyForClass(
469 fromType, null) : .getName(fromType); 468 fromType, null) : fromType.getName();
470 469
471 map 470 map
472 .put(new Pair(fromName, SHORT_TYPE), 471 .put(new Pair(fromName, SHORT_TYPE),
473 new NumberToShortConverter(numberFormat, 472 new NumberToShortConverter(numberFormat,
474 fromType, true)); 473 fromType, true));
475 map.put(new Pair(fromName, .getName(Short.classinfo)), 474 map.put(new Pair(fromName, Class.fromType!(Short).getName()),
476 new NumberToShortConverter(numberFormat, fromType, 475 new NumberToShortConverter(numberFormat, fromType,
477 false)); 476 false));
478 } 477 }
479 } 478 }
480 } 479 }
486 * @param map 485 * @param map
487 * @param numberFormat 486 * @param numberFormat
488 * @param fromTypes 487 * @param fromTypes
489 */ 488 */
490 private static void addNumberToIntegerConverters(Map map, 489 private static void addNumberToIntegerConverters(Map map,
491 NumberFormat numberFormat, TypeInfo[] fromTypes) { 490 NumberFormat numberFormat, Class[] fromTypes) {
492 for (int i = 0; i < fromTypes.length; i++) { 491 for (int i = 0; i < fromTypes.length; i++) {
493 TypeInfo fromType = fromTypes[i]; 492 Class fromType = fromTypes[i];
494 if (fromType != typeid(Integer) 493 if (fromType != Class.fromType!(Integer)
495 && fromType != Integer.TYPE) { 494 && fromType != Integer.TYPE) {
496 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 495 String fromName = fromType.isPrimitive() ? getKeyForClass(
497 fromType, null) : .getName(fromType); 496 fromType, null) : fromType.getName();
498 497
499 map.put(new Pair(fromName, INTEGER_TYPE), 498 map.put(new Pair(fromName, INTEGER_TYPE),
500 new NumberToIntegerConverter(numberFormat, fromType, 499 new NumberToIntegerConverter(numberFormat, fromType,
501 true)); 500 true));
502 map.put(new Pair(fromName, .getName(Integer.classinfo)), 501 map.put(new Pair(fromName, Class.fromType!(Integer).getName()),
503 new NumberToIntegerConverter(numberFormat, fromType, 502 new NumberToIntegerConverter(numberFormat, fromType,
504 false)); 503 false));
505 } 504 }
506 } 505 }
507 } 506 }
513 * @param map 512 * @param map
514 * @param numberFormat 513 * @param numberFormat
515 * @param fromTypes 514 * @param fromTypes
516 */ 515 */
517 private static void addNumberToLongConverters(Map map, 516 private static void addNumberToLongConverters(Map map,
518 NumberFormat numberFormat, TypeInfo[] fromTypes) { 517 NumberFormat numberFormat, Class[] fromTypes) {
519 for (int i = 0; i < fromTypes.length; i++) { 518 for (int i = 0; i < fromTypes.length; i++) {
520 TypeInfo fromType = fromTypes[i]; 519 Class fromType = fromTypes[i];
521 if (fromType != typeid(Long) && fromType != Long.TYPE) { 520 if (fromType != Class.fromType!(Long) && fromType != Long.TYPE) {
522 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 521 String fromName = fromType.isPrimitive() ? getKeyForClass(
523 fromType, null) : .getName(fromType); 522 fromType, null) : fromType.getName();
524 523
525 map 524 map
526 .put(new Pair(fromName, LONG_TYPE), 525 .put(new Pair(fromName, LONG_TYPE),
527 new NumberToLongConverter(numberFormat, 526 new NumberToLongConverter(numberFormat,
528 fromType, true)); 527 fromType, true));
529 map 528 map
530 .put(new Pair(fromName, .getName(Long.classinfo)), 529 .put(new Pair(fromName, Class.fromType!(Long).getName()),
531 new NumberToLongConverter(numberFormat, 530 new NumberToLongConverter(numberFormat,
532 fromType, false)); 531 fromType, false));
533 } 532 }
534 } 533 }
535 } 534 }
541 * @param map 540 * @param map
542 * @param numberFormat 541 * @param numberFormat
543 * @param fromTypes 542 * @param fromTypes
544 */ 543 */
545 private static void addNumberToFloatConverters(Map map, 544 private static void addNumberToFloatConverters(Map map,
546 NumberFormat numberFormat, TypeInfo[] fromTypes) { 545 NumberFormat numberFormat, Class[] fromTypes) {
547 for (int i = 0; i < fromTypes.length; i++) { 546 for (int i = 0; i < fromTypes.length; i++) {
548 TypeInfo fromType = fromTypes[i]; 547 Class fromType = fromTypes[i];
549 if (fromType != typeid(Float) && fromType != Float.TYPE) { 548 if (fromType != Class.fromType!(Float) && fromType != Float.TYPE) {
550 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 549 String fromName = fromType.isPrimitive() ? getKeyForClass(
551 fromType, null) : .getName(fromType); 550 fromType, null) : fromType.getName();
552 551
553 map 552 map
554 .put(new Pair(fromName, FLOAT_TYPE), 553 .put(new Pair(fromName, FLOAT_TYPE),
555 new NumberToFloatConverter(numberFormat, 554 new NumberToFloatConverter(numberFormat,
556 fromType, true)); 555 fromType, true));
557 map.put(new Pair(fromName, .getName(Float.classinfo)), 556 map.put(new Pair(fromName, Class.fromType!(Float).getName()),
558 new NumberToFloatConverter(numberFormat, fromType, 557 new NumberToFloatConverter(numberFormat, fromType,
559 false)); 558 false));
560 } 559 }
561 } 560 }
562 } 561 }
568 * @param map 567 * @param map
569 * @param numberFormat 568 * @param numberFormat
570 * @param fromTypes 569 * @param fromTypes
571 */ 570 */
572 private static void addNumberToDoubleConverters(Map map, 571 private static void addNumberToDoubleConverters(Map map,
573 NumberFormat numberFormat, TypeInfo[] fromTypes) { 572 NumberFormat numberFormat, Class[] fromTypes) {
574 for (int i = 0; i < fromTypes.length; i++) { 573 for (int i = 0; i < fromTypes.length; i++) {
575 TypeInfo fromType = fromTypes[i]; 574 Class fromType = fromTypes[i];
576 if (fromType != typeid(Double) && fromType != Double.TYPE) { 575 if (fromType != Class.fromType!(Double) && fromType != Double.TYPE) {
577 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 576 String fromName = fromType.isPrimitive() ? getKeyForClass(
578 fromType, null) : .getName(fromType); 577 fromType, null) : fromType.getName();
579 578
580 map.put(new Pair(fromName, DOUBLE_TYPE), 579 map.put(new Pair(fromName, DOUBLE_TYPE),
581 new NumberToDoubleConverter(numberFormat, fromType, 580 new NumberToDoubleConverter(numberFormat, fromType,
582 true)); 581 true));
583 map.put(new Pair(fromName, .getName(Double.classinfo)), 582 map.put(new Pair(fromName, Class.fromType!(Double).getName()),
584 new NumberToDoubleConverter(numberFormat, fromType, 583 new NumberToDoubleConverter(numberFormat, fromType,
585 false)); 584 false));
586 } 585 }
587 } 586 }
588 } 587 }
594 * @param map 593 * @param map
595 * @param numberFormat 594 * @param numberFormat
596 * @param fromTypes 595 * @param fromTypes
597 */ 596 */
598 private static void addNumberToBigIntegerConverters(Map map, 597 private static void addNumberToBigIntegerConverters(Map map,
599 NumberFormat numberFormat, TypeInfo[] fromTypes) { 598 NumberFormat numberFormat, Class[] fromTypes) {
600 for (int i = 0; i < fromTypes.length; i++) { 599 for (int i = 0; i < fromTypes.length; i++) {
601 TypeInfo fromType = fromTypes[i]; 600 Class fromType = fromTypes[i];
602 if (!fromType.opEquals(typeid(BigInteger))) { 601 if (!fromType.opEquals(Class.fromType!(BigInteger))) {
603 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 602 String fromName = fromType.isPrimitive() ? getKeyForClass(
604 fromType, null) : .getName(fromType); 603 fromType, null) : fromType.getName();
605 604
606 map 605 map
607 .put(new Pair(fromName, .getName(BigInteger.classinfo)), 606 .put(new Pair(fromName, Class.fromType!(BigInteger).getName()),
608 new NumberToBigIntegerConverter(numberFormat, 607 new NumberToBigIntegerConverter(numberFormat,
609 fromType)); 608 fromType));
610 } 609 }
611 } 610 }
612 } 611 }
618 * @param map 617 * @param map
619 * @param numberFormat 618 * @param numberFormat
620 * @param fromTypes 619 * @param fromTypes
621 */ 620 */
622 private static void addNumberToBigDecimalConverters(Map map, 621 private static void addNumberToBigDecimalConverters(Map map,
623 NumberFormat numberFormat, TypeInfo[] fromTypes) { 622 NumberFormat numberFormat, Class[] fromTypes) {
624 for (int i = 0; i < fromTypes.length; i++) { 623 for (int i = 0; i < fromTypes.length; i++) {
625 TypeInfo fromType = fromTypes[i]; 624 Class fromType = fromTypes[i];
626 if (!fromType.opEquals(typeid(BigDecimal))) { 625 if (!fromType.opEquals(Class.fromType!(BigDecimal))) {
627 String fromName = isJavaPrimitive(fromType) ? getKeyForClass( 626 String fromName = fromType.isPrimitive() ? getKeyForClass(
628 fromType, null) : .getName(fromType); 627 fromType, null) : fromType.getName();
629 628
630 map 629 map
631 .put(new Pair(fromName, .getName(BigDecimal.classinfo)), 630 .put(new Pair(fromName, Class.fromType!(BigDecimal).getName()),
632 new NumberToBigDecimalConverter(numberFormat, 631 new NumberToBigDecimalConverter(numberFormat,
633 fromType)); 632 fromType));
634 } 633 }
635 } 634 }
636 } 635 }
637 636
638 private static String getKeyForClass(Object originalValue, 637 private static String getKeyForClass(Object originalValue,
639 TypeInfo filteredValue) { 638 Class filteredValue) {
640 if ( null !is cast(TypeInfo)originalValue ) { 639 if ( null !is cast(Class)originalValue ) {
641 TypeInfo originalClass = cast(TypeInfo) originalValue; 640 Class originalClass = cast(Class) originalValue;
642 if (originalClass == Integer.TYPE) { 641 if (originalClass == Integer.TYPE) {
643 return INTEGER_TYPE; 642 return INTEGER_TYPE;
644 } else if (originalClass == Byte.TYPE) { 643 } else if (originalClass == Byte.TYPE) {
645 return BYTE_TYPE; 644 return BYTE_TYPE;
646 } else if (originalClass == Boolean.TYPE) { 645 } else if (originalClass == Boolean.TYPE) {
653 return LONG_TYPE; 652 return LONG_TYPE;
654 } else if (originalClass == Short.TYPE) { 653 } else if (originalClass == Short.TYPE) {
655 return SHORT_TYPE; 654 return SHORT_TYPE;
656 } 655 }
657 } 656 }
658 return .getName(filteredValue); 657 return filteredValue.getName();
659 } 658 }
660 659
661 /** 660 /**
662 * Returns {@link Boolean#TRUE} if the from type is assignable to the to 661 * Returns {@link Boolean#TRUE} if the from type is assignable to the to
663 * type, or {@link Boolean#FALSE} if it not, or <code>null</code> if 662 * type, or {@link Boolean#FALSE} if it not, or <code>null</code> if
667 * @param toType 666 * @param toType
668 * @return whether fromType is assignable to toType, or <code>null</code> 667 * @return whether fromType is assignable to toType, or <code>null</code>
669 * if unknown 668 * if unknown
670 */ 669 */
671 protected Boolean isAssignableFromTo(Object fromType, Object toType) { 670 protected Boolean isAssignableFromTo(Object fromType, Object toType) {
672 if ( null !is cast(TypeInfo)fromType && null !is cast(TypeInfo)toType ) { 671 if ( null !is cast(Class)fromType && null !is cast(Class)toType ) {
673 TypeInfo toClass = cast(TypeInfo) toType; 672 Class toClass = cast(Class) toType;
674 if (isJavaPrimitive(toClass)) { 673 if (toClass.isPrimitive()) {
675 toClass = autoboxed(toClass); 674 toClass = autoboxed(toClass);
676 } 675 }
677 TypeInfo fromClass = cast(TypeInfo) fromType; 676 Class fromClass = cast(Class) fromType;
678 if (isJavaPrimitive(fromClass)) { 677 if (fromClass.isPrimitive()) {
679 fromClass = autoboxed(fromClass); 678 fromClass = autoboxed(fromClass);
680 } 679 }
681 return isImplicitly(fromClass, toClass) ? Boolean.TRUE 680 return toClass.isAssignableFrom(fromClass) ? Boolean.TRUE
682 : Boolean.FALSE; 681 : Boolean.FALSE;
683 } 682 }
684 return null; 683 return null;
685 } 684 }
686 685