1 /* src/native/vm/gnu/java_lang_reflect_VMConstructor.c
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #if defined(ENABLE_ANNOTATIONS)
33 #include "vm/exceptions.h"
36 #include "native/jni.h"
37 #include "native/llni.h"
38 #include "native/native.h"
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_Object.h"
42 #include "native/include/java_lang_String.h"
44 #if defined(ENABLE_ANNOTATIONS)
45 # include "native/include/java_util_Map.h"
46 # include "native/include/sun_reflect_ConstantPool.h"
49 #include "native/include/java_lang_reflect_Constructor.h"
50 #include "native/include/java_lang_reflect_VMConstructor.h"
52 #include "native/vm/reflect.h"
54 #include "vm/stringlocal.h"
56 #include "vmcore/utf8.h"
59 /* native methods implemented by this file ************************************/
61 static JNINativeMethod methods[] = {
62 { "getModifiersInternal", "()I", (void *) (intptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal },
63 { "getParameterTypes", "()[Ljava/lang/Class;", (void *) (intptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes },
64 { "getExceptionTypes", "()[Ljava/lang/Class;", (void *) (intptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes },
65 { "construct", "([Ljava/lang/Object;)Ljava/lang/Object;", (void *) (intptr_t) &Java_java_lang_reflect_VMConstructor_construct },
66 { "getSignature", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_reflect_VMConstructor_getSignature },
67 #if defined(ENABLE_ANNOTATIONS)
68 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (intptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations },
69 { "getParameterAnnotations", "()[[Ljava/lang/annotation/Annotation;", (void *) (intptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations },
74 /* _Jv_java_lang_reflect_VMConstructor_init ************************************
76 Register native functions.
78 *******************************************************************************/
80 void _Jv_java_lang_reflect_VMConstructor_init(void)
84 u = utf_new_char("java/lang/reflect/VMConstructor");
86 native_method_register(u, methods, NATIVE_METHODS_COUNT);
91 * Class: java/lang/reflect/VMConstructor
92 * Method: getModifiersInternal
95 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMConstructor *this)
101 LLNI_field_get_cls(this, clazz, c);
102 LLNI_field_get_val(this, slot, slot);
104 m = &(c->methods[slot]);
111 * Class: java/lang/reflect/VMConstructor
112 * Method: getParameterTypes
113 * Signature: ()[Ljava/lang/Class;
115 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, java_lang_reflect_VMConstructor *this)
121 LLNI_field_get_cls(this, clazz, c);
122 LLNI_field_get_val(this, slot, slot);
124 m = &(c->methods[slot]);
126 return method_get_parametertypearray(m);
131 * Class: java/lang/reflect/VMConstructor
132 * Method: getExceptionTypes
133 * Signature: ()[Ljava/lang/Class;
135 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_VMConstructor *this)
141 LLNI_field_get_cls(this, clazz, c);
142 LLNI_field_get_val(this, slot, slot);
144 m = &(c->methods[slot]);
146 return method_get_exceptionarray(m);
151 * Class: java/lang/reflect/VMConstructor
153 * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
155 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, java_lang_reflect_VMConstructor *this, java_handle_objectarray_t *args)
159 java_lang_reflect_Constructor *rc;
164 LLNI_field_get_cls(this, clazz, c);
165 LLNI_field_get_val(this, slot, slot);
167 LLNI_field_get_ref(this, cons, rc);
168 LLNI_field_get_val(rc, flag, override);
170 m = &(c->methods[slot]);
172 o = reflect_constructor_newinstance(m, args, override);
174 return (java_lang_Object *) o;
179 * Class: java/lang/reflect/VMConstructor
180 * Method: getSignature
181 * Signature: ()Ljava/lang/String;
183 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, java_lang_reflect_VMConstructor *this)
190 LLNI_field_get_cls(this, clazz, c);
191 LLNI_field_get_val(this, slot, slot);
193 m = &(c->methods[slot]);
195 if (m->signature == NULL)
198 o = javastring_new(m->signature);
200 /* In error case o is NULL. */
202 return (java_lang_String *) o;
206 #if defined(ENABLE_ANNOTATIONS)
208 * Class: java/lang/reflect/VMConstructor
209 * Method: declaredAnnotations
210 * Signature: ()Ljava/util/Map;
212 * Parses the annotations (if they aren't parsed yet) and stores them into
213 * the declaredAnnotations map and return this map.
215 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMConstructor *this)
217 java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
218 java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
219 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
220 classinfo *referer = NULL; /* class, which calles the annotation parser */
221 /* (for the parameter 'referer' of vm_call_method()) */
223 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
225 /* are the annotations parsed yet? */
226 if (declaredAnnotations == NULL) {
227 LLNI_field_get_ref(this, annotations, annotations);
228 LLNI_field_get_ref(this, clazz, declaringClass);
229 LLNI_class_get(this, referer);
231 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
233 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
236 return declaredAnnotations;
241 * Class: java/lang/reflect/VMConstructor
242 * Method: getParameterAnnotations
243 * Signature: ()[[Ljava/lang/annotation/Annotation;
245 * Parses the parameter annotations and returns them in an 2 dimensional array.
247 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, java_lang_reflect_VMConstructor *this)
249 java_handle_bytearray_t *parameterAnnotations = NULL; /* unparsed parameter annotations */
250 int32_t slot = -1; /* slot of the method */
251 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
252 classinfo *referer = NULL; /* class, which calles the annotation parser */
253 /* (for the parameter 'referer' of vm_call_method()) */
255 LLNI_field_get_ref(this, parameterAnnotations, parameterAnnotations);
256 LLNI_field_get_val(this, slot, slot);
257 LLNI_field_get_ref(this, clazz, declaringClass);
258 LLNI_class_get(this, referer);
260 return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, referer);
265 * These are local overrides for various environment variables in Emacs.
266 * Please do not remove this and leave it at the end of the file, where
267 * Emacs will automagically detect them.
268 * ---------------------------------------------------------------------
271 * indent-tabs-mode: t