rt/emul/mini/src/main/java/java/lang/reflect/Array.java
branchclosure
changeset 1541 3471d74a6b99
parent 1535 c02c6d409461
child 1702 228f26fc1159
     1.1 --- a/rt/emul/mini/src/main/java/java/lang/reflect/Array.java	Tue May 06 11:12:40 2014 +0200
     1.2 +++ b/rt/emul/mini/src/main/java/java/lang/reflect/Array.java	Wed May 07 08:49:54 2014 +0200
     1.3 @@ -75,40 +75,10 @@
     1.4          if (length < 0) {
     1.5              throw new NegativeArraySizeException();
     1.6          }
     1.7 -        String sig = findSignature(componentType);
     1.8 +        String sig = Method.findArraySignature(componentType);
     1.9          return newArray(componentType.isPrimitive(), sig, null, length);
    1.10      }
    1.11      
    1.12 -    private static String findSignature(Class<?> type) {
    1.13 -        if (type == Integer.TYPE) {
    1.14 -            return "[I";
    1.15 -        }
    1.16 -        if (type == Long.TYPE) {
    1.17 -            return "[J";
    1.18 -        }
    1.19 -        if (type == Double.TYPE) {
    1.20 -            return "[D";
    1.21 -        }
    1.22 -        if (type == Float.TYPE) {
    1.23 -            return "[F";
    1.24 -        }
    1.25 -        if (type == Byte.TYPE) {
    1.26 -            return "[B";
    1.27 -        }
    1.28 -        if (type == Boolean.TYPE) {
    1.29 -            return "[Z";
    1.30 -        }
    1.31 -        if (type == Short.TYPE) {
    1.32 -            return "[S";
    1.33 -        }
    1.34 -        if (type == Character.TYPE) {
    1.35 -            return "[C";
    1.36 -        }
    1.37 -        if (type.getName().equals("void")) {
    1.38 -            throw new IllegalStateException("Can't create array for " + type);
    1.39 -        }
    1.40 -        return "[L" + type.getName().replace('.', '/') + ";";
    1.41 -    }
    1.42      /**
    1.43       * Creates a new array
    1.44       * with the specified component type and dimensions.
    1.45 @@ -148,7 +118,7 @@
    1.46          for (int i = 1; i < dimensions.length; i++) {
    1.47              sig.append('[');
    1.48          }
    1.49 -        sig.append(findSignature(componentType));
    1.50 +        sig.append(Method.findArraySignature(componentType));
    1.51          return multiNewArray(sig.toString(), dimensions, 0);
    1.52      }
    1.53  
    1.54 @@ -234,7 +204,7 @@
    1.55       */
    1.56      public static byte getByte(Object array, int index)
    1.57      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.58 -        if (array.getClass().getComponentType() != Byte.TYPE) {
    1.59 +        if (!Method.samePrimitive(array.getClass().getComponentType(), Byte.TYPE)) {
    1.60              throw new IllegalArgumentException();
    1.61          }
    1.62          byte[] arr = (byte[]) array;
    1.63 @@ -279,7 +249,7 @@
    1.64      public static short getShort(Object array, int index)
    1.65      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.66          final Class<?> t = array.getClass().getComponentType();
    1.67 -        if (t == Short.TYPE) {
    1.68 +        if (Method.samePrimitive(t, Short.TYPE)) {
    1.69              short[] arr = (short[]) array;
    1.70              return arr[index];
    1.71          }
    1.72 @@ -305,7 +275,7 @@
    1.73      public static int getInt(Object array, int index) 
    1.74      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.75          final Class<?> t = array.getClass().getComponentType();
    1.76 -        if (t == Integer.TYPE) {
    1.77 +        if (Method.samePrimitive(t, Integer.TYPE)) {
    1.78              int[] arr = (int[]) array;
    1.79              return arr[index];
    1.80          }
    1.81 @@ -331,7 +301,7 @@
    1.82      public static long getLong(Object array, int index)
    1.83      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.84          final Class<?> t = array.getClass().getComponentType();
    1.85 -        if (t == Long.TYPE) {
    1.86 +        if (Method.samePrimitive(t, Long.TYPE)) {
    1.87              long[] arr = (long[]) array;
    1.88              return arr[index];
    1.89          }
    1.90 @@ -357,7 +327,7 @@
    1.91      public static float getFloat(Object array, int index)
    1.92      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.93          final Class<?> t = array.getClass().getComponentType();
    1.94 -        if (t == Float.TYPE) {
    1.95 +        if (Method.samePrimitive(t, Float.TYPE)) {
    1.96              float[] arr = (float[]) array;
    1.97              return arr[index];
    1.98          }
    1.99 @@ -383,7 +353,7 @@
   1.100      public static double getDouble(Object array, int index)
   1.101      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.102          final Class<?> t = array.getClass().getComponentType();
   1.103 -        if (t == Double.TYPE) {
   1.104 +        if (Method.samePrimitive(t, Double.TYPE)) {
   1.105              double[] arr = (double[]) array;
   1.106              return arr[index];
   1.107          }
   1.108 @@ -457,7 +427,7 @@
   1.109      public static void setByte(Object array, int index, byte b)
   1.110      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.111          Class<?> t = array.getClass().getComponentType();
   1.112 -        if (t == Byte.TYPE) {
   1.113 +        if (Method.samePrimitive(t, Byte.TYPE)) {
   1.114              byte[] arr = (byte[]) array;
   1.115              arr[index] = b;
   1.116          } else {
   1.117 @@ -505,7 +475,7 @@
   1.118      public static void setShort(Object array, int index, short s)
   1.119      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.120          Class<?> t = array.getClass().getComponentType();
   1.121 -        if (t == Short.TYPE) {
   1.122 +        if (Method.samePrimitive(t, Short.TYPE)) {
   1.123              short[] arr = (short[]) array;
   1.124              arr[index] = s;
   1.125          } else {
   1.126 @@ -534,7 +504,7 @@
   1.127      public static void setInt(Object array, int index, int i)
   1.128      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.129          Class<?> t = array.getClass().getComponentType();
   1.130 -        if (t == Integer.TYPE) {
   1.131 +        if (Method.samePrimitive(t, Integer.TYPE)) {
   1.132              int[] arr = (int[]) array;
   1.133              arr[index] = i;
   1.134          } else {
   1.135 @@ -562,7 +532,7 @@
   1.136      public static void setLong(Object array, int index, long l)
   1.137      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.138          Class<?> t = array.getClass().getComponentType();
   1.139 -        if (t == Long.TYPE) {
   1.140 +        if (Method.samePrimitive(t, Long.TYPE)) {
   1.141              long[] arr = (long[]) array;
   1.142              arr[index] = l;
   1.143          } else {
   1.144 @@ -590,7 +560,7 @@
   1.145      public static void setFloat(Object array, int index, float f)
   1.146      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.147          Class<?> t = array.getClass().getComponentType();
   1.148 -        if (t == Float.TYPE) {
   1.149 +        if (Method.samePrimitive(t, Float.TYPE)) {
   1.150              float[] arr = (float[])array;
   1.151              arr[index] = f;
   1.152          } else {
   1.153 @@ -618,7 +588,7 @@
   1.154      public static void setDouble(Object array, int index, double d)
   1.155      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   1.156          Class<?> t = array.getClass().getComponentType();
   1.157 -        if (t == Double.TYPE) {
   1.158 +        if (Method.samePrimitive(t, Double.TYPE)) {
   1.159              double[] arr = (double[])array;
   1.160              arr[index] = d;
   1.161          } else {