* src/vm/class.h (vm/loader.h): Added.
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Method.c
1 /* src/native/vm/Method.c - java/lang/reflect/Method
2
3    Copyright (C) 1996-2005, 2006 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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Roman Obermaiser
28             Joseph Wenninger
29             Christian Thalinger
30
31    $Id: java_lang_reflect_Method.c 6213 2006-12-18 17:36:06Z twisti $
32
33 */
34
35
36 #include "config.h"
37
38 #include <assert.h>
39
40 #include "vm/types.h"
41
42 #include "native/jni.h"
43 #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_reflect_Method.h"
47 #include "vm/access.h"
48 #include "vm/global.h"
49 #include "vm/builtin.h"
50 #include "vm/exceptions.h"
51 #include "vm/initialize.h"
52 #include "vm/stringlocal.h"
53
54
55 /*
56  * Class:     java/lang/reflect/Method
57  * Method:    getModifiersInternal
58  * Signature: ()I
59  */
60 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
61 {
62         classinfo  *c;
63         methodinfo *m;
64
65         c = (classinfo *) this->declaringClass;
66         m = &(c->methods[this->slot]);
67
68         return m->flags;
69 }
70
71
72 /*
73  * Class:     java/lang/reflect/Method
74  * Method:    getReturnType
75  * Signature: ()Ljava/lang/Class;
76  */
77 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
78 {
79         classinfo  *c;
80         methodinfo *m;
81
82         c = (classinfo *) this->declaringClass;
83         m = &(c->methods[this->slot]);
84
85         return (java_lang_Class *) native_get_returntype(m);
86 }
87
88
89 /*
90  * Class:     java/lang/reflect/Method
91  * Method:    getParameterTypes
92  * Signature: ()[Ljava/lang/Class;
93  */
94 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
95 {
96         classinfo  *c;
97         methodinfo *m;
98
99         c = (classinfo *) this->declaringClass;
100         m = &(c->methods[this->slot]);
101
102         return native_get_parametertypes(m);
103 }
104
105
106 /*
107  * Class:     java/lang/reflect/Method
108  * Method:    getExceptionTypes
109  * Signature: ()[Ljava/lang/Class;
110  */
111 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
112 {
113         classinfo  *c;
114         methodinfo *m;
115
116         c = (classinfo *) this->declaringClass;
117         m = &(c->methods[this->slot]);
118
119         return native_get_exceptiontypes(m);
120 }
121
122
123 /*
124  * Class:     java/lang/reflect/Method
125  * Method:    invokeNative
126  * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
127  */
128 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)
129 {
130         classinfo        *c;
131         methodinfo       *m;
132
133         c = (classinfo *) declaringClass;
134         m = &(c->methods[slot]);
135
136         /* check method access */
137         /* check if we should bypass security checks (AccessibleObject) */
138
139         if (this->flag == false) {
140                 if (!access_check_caller(c, m->flags, 1))
141                         return NULL;
142         }
143
144         /* check if method class is initialized */
145
146         if (!(c->state & CLASS_INITIALIZED))
147                 if (!initialize_class(c))
148                         return NULL;
149
150         /* call the Java method via a helper function */
151
152         return (java_lang_Object *) _Jv_jni_invokeNative(m, (jobject) o, args);
153 }
154
155
156 /*
157  * Class:     java/lang/reflect/Method
158  * Method:    getSignature
159  * Signature: ()Ljava/lang/String;
160  */
161 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(JNIEnv *env, java_lang_reflect_Method* this)
162 {
163         classinfo        *c;
164         methodinfo       *m;
165         java_lang_String *s;
166
167         c = (classinfo *) this->declaringClass;
168         m = &(c->methods[this->slot]);
169
170         if (m->signature == NULL)
171                 return NULL;
172
173         s = javastring_new(m->signature);
174
175         /* in error case, s == NULL */
176
177         return s;
178 }
179
180
181 /*
182  * These are local overrides for various environment variables in Emacs.
183  * Please do not remove this and leave it at the end of the file, where
184  * Emacs will automagically detect them.
185  * ---------------------------------------------------------------------
186  * Local variables:
187  * mode: c
188  * indent-tabs-mode: t
189  * c-basic-offset: 4
190  * tab-width: 4
191  * End:
192  */