a22bdacd14e24d1a29c60d9a7ca281a27edcb9f9
[cacao.git] / src / native / vm / gnuclasspath / java_lang_reflect_VMConstructor.cpp
1 /* src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <stdlib.h>
30
31 #include "native/jni.h"
32 #include "native/llni.h"
33 #include "native/native.h"
34
35 #if defined(ENABLE_JNI_HEADERS)
36 # include "native/vm/include/java_lang_reflect_VMConstructor.h"
37 #endif
38
39 #include "native/vm/reflection.hpp"
40
41 #include "vm/javaobjects.hpp"
42 #include "vm/string.hpp"
43 #include "vm/utf8.h"
44
45
46 // Native functions are exported as C functions.
47 extern "C" {
48
49 /*
50  * Class:     java/lang/reflect/VMConstructor
51  * Method:    getModifiersInternal
52  * Signature: ()I
53  */
54 JNIEXPORT jint JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, jobject _this)
55 {
56         java_lang_reflect_VMConstructor rvmc(_this);
57         methodinfo* m = rvmc.get_method();
58         return m->flags;
59 }
60
61
62 /*
63  * Class:     java/lang/reflect/VMConstructor
64  * Method:    getParameterTypes
65  * Signature: ()[Ljava/lang/Class;
66  */
67 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, jobject _this)
68 {
69         java_lang_reflect_VMConstructor rvmc(_this);
70         methodinfo* m = rvmc.get_method();
71
72         java_handle_objectarray_t* hoa = method_get_parametertypearray(m);
73
74         return (jobjectArray) hoa;
75 }
76
77
78 /*
79  * Class:     java/lang/reflect/VMConstructor
80  * Method:    getExceptionTypes
81  * Signature: ()[Ljava/lang/Class;
82  */
83 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, jobject _this)
84 {
85         java_lang_reflect_VMConstructor rvmc(_this);
86         methodinfo* m = rvmc.get_method();
87
88         java_handle_objectarray_t* hoa = method_get_exceptionarray(m);
89
90         return (jobjectArray) hoa;
91 }
92
93
94 /*
95  * Class:     java/lang/reflect/VMConstructor
96  * Method:    construct
97  * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
98  */
99 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, jobject _this, jobjectArray args)
100 {
101         java_lang_reflect_VMConstructor jlrvmc(_this);
102         java_lang_reflect_Constructor jlrc(jlrvmc.get_cons());
103
104         java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args);
105
106         return (jobject) o;
107 }
108
109
110 /*
111  * Class:     java/lang/reflect/VMConstructor
112  * Method:    getSignature
113  * Signature: ()Ljava/lang/String;
114  */
115 JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, jobject _this)
116 {
117         java_lang_reflect_VMConstructor rvmc(_this);
118         methodinfo* m = rvmc.get_method();
119         java_handle_t *o;
120
121         if (m->signature == NULL)
122                 return NULL;
123
124         o = javastring_new(m->signature);
125
126         /* In error case o is NULL. */
127
128         return (jstring) o;
129 }
130
131
132 #if defined(ENABLE_ANNOTATIONS)
133 /*
134  * Class:     java/lang/reflect/VMConstructor
135  * Method:    declaredAnnotations
136  * Signature: ()Ljava/util/Map;
137  *
138  * Parses the annotations (if they aren't parsed yet) and stores them into
139  * the declaredAnnotations map and return this map.
140  */
141 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, jobject _this)
142 {
143         java_lang_reflect_VMConstructor rvmc(_this);
144
145         java_handle_t* declaredAnnotations = rvmc.get_declaredAnnotations();
146
147         /* are the annotations parsed yet? */
148         if (declaredAnnotations == NULL) {
149                 java_handle_bytearray_t* annotations    = rvmc.get_annotations();
150                 classinfo*               declaringClass = rvmc.get_clazz();
151
152                 classinfo *referer;
153                 LLNI_class_get(_this, referer);
154
155                 declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer);
156
157                 rvmc.set_declaredAnnotations(declaredAnnotations);
158         }
159
160         return (jobject) declaredAnnotations;
161 }
162
163
164 /*
165  * Class:     java/lang/reflect/VMConstructor
166  * Method:    getParameterAnnotations
167  * Signature: ()[[Ljava/lang/annotation/Annotation;
168  *
169  * Parses the parameter annotations and returns them in an 2 dimensional array.
170  */
171 JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, jobject _this)
172 {
173         java_lang_reflect_VMConstructor rvmc(_this);
174
175         java_handle_bytearray_t* parameterAnnotations = rvmc.get_parameterAnnotations();
176         methodinfo* m = rvmc.get_method();
177
178         classinfo* referer;
179         LLNI_class_get((java_lang_reflect_VMConstructor*) _this, referer);
180
181         java_handle_objectarray_t* oa = Reflection::get_parameterannotations(parameterAnnotations, m, referer);
182
183         return (jobjectArray) oa;
184 }
185 #endif
186
187 } // extern "C"
188
189
190 /* native methods implemented by this file ************************************/
191
192 static JNINativeMethod methods[] = {
193         { (char*) "getModifiersInternal",    (char*) "()I",                                     (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal    },
194         { (char*) "getParameterTypes",       (char*) "()[Ljava/lang/Class;",                    (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes       },
195         { (char*) "getExceptionTypes",       (char*) "()[Ljava/lang/Class;",                    (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes       },
196         { (char*) "construct",               (char*) "([Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_construct               },
197         { (char*) "getSignature",            (char*) "()Ljava/lang/String;",                    (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getSignature            },
198 #if defined(ENABLE_ANNOTATIONS)
199         { (char*) "declaredAnnotations",     (char*) "()Ljava/util/Map;",                       (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations     },
200         { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;",   (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations },
201 #endif
202 };
203
204
205 /* _Jv_java_lang_reflect_VMConstructor_init ************************************
206
207    Register native functions.
208
209 *******************************************************************************/
210
211 extern "C" {
212 void _Jv_java_lang_reflect_VMConstructor_init(void)
213 {
214         utf *u;
215
216         u = utf_new_char("java/lang/reflect/VMConstructor");
217
218         native_method_register(u, methods, NATIVE_METHODS_COUNT);
219 }
220 }
221
222
223 /*
224  * These are local overrides for various environment variables in Emacs.
225  * Please do not remove this and leave it at the end of the file, where
226  * Emacs will automagically detect them.
227  * ---------------------------------------------------------------------
228  * Local variables:
229  * mode: c++
230  * indent-tabs-mode: t
231  * c-basic-offset: 4
232  * tab-width: 4
233  * End:
234  */