* Merged with default branch at rev 16f3633aaa5a.
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Constructor.c
index 9a5a343be2438e0a4eddffa570114e390f901abf..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 7573 2007-03-25 18:55:02Z 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_Object.h"
 #include "native/include/java_lang_String.h"
 #include "native/include/java_lang_reflect_Constructor.h"
 
-#include "toolbox/logging.h"
+#if defined(ENABLE_ANNOTATIONS)
+# include "native/include/sun_reflect_ConstantPool.h"
 
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/access.h"
-#include "vm/stringlocal.h"
+# include "native/vm/reflect.h"
+#endif
 
-#include "vmcore/class.h"
-#include "vmcore/method.h"
+#include "native/vm/java_lang_reflect_Constructor.h"
 
+#include "vmcore/utf8.h"
 
-/*
- * Class:     java/lang/reflect/Constructor
- * Method:    getModifiersInternal
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_Constructor *this)
-{
-       classinfo  *c;
-       methodinfo *m;
 
-       c = (classinfo *) (this->clazz);
-       m = &(c->methods[this->slot]);
+/* native methods implemented by this file ************************************/
 
-       return m->flags;
-}
+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        },
+#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
+};
 
 
-/*
- * Class:     java/lang/reflect/Constructor
- * Method:    getParameterTypes
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getParameterTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
+/* _Jv_java_lang_reflect_Constructor_init **************************************
+
+   Register native functions.
+
+*******************************************************************************/
+
+void _Jv_java_lang_reflect_Constructor_init(void)
 {
-       classinfo  *c;
-       methodinfo *m;
+       utf *u;
 
-       c = (classinfo *) this->clazz;
-       m = &(c->methods[this->slot]);
+       u = utf_new_char("java/lang/reflect/Constructor");
 
-       return method_get_parametertypearray(m);
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
 /*
  * Class:     java/lang/reflect/Constructor
- * Method:    getExceptionTypes
- * Signature: ()[Ljava/lang/Class;
+ * Method:    constructNative
+ * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
  */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
+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)
 {
-       classinfo  *c;
-       methodinfo *m;
+       /* just to be sure */
 
-       c = (classinfo *) this->clazz;
-       m = &(c->methods[this->slot]);
+       assert(LLNI_field_direct(this, clazz) == LLNI_DIRECT(declaringClass));
+       assert(LLNI_field_direct(this, slot)  == slot);
 
-       return method_get_exceptionarray(m);
+       return _Jv_java_lang_reflect_Constructor_newInstance(env, this, args);
 }
 
 
+#if defined(ENABLE_ANNOTATIONS)
 /*
  * Class:     java/lang/reflect/Constructor
- * Method:    constructNative
- * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
+ * Method:    declaredAnnotations
+ * Signature: ()Ljava/util/Map;
  */
-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 struct java_util_Map* JNICALL Java_java_lang_reflect_Constructor_declaredAnnotations(JNIEnv *env, java_lang_reflect_Constructor *this)
 {
-       classinfo         *c;
-       methodinfo        *m;
-       java_objectheader *o;
+       struct java_util_Map    *declaredAnnotations = NULL;
+       java_handle_bytearray_t *annotations         = NULL;
+       java_lang_Class         *declaringClass      = NULL;
+       classinfo               *referer             = NULL;
 
-       c = (classinfo *) declaringClass;
-       m = &(c->methods[this->slot]);
+       LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
 
-       /* check method access */
+       if (declaredAnnotations == NULL) {
+               LLNI_field_get_val(this, annotations, annotations);
+               LLNI_field_get_ref(this, clazz, declaringClass);
+               LLNI_class_get(this, referer);
 
-       /* check if we should bypass security checks (AccessibleObject) */
+               declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
 
-       if (this->flag == false) {
-               if (!access_check_member(c, m->flags, 1))
-                       return NULL;
+               LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
        }
 
-       /* create object */
-
-       o = builtin_new(c);
-
-       if (o == NULL)
-               return NULL;
-        
-       /* call initializer */
-
-       (void) _Jv_jni_invokeNative(m, o, args);
-
-       return (java_lang_Object *) o;
+       return declaredAnnotations;
 }
 
 
 /*
  * Class:     java/lang/reflect/Constructor
- * Method:    getSignature
- * Signature: ()Ljava/lang/String;
+ * Method:    getParameterAnnotations
+ * Signature: ()[[Ljava/lang/annotation/Annotation;
  */
-JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Constructor_getSignature(JNIEnv *env, java_lang_reflect_Constructor *this)
+JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Constructor_getParameterAnnotations(JNIEnv *env, java_lang_reflect_Constructor *this)
 {
-       classinfo        *c;
-       methodinfo       *m;
-       java_lang_String *s;
-
-       c = (classinfo *) this->clazz;
-       m = &(c->methods[this->slot]);
+       java_handle_bytearray_t *parameterAnnotations = NULL;
+       int32_t                  slot                 = -1;
+       java_lang_Class         *declaringClass       = NULL;
+       classinfo               *referer              = NULL;
 
-       if (m->signature == NULL)
-               return 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);
 
-       s = javastring_new(m->signature);
-
-       /* in error case, s == NULL */
-
-       return s;
+       return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, referer);
 }
-
+#endif
 
 /*
  * These are local overrides for various environment variables in Emacs.