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 7976 2007-05-29 12:22:55Z twisti $
36 #include "native/jni.h"
37 #include "native/native.h"
39 #include "native/include/java_lang_Object.h"
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_String.h"
43 #include "native/include/java_lang_reflect_Method.h"
45 #include "vm/access.h"
46 #include "vm/global.h"
47 #include "vm/builtin.h"
48 #include "vm/exceptions.h"
49 #include "vm/initialize.h"
50 #include "vm/resolve.h"
51 #include "vm/stringlocal.h"
54 /* native methods implemented by this file ************************************/
56 static JNINativeMethod methods[] = {
57 { "getModifiersInternal", "()I", (void *) (ptrint) &Java_java_lang_reflect_Method_getModifiersInternal },
58 { "getReturnType", "()Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getReturnType },
59 { "getParameterTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterTypes },
60 { "getExceptionTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getExceptionTypes },
61 { "invokeNative", "(Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_invokeNative },
62 { "getSignature", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_reflect_Method_getSignature },
66 /* _Jv_java_lang_reflect_Method_init *******************************************
68 Register native functions.
70 *******************************************************************************/
72 void _Jv_java_lang_reflect_Method_init(void)
76 u = utf_new_char("java/lang/reflect/Method");
78 native_method_register(u, methods, NATIVE_METHODS_COUNT);
83 * Class: java/lang/reflect/Method
84 * Method: getModifiersInternal
87 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
92 c = (classinfo *) this->declaringClass;
93 m = &(c->methods[this->slot]);
100 * Class: java/lang/reflect/Method
101 * Method: getReturnType
102 * Signature: ()Ljava/lang/Class;
104 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
110 c = (classinfo *) this->declaringClass;
111 m = &(c->methods[this->slot]);
113 td = &(m->parseddesc->returntype);
115 if (!resolve_class_from_typedesc(td, true, false, &c))
118 return (java_lang_Class *) c;
123 * Class: java/lang/reflect/Method
124 * Method: getParameterTypes
125 * Signature: ()[Ljava/lang/Class;
127 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
132 c = (classinfo *) this->declaringClass;
133 m = &(c->methods[this->slot]);
135 return method_get_parametertypearray(m);
140 * Class: java/lang/reflect/Method
141 * Method: getExceptionTypes
142 * Signature: ()[Ljava/lang/Class;
144 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
149 c = (classinfo *) this->declaringClass;
150 m = &(c->methods[this->slot]);
152 return method_get_exceptionarray(m);
157 * Class: java/lang/reflect/Method
158 * Method: invokeNative
159 * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
161 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 *declaringClass, s4 slot)
166 c = (classinfo *) declaringClass;
167 m = &(c->methods[slot]);
169 /* check method access */
171 /* check if we should bypass security checks (AccessibleObject) */
173 if (this->flag == false) {
174 if (!access_check_method(m, 1))
178 /* check if method class is initialized */
180 if (!(c->state & CLASS_INITIALIZED))
181 if (!initialize_class(c))
184 /* call the Java method via a helper function */
186 return (java_lang_Object *) _Jv_jni_invokeNative(m, (jobject) o, args);
191 * Class: java/lang/reflect/Method
192 * Method: getSignature
193 * Signature: ()Ljava/lang/String;
195 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(JNIEnv *env, java_lang_reflect_Method* this)
199 java_objectheader *o;
201 c = (classinfo *) this->declaringClass;
202 m = &(c->methods[this->slot]);
204 if (m->signature == NULL)
207 o = javastring_new(m->signature);
209 /* in error case o is NULL */
211 return (java_lang_String *) o;
216 * These are local overrides for various environment variables in Emacs.
217 * Please do not remove this and leave it at the end of the file, where
218 * Emacs will automagically detect them.
219 * ---------------------------------------------------------------------
222 * indent-tabs-mode: t