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 8311 2007-08-15 17:03:40Z 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 (java_lang_Class *) result;
143 * Class: java/lang/reflect/Method
144 * Method: getParameterTypes
145 * Signature: ()[Ljava/lang/Class;
147 JNIEXPORT java_objectarray* 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_objectarray* 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_objectarray *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;
238 exceptions_throw_nullpointerexception();
243 (sun_reflect_ConstantPool*)native_new_and_init(
244 class_sun_reflect_ConstantPool);
246 if(constantPool == NULL) {
251 LLNI_field_get_ref(this, clazz, constantPoolOop);
252 LLNI_field_set_ref(constantPool, constantPoolOop, (java_lang_Object*)constantPoolOop);
254 /* only resolve the method the first time */
255 if (m_parseAnnotationDefault == NULL) {
256 utf_parseAnnotationDefault = utf_new_char("parseAnnotationDefault");
257 utf_desc = utf_new_char(
258 "(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;)"
259 "Ljava/lang/Object;");
261 if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
266 m_parseAnnotationDefault = class_resolveclassmethod(
267 class_sun_reflect_annotation_AnnotationParser,
268 utf_parseAnnotationDefault,
273 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, struct java_lang_reflect_Method* this)
293 java_handle_t *o = (java_handle_t*)this;
294 struct java_util_Map *declaredAnnotations = NULL;
295 java_bytearray *annotations = NULL;
296 java_lang_Class *declaringClass = NULL;
299 exceptions_throw_nullpointerexception();
303 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
305 if (declaredAnnotations == NULL) {
306 LLNI_field_get_val(this, annotations, annotations);
307 LLNI_field_get_ref(this, clazz, declaringClass);
309 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, o->vftbl->class);
311 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
314 return declaredAnnotations;
319 * Class: java/lang/reflect/Method
320 * Method: getParameterAnnotations
321 * Signature: ()[[Ljava/lang/annotation/Annotation;
323 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterAnnotations(JNIEnv *env, struct java_lang_reflect_Method* this)
325 java_handle_t *o = (java_handle_t*)this;
326 java_bytearray *parameterAnnotations = NULL;
328 java_lang_Class *declaringClass = NULL;
331 exceptions_throw_nullpointerexception();
335 LLNI_field_get_ref(this, parameterAnnotations, parameterAnnotations);
336 LLNI_field_get_val(this, slot, slot);
337 LLNI_field_get_ref(this, clazz, declaringClass);
339 return reflect_get_parameterannotations((java_handle_t*)parameterAnnotations, slot, declaringClass, o->vftbl->class);
345 * These are local overrides for various environment variables in Emacs.
346 * Please do not remove this and leave it at the end of the file, where
347 * Emacs will automagically detect them.
348 * ---------------------------------------------------------------------
351 * indent-tabs-mode: t