From 518f428f1365536d1afdf0a2c3c9add2d5856dd3 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 7 May 2014 14:43:29 -0600 Subject: [PATCH] add Field.getDeclaredAnnotations default method for android classpath (fixes Reflection test) --- src/classpath-android.cpp | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index d8bb1fc460..99c2965ce7 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -1968,6 +1968,62 @@ Avian_java_lang_reflect_Method_getDeclaredAnnotations 0)); } +extern "C" AVIAN_EXPORT int64_t JNICALL + Avian_java_lang_reflect_Field_getDeclaredAnnotations(Thread* t, + object, + uintptr_t* arguments) +{ + object field = arrayBody( + t, + classFieldTable( + t, jclassVmClass(t, reinterpret_cast(arguments[0]))), + arguments[1]); + + object addendum = fieldAddendum(t, field); + if (addendum) { + object table = addendumAnnotationTable(t, addendum); + if (table) { + PROTECT(t, field); + PROTECT(t, table); + + object array + = makeObjectArray(t, + resolveClass(t, + root(t, Machine::BootLoader), + "java/lang/annotation/Annotation"), + objectArrayLength(t, table)); + PROTECT(t, array); + + object get = resolveMethod(t, + root(t, Machine::BootLoader), + "avian/Classes", + "getAnnotation", + "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" + "Ljava/lang/annotation/Annotation;"); + PROTECT(t, get); + + for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { + object a + = t->m->processor->invoke(t, + get, + 0, + classLoader(t, reinterpret_cast(arguments[0])), + objectArrayBody(t, table, i)); + + set(t, array, ArrayBody + (i * BytesPerWord), a); + } + + return reinterpret_cast(array); + } + } + + return reinterpret_cast(makeObjectArray( + t, + resolveClass( + t, root(t, Machine::BootLoader), "java/lang/annotation/Annotation"), + 0)); +} + extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_reflect_Method_getDefaultValue (Thread* t, object, uintptr_t* arguments)