* Merged with default branch at rev 16f3633aaa5a.
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Constructor.c
index a4507d22381b8c5af782c2fb22d669171a6967fb..dda0424b546a2f4cbf30d96c68dea21139f6302b 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_reflect_Constructor.c 8067 2007-06-12 12:32:18Z twisti $
-
 */
 
 
 #include <assert.h>
 #include <stdlib.h>
 
+#if defined(ENABLE_ANNOTATIONS)
+#include "vm/vm.h"
+#include "vm/exceptions.h"
+#endif
+
 #include "vm/types.h"
 
 #include "native/jni.h"
+#include "native/llni.h"
 #include "native/native.h"
 
 #include "native/include/java_lang_Class.h"
 #include "native/include/java_lang_String.h"
 #include "native/include/java_lang_reflect_Constructor.h"
 
+#if defined(ENABLE_ANNOTATIONS)
+# include "native/include/sun_reflect_ConstantPool.h"
+
+# include "native/vm/reflect.h"
+#endif
+
 #include "native/vm/java_lang_reflect_Constructor.h"
 
 #include "vmcore/utf8.h"
 /* native methods implemented by this file ************************************/
 
 static JNINativeMethod methods[] = {
-       { "getModifiersInternal", "()I",                                                       (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getModifiers      },
-       { "getParameterTypes",    "()[Ljava/lang/Class;",                                      (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getParameterTypes },
-       { "getExceptionTypes",    "()[Ljava/lang/Class;",                                      (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getExceptionTypes },
-       { "constructNative",      "([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Constructor_constructNative  },
-       { "getSignature",         "()Ljava/lang/String;",                                      (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getSignature      },
+       { "getModifiersInternal",    "()I",                                                       (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getModifiers        },
+       { "getParameterTypes",       "()[Ljava/lang/Class;",                                      (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getParameterTypes   },
+       { "getExceptionTypes",       "()[Ljava/lang/Class;",                                      (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getExceptionTypes   },
+       { "constructNative",         "([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Constructor_constructNative    },
+       { "getSignature",            "()Ljava/lang/String;",                                      (void *) (ptrint) &_Jv_java_lang_reflect_Constructor_getSignature        },
+#if defined(ENABLE_ANNOTATIONS)
+       { "declaredAnnotations",     "()Ljava/util/Map;",                                         (void *) (ptrint) &Java_java_lang_reflect_Constructor_declaredAnnotations     },
+       { "getParameterAnnotations", "()[[Ljava/lang/annotation/Annotation;",                     (void *) (ptrint) &Java_java_lang_reflect_Constructor_getParameterAnnotations },
+#endif
 };
 
 
@@ -79,17 +93,67 @@ void _Jv_java_lang_reflect_Constructor_init(void)
  * Method:    constructNative
  * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
  */
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative(JNIEnv *env, java_lang_reflect_Constructor *this, java_objectarray *args, java_lang_Class *declaringClass, s4 slot)
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative(JNIEnv *env, java_lang_reflect_Constructor *this, java_handle_objectarray_t *args, java_lang_Class *declaringClass, s4 slot)
 {
        /* just to be sure */
 
-       assert(this->clazz == declaringClass);
-       assert(this->slot  == slot);
+       assert(LLNI_field_direct(this, clazz) == LLNI_DIRECT(declaringClass));
+       assert(LLNI_field_direct(this, slot)  == slot);
 
        return _Jv_java_lang_reflect_Constructor_newInstance(env, this, args);
 }
 
 
+#if defined(ENABLE_ANNOTATIONS)
+/*
+ * Class:     java/lang/reflect/Constructor
+ * Method:    declaredAnnotations
+ * Signature: ()Ljava/util/Map;
+ */
+JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Constructor_declaredAnnotations(JNIEnv *env, java_lang_reflect_Constructor *this)
+{
+       struct java_util_Map    *declaredAnnotations = NULL;
+       java_handle_bytearray_t *annotations         = NULL;
+       java_lang_Class         *declaringClass      = NULL;
+       classinfo               *referer             = NULL;
+
+       LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
+
+       if (declaredAnnotations == NULL) {
+               LLNI_field_get_val(this, annotations, annotations);
+               LLNI_field_get_ref(this, clazz, declaringClass);
+               LLNI_class_get(this, referer);
+
+               declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
+
+               LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
+       }
+
+       return declaredAnnotations;
+}
+
+
+/*
+ * Class:     java/lang/reflect/Constructor
+ * Method:    getParameterAnnotations
+ * Signature: ()[[Ljava/lang/annotation/Annotation;
+ */
+JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Constructor_getParameterAnnotations(JNIEnv *env, java_lang_reflect_Constructor *this)
+{
+       java_handle_bytearray_t *parameterAnnotations = NULL;
+       int32_t                  slot                 = -1;
+       java_lang_Class         *declaringClass       = NULL;
+       classinfo               *referer              = NULL;
+
+       LLNI_field_get_ref(this, parameterAnnotations, parameterAnnotations);
+       LLNI_field_get_val(this, slot, slot);
+       LLNI_field_get_ref(this, clazz, declaringClass);
+       LLNI_class_get(this, referer);
+
+       return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, referer);
+}
+#endif
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where