Just autoboxing on Arrays remains ArrayReflect
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 18 Jan 2013 21:51:06 +0100
branchArrayReflect
changeset 485d962d1330e54
parent 484 7ca6bd52b668
child 486 947269b26dc0
Just autoboxing on Arrays remains
emul/src/main/java/java/lang/reflect/Array.java
vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java
     1.1 --- a/emul/src/main/java/java/lang/reflect/Array.java	Fri Jan 18 21:21:35 2013 +0100
     1.2 +++ b/emul/src/main/java/java/lang/reflect/Array.java	Fri Jan 18 21:51:06 2013 +0100
     1.3 @@ -186,8 +186,14 @@
     1.4       * argument is negative, or if it is greater than or equal to the
     1.5       * length of the specified array
     1.6       */
     1.7 -    public static native Object get(Object array, int index)
     1.8 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
     1.9 +    public static Object get(Object array, int index)
    1.10 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.11 +        if (array.getClass().getComponentType().isPrimitive()) {
    1.12 +            throw new IllegalArgumentException();
    1.13 +        } else {
    1.14 +            return ((Object[])array)[index];
    1.15 +        }
    1.16 +    }
    1.17  
    1.18      /**
    1.19       * Returns the value of the indexed component in the specified
    1.20 @@ -399,8 +405,15 @@
    1.21       * argument is negative, or if it is greater than or equal to
    1.22       * the length of the specified array
    1.23       */
    1.24 -    public static native void set(Object array, int index, Object value)
    1.25 -        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
    1.26 +    public static void set(Object array, int index, Object value)
    1.27 +    throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.28 +        if (array.getClass().getComponentType().isPrimitive()) {
    1.29 +            throw new IllegalArgumentException();
    1.30 +        } else {
    1.31 +            Object[] arr = (Object[])array;
    1.32 +            arr[index] = value;
    1.33 +        }
    1.34 +    }
    1.35  
    1.36      /**
    1.37       * Sets the value of the indexed component of the specified array
     2.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java	Fri Jan 18 21:21:35 2013 +0100
     2.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java	Fri Jan 18 21:51:06 2013 +0100
     2.3 @@ -74,6 +74,11 @@
     2.4          int[] arr = (int[]) Array.newInstance(int.class, 5);
     2.5          return (Integer) Array.get(arr, 0);
     2.6      }
     2.7 +    @Compare public String verifyObjectArray() {
     2.8 +        String[] arr = (String[]) Array.newInstance(String.class, 5);
     2.9 +        Array.set(arr, 0, "Hello");
    2.10 +        return (String) Array.get(arr, 0);
    2.11 +    }
    2.12      @Compare public int verifyInt() {
    2.13          int[] arr = (int[]) Array.newInstance(int.class, 5);
    2.14          return Array.getInt(arr, 0);
    2.15 @@ -84,9 +89,13 @@
    2.16      }
    2.17  
    2.18      @Compare public Object verifySetIntToObject() {
    2.19 -        Object[] arr = (Object[]) Array.newInstance(Object.class, 5);
    2.20 -        Array.setInt(arr, 0, 10);
    2.21 -        return Array.get(arr, 0);
    2.22 +        try {
    2.23 +            Object[] arr = (Object[]) Array.newInstance(Object.class, 5);
    2.24 +            Array.setInt(arr, 0, 10);
    2.25 +            return Array.get(arr, 0);
    2.26 +        } catch (Exception exception) {
    2.27 +            return exception.getClass().getName();
    2.28 +        }
    2.29      }
    2.30      @Compare public long verifySetShort() {
    2.31          int[] arr = (int[]) Array.newInstance(int.class, 5);