c3936f2aa227f984e5bbe9491b0bdc6655b6ebdc
[cacao.git] / src / native / vm / Method.c
1 /* nat/Method.c - java/lang/reflect/Method
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Roman Obermaiser
28
29    Changes: Joseph Wenninger
30
31    $Id: Method.c 1537 2004-11-18 12:12:05Z twisti $
32
33 */
34
35
36 #include "jni.h"
37 #include "loader.h"
38 #include "global.h"
39 #include "tables.h"
40 #include "types.h"
41 #include "builtin.h"
42 #include "native.h"
43 #include "toolbox/logging.h"
44 #include "nat/java_lang_Object.h"
45 #include "nat/java_lang_Class.h"
46 #include "nat/java_lang_reflect_Method.h"
47
48
49 /*
50  * Class:     java_lang_reflect_Method
51  * Method:    getModifiers
52  * Signature: ()I
53  */
54 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiers(JNIEnv *env, java_lang_reflect_Method *this)
55 {
56         classinfo *c = (classinfo *) this->declaringClass;
57
58         if (this->slot < 0 || this->slot >= c->methodscount)
59                 panic("error illegal slot for method in class (getReturnType)");
60         
61         return (c->methods[this->slot]).flags &
62                 (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_ABSTRACT | ACC_STATIC | ACC_FINAL |
63                  ACC_SYNCHRONIZED | ACC_NATIVE | ACC_STRICT);
64 }
65
66
67 /*
68  * Class:     java_lang_reflect_Method
69  * Method:    getReturnType
70  * Signature: ()Ljava/lang/Class;
71  */
72 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
73 {
74         classinfo *c = (classinfo *) this->declaringClass;
75
76         if (this->slot < 0 || this->slot >= c->methodscount)
77                 panic("error illegal slot for method in class (getReturnType)");
78
79         return (java_lang_Class *) get_returntype(&(c->methods[this->slot]));
80 }
81
82
83 /*
84  * Class:     java_lang_reflect_Method
85  * Method:    getParameterTypes
86  * Signature: ()[Ljava/lang/Class;
87  */
88 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
89 {
90         classinfo *c = (classinfo *) this->declaringClass;
91
92         if (this->slot < 0 || this->slot >= c->methodscount)
93                 panic("error illegal slot for method in class(getParameterTypes)");
94
95         return get_parametertypes(&(c->methods[this->slot]));
96 }
97
98
99 /*
100  * Class:     java_lang_reflect_Method
101  * Method:    getExceptionTypes
102  * Signature: ()[Ljava/lang/Class;
103  */
104 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
105 {
106         classinfo *c = (classinfo *) this->declaringClass;
107
108         if (this->slot < 0 || this->slot >= c->methodscount)
109                 panic("error illegal slot for method in class(getExceptionTypes)");
110
111         return get_exceptiontypes(&(c->methods[this->slot]));
112
113 }
114
115
116 /*
117  * Class:     java_lang_reflect_Method
118  * Method:    invokeNative
119  * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
120  */
121 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *obj, java_objectarray *params, java_lang_Class *declaringClass, s4 slot)
122 {
123     struct methodinfo *mi;
124
125     classinfo *c = (classinfo *) declaringClass;
126     if (slot < 0 || slot >= c->methodscount) {
127                 panic("error illegal slot for method in class(getParameterTypes)");
128     }
129
130     mi = &(c->methods[slot]);
131
132     return (java_lang_Object *) jni_method_invokeNativeHelper(env, mi, (jobject) obj, params);
133 }
134
135
136 /*
137  * These are local overrides for various environment variables in Emacs.
138  * Please do not remove this and leave it at the end of the file, where
139  * Emacs will automagically detect them.
140  * ---------------------------------------------------------------------
141  * Local variables:
142  * mode: c
143  * indent-tabs-mode: t
144  * c-basic-offset: 4
145  * tab-width: 4
146  * End:
147  */