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
25 $Id: java_lang_reflect_Method.c 8393 2007-08-22 01:10:09Z panzi $
34 #if defined(ENABLE_ANNOTATIONS)
40 #include "native/jni.h"
41 #include "native/llni.h"
42 #include "native/native.h"
44 #include "native/include/java_lang_Object.h"
45 #include "native/include/java_lang_Class.h"
46 #include "native/include/java_lang_String.h"
48 #if defined(ENABLE_ANNOTATIONS)
49 #include "native/include/sun_reflect_ConstantPool.h"
50 #include "native/vm/reflect.h"
53 #include "native/include/java_lang_reflect_Method.h"
55 #include "native/vm/java_lang_reflect_Method.h"
57 #include "vm/access.h"
58 #include "vm/global.h"
59 #include "vm/builtin.h"
60 #include "vm/exceptions.h"
61 #include "vm/initialize.h"
62 #include "vm/resolve.h"
63 #include "vm/stringlocal.h"
65 #include "vmcore/method.h"
68 /* native methods implemented by this file ************************************/
70 static JNINativeMethod methods[] = {
71 { "getModifiersInternal", "()I", (void *) (ptrint) &Java_java_lang_reflect_Method_getModifiersInternal },
72 { "getReturnType", "()Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getReturnType },
73 { "getParameterTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterTypes },
74 { "getExceptionTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getExceptionTypes },
75 { "invokeNative", "(Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_invokeNative },
76 { "getSignature", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_reflect_Method_getSignature },
77 #if defined(ENABLE_ANNOTATIONS)
78 { "getDefaultValue", "()Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_getDefaultValue },
79 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (ptrint) &Java_java_lang_reflect_Method_declaredAnnotations },
80 { "getParameterAnnotations", "()[[Ljava/lang/annotation/Annotation;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterAnnotations },
85 /* _Jv_java_lang_reflect_Method_init *******************************************
87 Register native functions.
89 *******************************************************************************/
91 void _Jv_java_lang_reflect_Method_init(void)
95 u = utf_new_char("java/lang/reflect/Method");
97 native_method_register(u, methods, NATIVE_METHODS_COUNT);
102 * Class: java/lang/reflect/Method
103 * Method: getModifiersInternal
106 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
112 LLNI_field_get_cls(this, clazz, c);
113 LLNI_field_get_val(this, slot , slot);
114 m = &(c->methods[slot]);
121 * Class: java/lang/reflect/Method
122 * Method: getReturnType
123 * Signature: ()Ljava/lang/Class;
125 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
132 LLNI_field_get_cls(this, clazz, c);
133 LLNI_field_get_val(this, slot , slot);
134 m = &(c->methods[slot]);
136 result = method_returntype_get(m);
138 return LLNI_classinfo_wrap(result);
143 * Class: java/lang/reflect/Method
144 * Method: getParameterTypes
145 * Signature: ()[Ljava/lang/Class;
147 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
153 LLNI_field_get_cls(this, clazz, c);
154 LLNI_field_get_val(this, slot , slot);
155 m = &(c->methods[slot]);
157 return method_get_parametertypearray(m);
162 * Class: java/lang/reflect/Method
163 * Method: getExceptionTypes
164 * Signature: ()[Ljava/lang/Class;
166 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
172 LLNI_field_get_cls(this, clazz, c);
173 LLNI_field_get_val(this, slot , slot);
174 m = &(c->methods[slot]);
176 return method_get_exceptionarray(m);
181 * Class: java/lang/reflect/Method
182 * Method: invokeNative
183 * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
185 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)
187 /* just to be sure */
189 assert(LLNI_field_direct(this, clazz) == clazz);
190 assert(LLNI_field_direct(this, slot) == slot);
192 return _Jv_java_lang_reflect_Method_invoke(this, o, args);
197 * Class: java/lang/reflect/Method
198 * Method: getSignature
199 * Signature: ()Ljava/lang/String;
201 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(JNIEnv *env, java_lang_reflect_Method* this)
208 LLNI_field_get_cls(this, clazz, c);
209 LLNI_field_get_val(this, slot , slot);
210 m = &(c->methods[slot]);
212 if (m->signature == NULL)
215 o = javastring_new(m->signature);
217 /* in error case o is NULL */
219 return (java_lang_String *) o;
222 #if defined(ENABLE_ANNOTATIONS)
224 * Class: java/lang/reflect/Method
225 * Method: getDefaultValue
226 * Signature: ()Ljava/lang/Object;
228 JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Method_getDefaultValue(JNIEnv *env, struct java_lang_reflect_Method* this)
230 static methodinfo *m_parseAnnotationDefault = NULL;
231 utf *utf_parseAnnotationDefault = NULL;
232 utf *utf_desc = NULL;
233 sun_reflect_ConstantPool *constantPool = NULL;
234 java_handle_t *o = (java_handle_t*)this;
235 java_lang_Class *constantPoolOop = NULL;
236 classinfo *referer = NULL;
239 exceptions_throw_nullpointerexception();
244 (sun_reflect_ConstantPool*)native_new_and_init(
245 class_sun_reflect_ConstantPool);
247 if(constantPool == NULL) {
252 LLNI_field_get_ref(this, clazz, constantPoolOop);
253 LLNI_field_set_ref(constantPool, constantPoolOop, (java_lang_Object*)constantPoolOop);
255 /* only resolve the method the first time */
256 if (m_parseAnnotationDefault == NULL) {
257 utf_parseAnnotationDefault = utf_new_char("parseAnnotationDefault");
258 utf_desc = utf_new_char(
259 "(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;)"
260 "Ljava/lang/Object;");
262 if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
267 LLNI_class_get(this, referer);
269 m_parseAnnotationDefault = class_resolveclassmethod(
270 class_sun_reflect_annotation_AnnotationParser,
271 utf_parseAnnotationDefault,
276 if (m_parseAnnotationDefault == NULL) {
277 /* method not found */
282 return (java_lang_Object*)vm_call_method(
283 m_parseAnnotationDefault, NULL,
284 this, this->annotationDefault, constantPool);
289 * Class: java/lang/reflect/Method
290 * Method: declaredAnnotations
291 * Signature: ()Ljava/util/Map;
293 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Method_declaredAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
295 java_handle_t *o = (java_handle_t*)this;
296 struct java_util_Map *declaredAnnotations = NULL;
297 java_handle_bytearray_t *annotations = NULL;
298 java_lang_Class *declaringClass = NULL;
299 classinfo *referer = NULL;
301 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
303 if (declaredAnnotations == NULL) {
304 LLNI_field_get_val(this, annotations, annotations);
305 LLNI_field_get_ref(this, clazz, declaringClass);
306 LLNI_class_get(this, referer);
308 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
310 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
313 return declaredAnnotations;
318 * Class: java/lang/reflect/Method
319 * Method: getParameterAnnotations
320 * Signature: ()[[Ljava/lang/annotation/Annotation;
322 JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_reflect_Method_getParameterAnnotations(JNIEnv *env, java_lang_reflect_Method *this)
324 java_handle_t *o = (java_handle_t*)this;
325 java_handle_bytearray_t *parameterAnnotations = NULL;
327 java_lang_Class *declaringClass = NULL;
328 classinfo *referer = NULL;
330 LLNI_field_get_ref(this, parameterAnnotations, parameterAnnotations);
331 LLNI_field_get_val(this, slot, slot);
332 LLNI_field_get_ref(this, clazz, declaringClass);
333 LLNI_class_get(this, referer);
335 return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, referer);
341 * These are local overrides for various environment variables in Emacs.
342 * Please do not remove this and leave it at the end of the file, where
343 * Emacs will automagically detect them.
344 * ---------------------------------------------------------------------
347 * indent-tabs-mode: t