1 /* src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp
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 #include "native/jni.h"
32 #include "native/llni.h"
33 #include "native/native.h"
35 #include "native/include/java_lang_Class.h"
36 #include "native/include/java_lang_Object.h"
37 #include "native/include/java_lang_String.h"
39 #if defined(ENABLE_ANNOTATIONS)
40 # include "native/include/java_util_Map.h"
41 # include "native/include/sun_reflect_ConstantPool.h"
44 #include "native/include/java_lang_reflect_Constructor.h"
47 #include "native/include/java_lang_reflect_VMConstructor.h"
50 #include "native/vm/reflect.h"
52 #include "vm/string.hpp"
54 #include "vmcore/utf8.h"
57 /* native methods implemented by this file ************************************/
59 static JNINativeMethod methods[] = {
60 { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal },
61 { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes },
62 { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes },
63 { (char*) "construct", (char*) "([Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_construct },
64 { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getSignature },
65 #if defined(ENABLE_ANNOTATIONS)
66 { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations },
67 { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations },
72 /* _Jv_java_lang_reflect_VMConstructor_init ************************************
74 Register native functions.
76 *******************************************************************************/
79 void _Jv_java_lang_reflect_VMConstructor_init(void)
83 u = utf_new_char("java/lang/reflect/VMConstructor");
85 native_method_register(u, methods, NATIVE_METHODS_COUNT);
90 // Native functions are exported as C functions.
94 * Class: java/lang/reflect/VMConstructor
95 * Method: getModifiersInternal
98 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMConstructor *_this)
104 LLNI_field_get_cls(_this, clazz, c);
105 LLNI_field_get_val(_this, slot, slot);
107 m = &(c->methods[slot]);
114 * Class: java/lang/reflect/VMConstructor
115 * Method: getParameterTypes
116 * Signature: ()[Ljava/lang/Class;
118 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, java_lang_reflect_VMConstructor *_this)
124 LLNI_field_get_cls(_this, clazz, c);
125 LLNI_field_get_val(_this, slot, slot);
127 m = &(c->methods[slot]);
129 return method_get_parametertypearray(m);
134 * Class: java/lang/reflect/VMConstructor
135 * Method: getExceptionTypes
136 * Signature: ()[Ljava/lang/Class;
138 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_VMConstructor *_this)
144 LLNI_field_get_cls(_this, clazz, c);
145 LLNI_field_get_val(_this, slot, slot);
147 m = &(c->methods[slot]);
149 return method_get_exceptionarray(m);
154 * Class: java/lang/reflect/VMConstructor
156 * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
158 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, java_lang_reflect_VMConstructor *_this, java_handle_objectarray_t *args)
162 java_lang_reflect_Constructor *rc;
167 LLNI_field_get_cls(_this, clazz, c);
168 LLNI_field_get_val(_this, slot, slot);
170 LLNI_field_get_ref(_this, cons, rc);
171 LLNI_field_get_val(rc, flag, override);
173 m = &(c->methods[slot]);
175 o = reflect_constructor_newinstance(m, args, override);
177 return (java_lang_Object *) o;
182 * Class: java/lang/reflect/VMConstructor
183 * Method: getSignature
184 * Signature: ()Ljava/lang/String;
186 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, java_lang_reflect_VMConstructor *_this)
193 LLNI_field_get_cls(_this, clazz, c);
194 LLNI_field_get_val(_this, slot, slot);
196 m = &(c->methods[slot]);
198 if (m->signature == NULL)
201 o = javastring_new(m->signature);
203 /* In error case o is NULL. */
205 return (java_lang_String *) o;
209 #if defined(ENABLE_ANNOTATIONS)
211 * Class: java/lang/reflect/VMConstructor
212 * Method: declaredAnnotations
213 * Signature: ()Ljava/util/Map;
215 * Parses the annotations (if they aren't parsed yet) and stores them into
216 * the declaredAnnotations map and return this map.
218 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMConstructor *_this)
220 java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
221 java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
222 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
223 classinfo *referer = NULL; /* class, which calles the annotation parser */
224 /* (for the parameter 'referer' of vm_call_method()) */
226 LLNI_field_get_ref(_this, declaredAnnotations, declaredAnnotations);
228 /* are the annotations parsed yet? */
229 if (declaredAnnotations == NULL) {
230 LLNI_field_get_ref(_this, annotations, annotations);
231 LLNI_field_get_ref(_this, clazz, declaringClass);
232 LLNI_class_get(_this, referer);
234 declaredAnnotations = reflect_get_declaredannotations(annotations, (classinfo*) declaringClass, referer);
236 LLNI_field_set_ref(_this, declaredAnnotations, declaredAnnotations);
239 return declaredAnnotations;
244 * Class: java/lang/reflect/VMConstructor
245 * Method: getParameterAnnotations
246 * Signature: ()[[Ljava/lang/annotation/Annotation;
248 * Parses the parameter annotations and returns them in an 2 dimensional array.
250 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, java_lang_reflect_VMConstructor *_this)
252 java_handle_bytearray_t *parameterAnnotations = NULL; /* unparsed parameter annotations */
253 int32_t slot = -1; /* slot of the method */
256 classinfo *referer = NULL; /* class, which calles the annotation parser */
257 /* (for the parameter 'referer' of vm_call_method()) */
259 LLNI_field_get_ref(_this, parameterAnnotations, parameterAnnotations);
260 LLNI_field_get_val(_this, slot, slot);
261 LLNI_field_get_cls(_this, clazz, c);
262 m = &(c->methods[slot]);
264 LLNI_class_get(_this, referer);
266 return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, m, referer);
274 * These are local overrides for various environment variables in Emacs.
275 * Please do not remove this and leave it at the end of the file, where
276 * Emacs will automagically detect them.
277 * ---------------------------------------------------------------------
280 * indent-tabs-mode: t