Merged revisions 8245-8298 via svnmerge from
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Constructor.c
index e507a1fa97da0bca5d8844a7c1b123c5391719dd..3a82a63aab28b0e2bc8cce0fe2845118083386d2 100644 (file)
@@ -1,6 +1,6 @@
-/* src/native/vm/java_lang_reflect_Constructor.c
+/* src/native/vm/gnu/java_lang_reflect_Constructor.c
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Roman Obermaiser
-            Joseph Wenninger
-            Christian Thalinger
-
-   $Id: java_lang_reflect_Constructor.c 6213 2006-12-18 17:36:06Z twisti $
+   $Id: java_lang_reflect_Constructor.c 8295 2007-08-11 17:57:24Z michi $
 
 */
 
 #include <assert.h>
 #include <stdlib.h>
 
+#if defined(ENABLE_ANNOTATIONS)
+#include "vm/vm.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"
-#include "vm/class.h"
-#include "vm/exceptions.h"
-#include "vm/method.h"
-#include "vm/access.h"
-#include "vm/stringlocal.h"
 
+#if defined(ENABLE_ANNOTATIONS)
+#include "native/include/sun_reflect_ConstantPool.h"
+#include "native/vm/reflect.h"
+#endif
 
-/*
- * 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;
+#include "native/vm/java_lang_reflect_Constructor.h"
 
-       c = (classinfo *) (this->clazz);
-       m = &(c->methods[this->slot]);
+#include "vmcore/utf8.h"
 
-       return m->flags;
-}
 
+/* native methods implemented by this file ************************************/
 
-/*
- * 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)
-{
-       classinfo  *c;
-       methodinfo *m;
+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
+};
 
-       c = (classinfo *) this->clazz;
-       m = &(c->methods[this->slot]);
 
-       return native_get_parametertypes(m);
-}
+/* _Jv_java_lang_reflect_Constructor_init **************************************
 
+   Register native functions.
 
-/*
- * Class:     java/lang/reflect/Constructor
- * Method:    getExceptionTypes
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
+*******************************************************************************/
+
+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 native_get_exceptiontypes(m);
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
 /*
  * Class:     java/lang/reflect/Constructor
  * Method:    constructNative
- * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
+ * 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)
 {
-       classinfo         *c;
-       methodinfo        *m;
-       java_objectheader *o;
-
-       c = (classinfo *) declaringClass;
-
-#if 0
-       /* find initializer */
-
-       if (!args) {
-               if (this->parameterTypes->header.size != 0) {
-                       *exceptionptr =
-                               new_exception_message(string_java_lang_IllegalArgumentException,
-                                                                         "wrong number of arguments");
-                       return NULL;
-               }
-
-       } else {
-               if (this->parameterTypes->header.size != args->header.size) {
-                       *exceptionptr =
-                               new_exception_message(string_java_lang_IllegalArgumentException,
-                                                                         "wrong number of arguments");
-                       return NULL;
-               }
-       }
-#endif
-
-       if (this->slot >= c->methodscount) {
-               log_text("illegal index in methods table");
-               return NULL;
-       }
-
-       m = &(c->methods[this->slot]);
+       /* just to be sure */
 
-       if (m->name != utf_init) {
-               /* XXX throw an exception here, although this should never happen */
+       assert(LLNI_field_direct(this, clazz) == declaringClass);
+       assert(LLNI_field_direct(this, slot)  == slot);
 
-               assert(0);
-       }
-
-       /* check method access */
-       /* check if we should bypass security checks (AccessibleObject) */
-
-       if (this->flag == false) {
-               if (!access_check_caller(c, m->flags, 1))
-                       return NULL;
-       }
+       return _Jv_java_lang_reflect_Constructor_newInstance(env, this, args);
+}
 
-       /* create object */
 
-       o = builtin_new(c);
+#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, struct java_lang_reflect_Constructor* this)
+{
+       java_handle_t *o = (java_handle_t*)this;
 
-       if (!o)
+       if (this == NULL) {
+               exceptions_throw_nullpointerexception();
                return NULL;
-        
-       /* call initializer */
-
-       (void) _Jv_jni_invokeNative(m, o, args);
+       }
 
-       return (java_lang_Object *) o;
+       return reflect_get_declaredannotatios(&(this->declaredAnnotations), this->annotations, this->clazz, o->vftbl->class);
 }
 
 
 /*
  * 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_objectarray* JNICALL Java_java_lang_reflect_Constructor_getParameterAnnotations(JNIEnv *env, struct java_lang_reflect_Constructor* this)
 {
-       classinfo        *c;
-       methodinfo       *m;
-       java_lang_String *s;
-
-       c = (classinfo *) this->clazz;
-       m = &(c->methods[this->slot]);
+       java_handle_t *o = (java_handle_t*)this;
 
-       if (m->signature == NULL)
+       if (this == NULL) {
+               exceptions_throw_nullpointerexception();
                return NULL;
+       }
 
-       s = javastring_new(m->signature);
-
-       /* in error case, s == NULL */
-
-       return s;
+       return reflect_get_parameterannotations((java_handle_t*)this->parameterAnnotations, this->slot, this->clazz, o->vftbl->class);
 }
-
+#endif
 
 /*
  * These are local overrides for various environment variables in Emacs.