1 /* src/native/vm/gnuclasspath/java_lang_reflect_VMMethod.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
30 #if defined(ENABLE_ANNOTATIONS)
34 #include "native/jni.h"
35 #include "native/llni.h"
36 #include "native/native.h"
39 //#include "native/include/java_lang_reflect_VMMethod.h"
41 #include "native/vm/reflection.hpp"
43 #include "vm/access.h"
44 #include "vm/global.h"
45 #include "vm/builtin.h"
46 #include "vm/exceptions.hpp"
47 #include "vm/initialize.h"
48 #include "vm/resolve.h"
49 #include "vm/string.hpp"
51 #include "vmcore/class.h"
52 #include "vmcore/globals.hpp"
53 #include "vmcore/javaobjects.hpp"
54 #include "vmcore/method.h"
57 // Native functions are exported as C functions.
61 * Class: java/lang/reflect/VMMethod
62 * Method: getModifiersInternal
65 JNIEXPORT jint JNICALL Java_java_lang_reflect_VMMethod_getModifiersInternal(JNIEnv *env, jobject _this)
67 java_lang_reflect_VMMethod rvmm(_this);
68 methodinfo* m = rvmm.get_method();
74 * Class: java/lang/reflect/VMMethod
75 * Method: getReturnType
76 * Signature: ()Ljava/lang/Class;
78 JNIEXPORT jclass JNICALL Java_java_lang_reflect_VMMethod_getReturnType(JNIEnv *env, jobject _this)
80 java_lang_reflect_VMMethod rvmm(_this);
81 methodinfo* m = rvmm.get_method();
82 classinfo* c = method_returntype_get(m);
84 return (jclass) LLNI_classinfo_wrap(c);
89 * Class: java/lang/reflect/VMMethod
90 * Method: getParameterTypes
91 * Signature: ()[Ljava/lang/Class;
93 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMMethod_getParameterTypes(JNIEnv *env, jobject _this)
95 java_lang_reflect_VMMethod rvmm(_this);
96 methodinfo* m = rvmm.get_method();
97 java_handle_objectarray_t* oa = method_get_parametertypearray(m);
98 return (jobjectArray) oa;
103 * Class: java/lang/reflect/VMMethod
104 * Method: getExceptionTypes
105 * Signature: ()[Ljava/lang/Class;
107 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMMethod_getExceptionTypes(JNIEnv *env, jobject _this)
109 java_lang_reflect_VMMethod rvmm(_this);
110 methodinfo* m = rvmm.get_method();
111 java_handle_objectarray_t* oa = method_get_exceptionarray(m);
112 return (jobjectArray) oa;
117 * Class: java/lang/reflect/VMMethod
119 * Signature: (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
121 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_invoke(JNIEnv *env, jobject _this, jobject o, jobjectArray args)
123 java_lang_reflect_VMMethod rvmm(_this);
124 java_lang_reflect_Method rm(rvmm.get_m());
126 methodinfo* m = rvmm.get_method();
127 int32_t override = rm.get_flag();
129 java_handle_t* result = Reflection::method_invoke(m, (java_handle_t*) o, (java_handle_objectarray_t*) args, override);
131 return (jobject) result;
136 * Class: java/lang/reflect/VMMethod
137 * Method: getSignature
138 * Signature: ()Ljava/lang/String;
140 JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMMethod_getSignature(JNIEnv *env, jobject _this)
142 java_lang_reflect_VMMethod rvmm(_this);
143 methodinfo* m = rvmm.get_method();
145 if (m->signature == NULL)
148 java_handle_t* s = javastring_new(m->signature);
150 /* in error case o is NULL */
156 #if defined(ENABLE_ANNOTATIONS)
158 * Class: java/lang/reflect/VMMethod
159 * Method: getDefaultValue
160 * Signature: ()Ljava/lang/Object;
162 * Parses the annotation default value and returnes it (boxed, if it's a primitive).
164 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_getDefaultValue(JNIEnv *env, jobject _this)
166 static methodinfo *m_parseAnnotationDefault = NULL; /* parser method (will be chached, therefore static) */
167 utf *utf_parseAnnotationDefault = NULL; /* parser method name */
168 utf *utf_desc = NULL; /* parser method descriptor (signature) */
171 exceptions_throw_nullpointerexception();
175 // TODO Use a constructor.
176 java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);
181 sun_reflect_ConstantPool cp(h);
183 java_lang_reflect_VMMethod rvmm(_this);
184 classinfo* declaringClass = rvmm.get_clazz();
185 cp.set_constantPoolOop(declaringClass);
187 /* only resolve the parser method the first time */
188 if (m_parseAnnotationDefault == NULL) {
189 utf_parseAnnotationDefault = utf_new_char("parseAnnotationDefault");
190 utf_desc = utf_new_char(
191 "(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;)"
192 "Ljava/lang/Object;");
194 if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
200 LLNI_class_get((java_lang_reflect_VMMethod *) _this, referer);
202 m_parseAnnotationDefault = class_resolveclassmethod(
203 class_sun_reflect_annotation_AnnotationParser,
204 utf_parseAnnotationDefault,
209 if (m_parseAnnotationDefault == NULL) {
210 /* method not found */
215 java_lang_reflect_Method rm(rvmm.get_m());
216 java_handle_bytearray_t* annotationDefault = rvmm.get_annotationDefault();
218 java_handle_t* result = vm_call_method(m_parseAnnotationDefault, NULL, rm.get_handle(), annotationDefault, cp.get_handle());
220 return (jobject) result;
225 * Class: java/lang/reflect/VMMethod
226 * Method: declaredAnnotations
227 * Signature: ()Ljava/util/Map;
229 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_declaredAnnotations(JNIEnv *env, jobject _this)
231 java_lang_reflect_VMMethod rvmm(_this);
232 java_handle_t* declaredAnnotations = rvmm.get_declaredAnnotations();
234 // Are the annotations parsed yet?
235 if (declaredAnnotations == NULL) {
236 java_handle_bytearray_t* annotations = rvmm.get_annotations();
237 classinfo* declaringClass = rvmm.get_clazz();
240 LLNI_class_get((java_lang_reflect_VMMethod *) _this, referer);
242 declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer);
244 rvmm.set_declaredAnnotations(declaredAnnotations);
247 return (jobject) declaredAnnotations;
252 * Class: java/lang/reflect/VMMethod
253 * Method: getParameterAnnotations
254 * Signature: ()[[Ljava/lang/annotation/Annotation;
256 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMMethod_getParameterAnnotations(JNIEnv *env, jobject _this)
258 java_lang_reflect_VMMethod rvmm(_this);
259 java_handle_bytearray_t* parameterAnnotations = rvmm.get_parameterAnnotations();
260 methodinfo* m = rvmm.get_method();
263 LLNI_class_get((java_lang_reflect_VMMethod *) _this, referer);
265 java_handle_objectarray_t* oa = Reflection::get_parameterannotations(parameterAnnotations, m, referer);
266 return (jobjectArray) oa;
273 /* native methods implemented by this file ************************************/
275 static JNINativeMethod methods[] = {
276 { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getModifiersInternal },
277 { (char*) "getReturnType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getReturnType },
278 { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getParameterTypes },
279 { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getExceptionTypes },
280 { (char*) "invoke", (char*) "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_invoke },
281 { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getSignature },
282 #if defined(ENABLE_ANNOTATIONS)
283 { (char*) "getDefaultValue", (char*) "()Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getDefaultValue },
284 { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_declaredAnnotations },
285 { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMMethod_getParameterAnnotations },
290 /* _Jv_java_lang_reflect_VMMethod_init *****************************************
292 Register native functions.
294 *******************************************************************************/
298 void _Jv_java_lang_reflect_VMMethod_init(void)
302 u = utf_new_char("java/lang/reflect/VMMethod");
304 native_method_register(u, methods, NATIVE_METHODS_COUNT);
310 * These are local overrides for various environment variables in Emacs.
311 * Please do not remove this and leave it at the end of the file, where
312 * Emacs will automagically detect them.
313 * ---------------------------------------------------------------------
316 * indent-tabs-mode: t