1 /* src/native/vm/gnu/java_lang_reflect_Method.c
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32 #if defined(ENABLE_ANNOTATIONS)
38 #include "native/jni.h"
39 #include "native/llni.h"
40 #include "native/native.h"
42 #include "native/include/java_lang_Object.h"
43 #include "native/include/java_lang_Class.h"
44 #include "native/include/java_lang_String.h"
46 #if defined(ENABLE_ANNOTATIONS)
47 #include "native/include/sun_reflect_ConstantPool.h"
48 #include "native/vm/reflect.h"
51 #include "native/include/java_lang_reflect_Method.h"
53 #include "native/vm/java_lang_reflect_Method.h"
55 #include "vm/access.h"
56 #include "vm/global.h"
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/initialize.h"
60 #include "vm/resolve.h"
61 #include "vm/stringlocal.h"
63 #include "vmcore/method.h"
66 /* native methods implemented by this file ************************************/
68 static JNINativeMethod methods[] = {
69 { "getModifiersInternal", "()I", (void *) (ptrint) &Java_java_lang_reflect_Method_getModifiersInternal },
70 { "getReturnType", "()Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getReturnType },
71 { "getParameterTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterTypes },
72 { "getExceptionTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getExceptionTypes },
73 { "invokeNative", "(Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_invokeNative },
74 { "getSignature", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_reflect_Method_getSignature },
75 #if defined(ENABLE_ANNOTATIONS)
76 { "getDefaultValue", "()Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_getDefaultValue },
77 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (ptrint) &Java_java_lang_reflect_Method_declaredAnnotations },
78 { "getParameterAnnotations", "()[[Ljava/lang/annotation/Annotation;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterAnnotations },
83 /* _Jv_java_lang_reflect_Method_init *******************************************
85 Register native functions.
87 *******************************************************************************/
89 void _Jv_java_lang_reflect_Method_init(void)
93 u = utf_new_char("java/lang/reflect/Method");
95 native_method_register(u, methods, NATIVE_METHODS_COUNT);
100 * Class: java/lang/reflect/Method
101 * Method: getModifiersInternal
104 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
110 LLNI_field_get_cls(this, clazz, c);
111 LLNI_field_get_val(this, slot , slot);
112 m = &(c->methods[slot]);
119 * Class: java/lang/reflect/Method
120 * Method: getReturnType
121 * Signature: ()Ljava/lang/Class;
123 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
130 LLNI_field_get_cls(this, clazz, c);
131 LLNI_field_get_val(this, slot , slot);
132 m = &(c->methods[slot]);
134 result = method_returntype_get(m);
136 return LLNI_classinfo_wrap(result);
141 * Class: java/lang/reflect/Method
142 * Method: getParameterTypes
143 * Signature: ()[Ljava/lang/Class;
145 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
151 LLNI_field_get_cls(this, clazz, c);
152 LLNI_field_get_val(this, slot , slot);
153 m = &(c->methods[slot]);
155 return method_get_parametertypearray(m);
160 * Class: java/lang/reflect/Method
161 * Method: getExceptionTypes
162 * Signature: ()[Ljava/lang/Class;
164 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
170 LLNI_field_get_cls(this, clazz, c);
171 LLNI_field_get_val(this, slot , slot);
172 m = &(c->methods[slot]);
174 return method_get_exceptionarray(m);
179 * Class: java/lang/reflect/Method
180 * Method: invokeNative
181 * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
183 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *o, java_handle_objectarray_t *args, java_lang_Class *clazz, s4 slot)
185 /* just to be sure */
187 assert(LLNI_field_direct(this, clazz) == clazz);
188 assert(LLNI_field_direct(this, slot) == slot);
190 return _Jv_java_lang_reflect_Method_invoke(this, o, args);
195 * Class: java/lang/reflect/Method
196 * Method: getSignature
197 * Signature: ()Ljava/lang/String;
199 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(JNIEnv *env, java_lang_reflect_Method* this)
206 LLNI_field_get_cls(this, clazz, c);
207 LLNI_field_get_val(this, slot , slot);
208 m = &(c->methods[slot]);
210 if (m->signature == NULL)
213 o = javastring_new(m->signature);
215 /* in error case o is NULL */
217 return (java_lang_String *) o;
220 #if defined(ENABLE_ANNOTATIONS)
222 * Class: java/lang/reflect/Method
223 * Method: getDefaultValue
224 * Signature: ()Ljava/lang/Object;
226 JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefaultValue(JNIEnv *env, struct java_lang_reflect_Method* this)
228 static methodinfo *m_parseAnnotationDefault = NULL;
229 utf *utf_parseAnnotationDefault = NULL;
230 utf *utf_desc = NULL;
231 sun_reflect_ConstantPool *constantPool = NULL;
232 java_handle_t *o = (java_handle_t*)this;
233 java_lang_Class *constantPoolOop = NULL;
234 classinfo *referer = NULL;
237 exceptions_throw_nullpointerexception();
242 (sun_reflect_ConstantPool*)native_new_and_init(
243 class_sun_reflect_ConstantPool);
245 if(constantPool == NULL) {
250 LLNI_field_get_ref(this, clazz, constantPoolOop);
251 LLNI_field_set_ref(constantPool, constantPoolOop, (java_lang_Object*)constantPoolOop);
253 /* only resolve the method the first time */
254 if (m_parseAnnotationDefault == NULL) {
255 utf_parseAnnotationDefault = utf_new_char("parseAnnotationDefault");
256 utf_desc = utf_new_char(
257 "(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;)"
258 "Ljava/lang/Object;");
260 if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
265 LLNI_class_get(this, referer);
267 m_parseAnnotationDefault = class_resolveclassmethod(
268 class_sun_reflect_annotation_AnnotationParser,
269 utf_parseAnnotationDefault,
274 if (m_parseAnnotationDefault == NULL) {
275 /* method not found */
280 return (java_lang_Object*)vm_call_method(
281 m_parseAnnotationDefault, NULL,
282 this, this->annotationDefault, constantPool);
287 * Class: java/lang/reflect/Method
288 * Method: declaredAnnotations
289 * Signature: ()Ljava/util/Map;
291 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Method_declaredAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
293 java_handle_t *o = (java_handle_t*)this;
294 struct java_util_Map *declaredAnnotations = NULL;
295 java_handle_bytearray_t *annotations = NULL;
296 java_lang_Class *declaringClass = NULL;
297 classinfo *referer = NULL;
299 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
301 if (declaredAnnotations == NULL) {
302 LLNI_field_get_val(this, annotations, annotations);
303 LLNI_field_get_ref(this, clazz, declaringClass);
304 LLNI_class_get(this, referer);
306 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
308 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
311 return declaredAnnotations;
316 * Class: java/lang/reflect/Method
317 * Method: getParameterAnnotations
318 * Signature: ()[[Ljava/lang/annotation/Annotation;
320 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getParameterAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
322 java_handle_t *o = (java_handle_t*)this;
323 java_handle_bytearray_t *parameterAnnotations = NULL;
325 java_lang_Class *declaringClass = NULL;
326 classinfo *referer = NULL;
328 LLNI_field_get_ref(this, parameterAnnotations, parameterAnnotations);
329 LLNI_field_get_val(this, slot, slot);
330 LLNI_field_get_ref(this, clazz, declaringClass);
331 LLNI_class_get(this, referer);
333 return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, referer);
339 * These are local overrides for various environment variables in Emacs.
340 * Please do not remove this and leave it at the end of the file, where
341 * Emacs will automagically detect them.
342 * ---------------------------------------------------------------------
345 * indent-tabs-mode: t