diff org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.d @ 85:6be48cf9f95c

Work on databinding
author Frank Benoit <benoit@tionex.de>
date Sat, 18 Apr 2009 13:54:50 +0200
parents 0a55d2d5a946
children 9e0ab372d5d8
line wrap: on
line diff
--- a/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.d	Sat Apr 18 09:25:29 2009 +0200
+++ b/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.d	Sat Apr 18 13:54:50 2009 +0200
@@ -12,6 +12,7 @@
 module org.eclipse.core.internal.databinding.conversion.IntegerToStringConverter;
 
 import java.lang.all;
+import java.nonstandard.RuntimeTraits;
 
 import org.eclipse.core.databinding.conversion.Converter;
 
@@ -30,17 +31,17 @@
 public class IntegerToStringConverter : Converter {
     private final bool primitive;
     private final NumberFormat numberFormat;
-    private final ClassInfo boxedType;
+    private final TypeInfo boxedType;
 
     /**
      * @param numberFormat
      * @param fromType
      * @param boxedType
      */
-    private this(NumberFormat numberFormat, ClassInfo fromType,
-            ClassInfo boxedType) {
-        super(fromType, String.classinfo);
-        this.primitive = fromType.isPrimitive();
+    private this(NumberFormat numberFormat, TypeInfo fromType,
+            TypeInfo boxedType) {
+        super(fromType, typeid(StringCls));
+        this.primitive = isJavaPrimitive(fromType);
         this.numberFormat = numberFormat;
         this.boxedType = boxedType;
     }
@@ -53,15 +54,15 @@
     public Object convert(Object fromObject) {
         // Null is allowed when the type is not primitve.
         if (fromObject is null && !primitive) {
-            return ""; //$NON-NLS-1$
+            return stringcast(""); //$NON-NLS-1$
         }
 
-        if (!boxedType.isInstance(fromObject)) {
+        if (!isImplicitly(fromObject.classinfo, boxedType.classinfo)) {
             throw new IllegalArgumentException(
-                    "'fromObject' is not of type [" + boxedType + "]."); //$NON-NLS-1$//$NON-NLS-2$
+                    Format("'fromObject' is not of type [{}].", boxedType)); //$NON-NLS-1$//$NON-NLS-2$
         }
 
-        return numberFormat.format((cast(Number) fromObject).longValue());
+        return stringcast(numberFormat.format((cast(Number) fromObject).longValue()));
     }
 
     /**
@@ -80,7 +81,7 @@
     public static IntegerToStringConverter fromShort(NumberFormat numberFormat,
             bool primitive) {
         return new IntegerToStringConverter(numberFormat,
-                primitive ? Short.TYPE : Short.classinfo, Short.classinfo);
+                primitive ? Short.TYPE : typeid(Short), typeid(Short));
     }
 
     /**
@@ -99,6 +100,6 @@
     public static IntegerToStringConverter fromByte(NumberFormat numberFormat,
             bool primitive) {
         return new IntegerToStringConverter(numberFormat, primitive ? Byte.TYPE
-                : Byte.classinfo, Byte.classinfo);
+                : typeid(Byte), typeid(Byte));
     }
 }