# HG changeset patch # User Jaroslav Tulach # Date 1358540495 -3600 # Node ID 7ca6bd52b6680482b5f67cc93dd40065dc0a0c15 # Parent 7e39f344e4a05a56e0831fe402f140dfc64d20a0 Array setter hierarchy diff -r 7e39f344e4a0 -r 7ca6bd52b668 emul/src/main/java/java/lang/reflect/Array.java --- a/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 21:04:10 2013 +0100 +++ b/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 21:21:35 2013 +0100 @@ -439,8 +439,16 @@ * the length of the specified array * @see Array#set */ - public static native void setByte(Object array, int index, byte b) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static void setByte(Object array, int index, byte b) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + Class t = array.getClass().getComponentType(); + if (t == Byte.TYPE) { + byte[] arr = (byte[]) array; + arr[index] = b; + } else { + setShort(array, index, b); + } + } /** * Sets the value of the indexed component of the specified array @@ -479,8 +487,17 @@ * the length of the specified array * @see Array#set */ - public static native void setShort(Object array, int index, short s) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static void setShort(Object array, int index, short s) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + Class t = array.getClass().getComponentType(); + if (t == Short.TYPE) { + short[] arr = (short[]) array; + arr[index] = s; + } else { + setInt(array, index, s); + } + + } /** * Sets the value of the indexed component of the specified array @@ -499,8 +516,16 @@ * the length of the specified array * @see Array#set */ - public static native void setInt(Object array, int index, int i) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static void setInt(Object array, int index, int i) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + Class t = array.getClass().getComponentType(); + if (t == Integer.TYPE) { + long[] arr = (long[]) array; + arr[index] = i; + } else { + setLong(array, index, i); + } + } /** * Sets the value of the indexed component of the specified array @@ -519,8 +544,16 @@ * the length of the specified array * @see Array#set */ - public static native void setLong(Object array, int index, long l) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static void setLong(Object array, int index, long l) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + Class t = array.getClass().getComponentType(); + if (t == Long.TYPE) { + long[] arr = (long[]) array; + arr[index] = l; + } else { + setFloat(array, index, l); + } + } /** * Sets the value of the indexed component of the specified array @@ -539,8 +572,16 @@ * the length of the specified array * @see Array#set */ - public static native void setFloat(Object array, int index, float f) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static void setFloat(Object array, int index, float f) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + Class t = array.getClass().getComponentType(); + if (t == Float.TYPE) { + float[] arr = (float[])array; + arr[index] = f; + } else { + setDouble(array, index, f); + } + } /** * Sets the value of the indexed component of the specified array @@ -559,8 +600,16 @@ * the length of the specified array * @see Array#set */ - public static native void setDouble(Object array, int index, double d) - throws IllegalArgumentException, ArrayIndexOutOfBoundsException; + public static void setDouble(Object array, int index, double d) + throws IllegalArgumentException, ArrayIndexOutOfBoundsException { + Class t = array.getClass().getComponentType(); + if (t == Double.TYPE) { + double[] arr = (double[])array; + arr[index] = d; + } else { + throw new IllegalArgumentException("argument type mismatch"); + } + } /* * Private @@ -587,7 +636,4 @@ } return arr; } - - - } diff -r 7e39f344e4a0 -r 7ca6bd52b668 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java Fri Jan 18 21:04:10 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java Fri Jan 18 21:21:35 2013 +0100 @@ -98,6 +98,11 @@ Array.setLong(arr, 0, 10); return Array.getLong(arr, 0); } + @Compare public float verifyLongToFloat() { + Object arr = Array.newInstance(float.class, 5); + Array.setLong(arr, 0, 10); + return Array.getFloat(arr, 0); + } @Compare public double verifyConvertToDouble() { int[] arr = (int[]) Array.newInstance(int.class, 5);