diff options
author | Brian Carlstrom <bdc@google.com> | 2013-07-30 01:26:50 -0700 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2013-08-13 18:09:46 -0700 |
commit | ea46f950e7a51585db293cd7f047de190a482414 (patch) | |
tree | 9dddc8073547a2dcb58a19e1728932a89cb149c3 /test/046-reflect | |
parent | 5e3572709b5a5d59957f835db4f73760ecef08da (diff) | |
download | art-ea46f950e7a51585db293cd7f047de190a482414.zip art-ea46f950e7a51585db293cd7f047de190a482414.tar.gz art-ea46f950e7a51585db293cd7f047de190a482414.tar.bz2 |
Refactor java.lang.reflect implementation
Cherry-picked from commit ed41d5c44299ec5d44b8514f6e17f802f48094d1.
Move to ArtMethod/Field instead of AbstractMethod/Field and have
java.lang.reflect APIs delegate to ArtMethod/ArtField.
Bug: 10014286.
Change-Id: Iafc1d8c5b62562c9af8fb9fd8c5e1d61270536e7
Diffstat (limited to 'test/046-reflect')
-rw-r--r-- | test/046-reflect/expected.txt | 9 | ||||
-rw-r--r-- | test/046-reflect/src/Main.java | 43 |
2 files changed, 49 insertions, 3 deletions
diff --git a/test/046-reflect/expected.txt b/test/046-reflect/expected.txt index 8de373c..fcfaf2f 100644 --- a/test/046-reflect/expected.txt +++ b/test/046-reflect/expected.txt @@ -81,8 +81,9 @@ Field name is cantTouchThis Field type is int Access flags are 0x11 cantTouchThis is 77 - setAccessible is always true cantTouchThis is now 99 + public final int Target.cantTouchThis accessible=false + public final int Target.cantTouchThis accessible=true cantTouchThis is now 87 cantTouchThis is now 88 cons modifiers=1 @@ -92,6 +93,8 @@ myMethod (I)I arg=17 anInt=7 ReflectTest done! public method +static java.lang.Object java.util.Collections.checkType(java.lang.Object,java.lang.Class) accessible=false +static java.lang.Object java.util.Collections.checkType(java.lang.Object,java.lang.Class) accessible=true checkType invoking null checkType got expected exception calling const-class FieldNoisyInitUser.class @@ -113,3 +116,7 @@ MethodNoisyInit is initializing generic field: java.util.List<java.lang.String> generic method fancyMethod params='[1] java.util.ArrayList<java.lang.String>' ret='java.util.Map<java.lang.Integer, java.lang.String>' generic ctor Main params='[1] java.util.ArrayList<java.lang.Integer>' +fields are unique +fields are .equals +methods are unique +methods are .equals diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java index 9d4cacf..dfb0d8f 100644 --- a/test/046-reflect/src/Main.java +++ b/test/046-reflect/src/Main.java @@ -335,14 +335,15 @@ public class Main { System.out.println(" cantTouchThis is " + intVal); try { field.setInt(instance, 99); - System.out.println(" setAccessible is always true"); } catch (IllegalAccessException iae) { System.out.println("ERROR: set-final failed"); } intVal = field.getInt(instance); System.out.println(" cantTouchThis is now " + intVal); + System.out.println(" " + field + " accessible=" + field.isAccessible()); field.setAccessible(true); + System.out.println(" " + field + " accessible=" + field.isAccessible()); field.setInt(instance, 87); // exercise int version intVal = field.getInt(instance); System.out.println(" cantTouchThis is now " + intVal); @@ -378,8 +379,9 @@ public class Main { nsme.printStackTrace(); return; } - + System.out.println(m + " accessible=" + m.isAccessible()); m.setAccessible(true); + System.out.println(m + " accessible=" + m.isAccessible()); try { m.invoke(null, new Object(), Object.class); } catch (IllegalAccessException iae) { @@ -518,6 +520,42 @@ public class Main { return stb.toString(); } + public static void checkUnique() { + Field field1, field2; + try { + field1 = Main.class.getField("dummy"); + field2 = Main.class.getField("dummy"); + } catch (NoSuchFieldException nsfe) { + throw new RuntimeException(nsfe); + } + if (field1 == field2) { + System.out.println("ERROR: fields shouldn't have reference equality"); + } else { + System.out.println("fields are unique"); + } + if (field1.hashCode() == field2.hashCode() && field1.equals(field2)) { + System.out.println("fields are .equals"); + } else { + System.out.println("ERROR: fields fail equality"); + } + Method method1, method2; + try { + method1 = Main.class.getMethod("fancyMethod", new Class[] { ArrayList.class }); + method2 = Main.class.getMethod("fancyMethod", new Class[] { ArrayList.class }); + } catch (NoSuchMethodException nsme) { + throw new RuntimeException(nsme); + } + if (method1 == method2) { + System.out.println("ERROR: methods shouldn't have reference equality"); + } else { + System.out.println("methods are unique"); + } + if (method1.hashCode() == method2.hashCode() && method1.equals(method2)) { + System.out.println("methods are .equals"); + } else { + System.out.println("ERROR: methods fail equality"); + } + } public static void main(String[] args) throws Exception { Main test = new Main(); @@ -528,6 +566,7 @@ public class Main { checkClinitForFields(); checkClinitForMethods(); checkGeneric(); + checkUnique(); } } |