8205bd9ae85ba3d2b36c7bb4d0766950c0fcad1d
[cacao.git] / src / native / vm / Method.c
1 /* native/vm/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 1621 2004-11-30 13:06:55Z twisti $
32
33 */
34
35
36 #include "types.h"
37 #include "native/jni.h"
38 #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_reflect_Method.h"
42 #include "toolbox/logging.h"
43
44
45 /*
46  * Class:     java_lang_reflect_Method
47  * Method:    getModifiers
48  * Signature: ()I
49  */
50 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiers(JNIEnv *env, java_lang_reflect_Method *this)
51 {
52         classinfo *c = (classinfo *) this->declaringClass;
53
54         if (this->slot < 0 || this->slot >= c->methodscount)
55                 panic("error illegal slot for method in class (getReturnType)");
56         
57         return (c->methods[this->slot]).flags &
58                 (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_ABSTRACT | ACC_STATIC | ACC_FINAL |
59                  ACC_SYNCHRONIZED | ACC_NATIVE | ACC_STRICT);
60 }
61
62
63 /*
64  * Class:     java_lang_reflect_Method
65  * Method:    getReturnType
66  * Signature: ()Ljava/lang/Class;
67  */
68 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
69 {
70         classinfo *c = (classinfo *) this->declaringClass;
71
72         if (this->slot < 0 || this->slot >= c->methodscount)
73                 panic("error illegal slot for method in class (getReturnType)");
74
75         return (java_lang_Class *) get_returntype(&(c->methods[this->slot]));
76 }
77
78
79 /*
80  * Class:     java_lang_reflect_Method
81  * Method:    getParameterTypes
82  * Signature: ()[Ljava/lang/Class;
83  */
84 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
85 {
86         classinfo *c = (classinfo *) this->declaringClass;
87
88         if (this->slot < 0 || this->slot >= c->methodscount)
89                 panic("error illegal slot for method in class(getParameterTypes)");
90
91         return get_parametertypes(&(c->methods[this->slot]));
92 }
93
94
95 /*
96  * Class:     java_lang_reflect_Method
97  * Method:    getExceptionTypes
98  * Signature: ()[Ljava/lang/Class;
99  */
100 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
101 {
102         classinfo *c = (classinfo *) this->declaringClass;
103
104         if (this->slot < 0 || this->slot >= c->methodscount)
105                 panic("error illegal slot for method in class(getExceptionTypes)");
106
107         return get_exceptiontypes(&(c->methods[this->slot]));
108
109 }
110
111
112 /*
113  * Class:     java_lang_reflect_Method
114  * Method:    invokeNative
115  * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
116  */
117 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)
118 {
119     struct methodinfo *mi;
120
121     classinfo *c = (classinfo *) declaringClass;
122     if (slot < 0 || slot >= c->methodscount) {
123                 panic("error illegal slot for method in class(getParameterTypes)");
124     }
125
126     mi = &(c->methods[slot]);
127
128     return (java_lang_Object *) jni_method_invokeNativeHelper(env, mi, (jobject) obj, params);
129 }
130
131
132 /*
133  * These are local overrides for various environment variables in Emacs.
134  * Please do not remove this and leave it at the end of the file, where
135  * Emacs will automagically detect them.
136  * ---------------------------------------------------------------------
137  * Local variables:
138  * mode: c
139  * indent-tabs-mode: t
140  * c-basic-offset: 4
141  * tab-width: 4
142  * End:
143  */