96888b0808aefea4d70538f3abe28eff2841c8c5
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Method.c
1 /* src/native/vm/gnu/java_lang_reflect_Method.c
2
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
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    $Id: java_lang_reflect_Method.c 8132 2007-06-22 11:15:47Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33
34 #include "vm/types.h"
35
36 #include "native/jni.h"
37 #include "native/native.h"
38
39 #include "native/include/java_lang_Object.h"
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_String.h"
42
43 #include "native/include/java_lang_reflect_Method.h"
44
45 #include "native/vm/java_lang_reflect_Method.h"
46
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/resolve.h"
53 #include "vm/stringlocal.h"
54
55 #include "vmcore/method.h"
56
57
58 /* native methods implemented by this file ************************************/
59
60 static JNINativeMethod methods[] = {
61         { "getModifiersInternal", "()I",                                                                         (void *) (ptrint) &Java_java_lang_reflect_Method_getModifiersInternal },
62         { "getReturnType",        "()Ljava/lang/Class;",                                                         (void *) (ptrint) &Java_java_lang_reflect_Method_getReturnType        },
63         { "getParameterTypes",    "()[Ljava/lang/Class;",                                                        (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterTypes    },
64         { "getExceptionTypes",    "()[Ljava/lang/Class;",                                                        (void *) (ptrint) &Java_java_lang_reflect_Method_getExceptionTypes    },
65         { "invokeNative",         "(Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_invokeNative         },
66         { "getSignature",         "()Ljava/lang/String;",                                                        (void *) (ptrint) &Java_java_lang_reflect_Method_getSignature         },
67 };
68
69
70 /* _Jv_java_lang_reflect_Method_init *******************************************
71
72    Register native functions.
73
74 *******************************************************************************/
75
76 void _Jv_java_lang_reflect_Method_init(void)
77 {
78         utf *u;
79
80         u = utf_new_char("java/lang/reflect/Method");
81
82         native_method_register(u, methods, NATIVE_METHODS_COUNT);
83 }
84
85
86 /*
87  * Class:     java/lang/reflect/Method
88  * Method:    getModifiersInternal
89  * Signature: ()I
90  */
91 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
92 {
93         classinfo  *c;
94         methodinfo *m;
95
96         c = (classinfo *) this->clazz;
97         m = &(c->methods[this->slot]);
98
99         return m->flags;
100 }
101
102
103 /*
104  * Class:     java/lang/reflect/Method
105  * Method:    getReturnType
106  * Signature: ()Ljava/lang/Class;
107  */
108 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
109 {
110         classinfo  *c;
111         methodinfo *m;
112         classinfo  *result;
113
114         c = (classinfo *) this->clazz;
115         m = &(c->methods[this->slot]);
116
117         result = method_returntype_get(m);
118
119         return (java_lang_Class *) result;
120 }
121
122
123 /*
124  * Class:     java/lang/reflect/Method
125  * Method:    getParameterTypes
126  * Signature: ()[Ljava/lang/Class;
127  */
128 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
129 {
130         classinfo  *c;
131         methodinfo *m;
132
133         c = (classinfo *) this->clazz;
134         m = &(c->methods[this->slot]);
135
136         return method_get_parametertypearray(m);
137 }
138
139
140 /*
141  * Class:     java/lang/reflect/Method
142  * Method:    getExceptionTypes
143  * Signature: ()[Ljava/lang/Class;
144  */
145 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
146 {
147         classinfo  *c;
148         methodinfo *m;
149
150         c = (classinfo *) this->clazz;
151         m = &(c->methods[this->slot]);
152
153         return method_get_exceptionarray(m);
154 }
155
156
157 /*
158  * Class:     java/lang/reflect/Method
159  * Method:    invokeNative
160  * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
161  */
162 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)
163 {
164         /* just to be sure */
165
166         assert(this->clazz == clazz);
167         assert(this->slot           == slot);
168
169         return _Jv_java_lang_reflect_Method_invoke(this, o, args);
170 }
171
172
173 /*
174  * Class:     java/lang/reflect/Method
175  * Method:    getSignature
176  * Signature: ()Ljava/lang/String;
177  */
178 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(JNIEnv *env, java_lang_reflect_Method* this)
179 {
180         classinfo         *c;
181         methodinfo        *m;
182         java_objectheader *o;
183
184         c = (classinfo *) this->clazz;
185         m = &(c->methods[this->slot]);
186
187         if (m->signature == NULL)
188                 return NULL;
189
190         o = javastring_new(m->signature);
191
192         /* in error case o is NULL */
193
194         return (java_lang_String *) o;
195 }
196
197
198 /*
199  * These are local overrides for various environment variables in Emacs.
200  * Please do not remove this and leave it at the end of the file, where
201  * Emacs will automagically detect them.
202  * ---------------------------------------------------------------------
203  * Local variables:
204  * mode: c
205  * indent-tabs-mode: t
206  * c-basic-offset: 4
207  * tab-width: 4
208  * End:
209  */