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 #if defined(ENABLE_JNI_HEADERS)
36 # include "native/vm/include/java_lang_reflect_VMConstructor.h"
39 #include "native/vm/reflection.hpp"
41 #include "vm/javaobjects.hpp"
42 #include "vm/string.hpp"
46 // Native functions are exported as C functions.
50 * Class: java/lang/reflect/VMConstructor
51 * Method: getModifiersInternal
54 JNIEXPORT jint JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, jobject _this)
56 java_lang_reflect_VMConstructor rvmc(_this);
57 methodinfo* m = rvmc.get_method();
63 * Class: java/lang/reflect/VMConstructor
64 * Method: getParameterTypes
65 * Signature: ()[Ljava/lang/Class;
67 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, jobject _this)
69 java_lang_reflect_VMConstructor rvmc(_this);
70 methodinfo* m = rvmc.get_method();
72 java_handle_objectarray_t* hoa = method_get_parametertypearray(m);
74 return (jobjectArray) hoa;
79 * Class: java/lang/reflect/VMConstructor
80 * Method: getExceptionTypes
81 * Signature: ()[Ljava/lang/Class;
83 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, jobject _this)
85 java_lang_reflect_VMConstructor rvmc(_this);
86 methodinfo* m = rvmc.get_method();
88 java_handle_objectarray_t* hoa = method_get_exceptionarray(m);
90 return (jobjectArray) hoa;
95 * Class: java/lang/reflect/VMConstructor
97 * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
99 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, jobject _this, jobjectArray args)
101 java_lang_reflect_VMConstructor jlrvmc(_this);
102 java_lang_reflect_Constructor jlrc(jlrvmc.get_cons());
104 java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args);
111 * Class: java/lang/reflect/VMConstructor
112 * Method: getSignature
113 * Signature: ()Ljava/lang/String;
115 JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, jobject _this)
117 java_lang_reflect_VMConstructor rvmc(_this);
118 methodinfo* m = rvmc.get_method();
121 if (m->signature == NULL)
124 o = javastring_new(m->signature);
126 /* In error case o is NULL. */
132 #if defined(ENABLE_ANNOTATIONS)
134 * Class: java/lang/reflect/VMConstructor
135 * Method: declaredAnnotations
136 * Signature: ()Ljava/util/Map;
138 * Parses the annotations (if they aren't parsed yet) and stores them into
139 * the declaredAnnotations map and return this map.
141 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, jobject _this)
143 java_lang_reflect_VMConstructor rvmc(_this);
145 java_handle_t* declaredAnnotations = rvmc.get_declaredAnnotations();
147 /* are the annotations parsed yet? */
148 if (declaredAnnotations == NULL) {
149 java_handle_bytearray_t* annotations = rvmc.get_annotations();
150 classinfo* declaringClass = rvmc.get_clazz();
153 LLNI_class_get(_this, referer);
155 declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer);
157 rvmc.set_declaredAnnotations(declaredAnnotations);
160 return (jobject) declaredAnnotations;
165 * Class: java/lang/reflect/VMConstructor
166 * Method: getParameterAnnotations
167 * Signature: ()[[Ljava/lang/annotation/Annotation;
169 * Parses the parameter annotations and returns them in an 2 dimensional array.
171 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, jobject _this)
173 java_lang_reflect_VMConstructor rvmc(_this);
175 java_handle_bytearray_t* parameterAnnotations = rvmc.get_parameterAnnotations();
176 methodinfo* m = rvmc.get_method();
179 LLNI_class_get((java_lang_reflect_VMConstructor*) _this, referer);
181 java_handle_objectarray_t* oa = Reflection::get_parameterannotations(parameterAnnotations, m, referer);
183 return (jobjectArray) oa;
190 /* native methods implemented by this file ************************************/
192 static JNINativeMethod methods[] = {
193 { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal },
194 { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes },
195 { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes },
196 { (char*) "construct", (char*) "([Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_construct },
197 { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getSignature },
198 #if defined(ENABLE_ANNOTATIONS)
199 { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations },
200 { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations },
205 /* _Jv_java_lang_reflect_VMConstructor_init ************************************
207 Register native functions.
209 *******************************************************************************/
212 void _Jv_java_lang_reflect_VMConstructor_init(void)
216 u = utf_new_char("java/lang/reflect/VMConstructor");
218 native_method_register(u, methods, NATIVE_METHODS_COUNT);
224 * These are local overrides for various environment variables in Emacs.
225 * Please do not remove this and leave it at the end of the file, where
226 * Emacs will automagically detect them.
227 * ---------------------------------------------------------------------
230 * indent-tabs-mode: t