CACAO
java_lang_reflect_VMConstructor.cpp
Go to the documentation of this file.
1 /* src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp
2 
3  Copyright (C) 1996-2013
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.hpp"
32 #include "native/llni.hpp"
33 #include "native/native.hpp"
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.hpp"
44 #include "vm/vm.hpp"
45 
46 
47 // Native functions are exported as C functions.
48 extern "C" {
49 
50 /*
51  * Class: java/lang/reflect/VMConstructor
52  * Method: getModifiersInternal
53  * Signature: ()I
54  */
56 {
58  methodinfo* m = rvmc.get_method();
59  return m->flags;
60 }
61 
62 
63 /*
64  * Class: java/lang/reflect/VMConstructor
65  * Method: getParameterTypes
66  * Signature: ()[Ljava/lang/Class;
67  */
69 {
71  methodinfo* m = rvmc.get_method();
72 
74 
75  return (jobjectArray) hoa;
76 }
77 
78 
79 /*
80  * Class: java/lang/reflect/VMConstructor
81  * Method: getExceptionTypes
82  * Signature: ()[Ljava/lang/Class;
83  */
85 {
87  methodinfo* m = rvmc.get_method();
88 
90 
91  return (jobjectArray) hoa;
92 }
93 
94 
95 /*
96  * Class: java/lang/reflect/VMConstructor
97  * Method: construct
98  * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
99  */
101 {
102  java_lang_reflect_VMConstructor jlrvmc(_this);
104 
105  java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args);
106 
107  return (jobject) o;
108 }
109 
110 
111 /*
112  * Class: java/lang/reflect/VMConstructor
113  * Method: getSignature
114  * Signature: ()Ljava/lang/String;
115  */
117 {
119  methodinfo* m = rvmc.get_method();
120  java_handle_t *o;
121 
122  if (m->signature == NULL)
123  return NULL;
124 
126 
127  /* In error case o is NULL. */
128 
129  return (jstring) o;
130 }
131 
132 
133 #if defined(ENABLE_ANNOTATIONS)
134 /*
135  * Class: java/lang/reflect/VMConstructor
136  * Method: declaredAnnotations
137  * Signature: ()Ljava/util/Map;
138  *
139  * Parses the annotations (if they aren't parsed yet) and stores them into
140  * the declaredAnnotations map and return this map.
141  */
143 {
145 
146  java_handle_t* declaredAnnotations = rvmc.get_declaredAnnotations();
147 
148  /* are the annotations parsed yet? */
149  if (declaredAnnotations == NULL) {
150  java_handle_bytearray_t* annotations = rvmc.get_annotations();
151  classinfo* declaringClass = rvmc.get_clazz();
152  classinfo* referer = rvmc.get_Class();
153 
154  declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer);
155 
156  rvmc.set_declaredAnnotations(declaredAnnotations);
157  }
158 
159  return (jobject) declaredAnnotations;
160 }
161 
162 
163 /*
164  * Class: java/lang/reflect/VMConstructor
165  * Method: getParameterAnnotations
166  * Signature: ()[[Ljava/lang/annotation/Annotation;
167  *
168  * Parses the parameter annotations and returns them in an 2 dimensional array.
169  */
171 {
173 
174  java_handle_bytearray_t* parameterAnnotations = rvmc.get_parameterAnnotations();
175  methodinfo* m = rvmc.get_method();
176  classinfo* referer = rvmc.get_Class();
177 
178  java_handle_objectarray_t* oa = Reflection::get_parameterannotations(parameterAnnotations, m, referer);
179 
180  return (jobjectArray) oa;
181 }
182 #endif
183 
184 } // extern "C"
185 
186 
187 /* native methods implemented by this file ************************************/
188 
189 static JNINativeMethod methods[] = {
190  { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getModifiersInternal },
191  { (char*) "getParameterTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterTypes },
192  { (char*) "getExceptionTypes", (char*) "()[Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getExceptionTypes },
193  { (char*) "construct", (char*) "([Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_construct },
194  { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getSignature },
195 #if defined(ENABLE_ANNOTATIONS)
196  { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_declaredAnnotations },
197  { (char*) "getParameterAnnotations", (char*) "()[[Ljava/lang/annotation/Annotation;", (void*) (uintptr_t) &Java_java_lang_reflect_VMConstructor_getParameterAnnotations },
198 #endif
199 };
200 
201 
202 /* _Jv_java_lang_reflect_VMConstructor_init ************************************
203 
204  Register native functions.
205 
206 *******************************************************************************/
207 
209 {
210  Utf8String u = Utf8String::from_utf8("java/lang/reflect/VMConstructor");
211 
214 }
215 
216 
217 /*
218  * These are local overrides for various environment variables in Emacs.
219  * Please do not remove this and leave it at the end of the file, where
220  * Emacs will automagically detect them.
221  * ---------------------------------------------------------------------
222  * Local variables:
223  * mode: c++
224  * indent-tabs-mode: t
225  * c-basic-offset: 4
226  * tab-width: 4
227  * End:
228  */
static java_handle_t * get_declaredannotations(java_handle_bytearray_t *annotations, classinfo *declaringClass, classinfo *referer)
Definition: reflection.cpp:143
java_handle_bytearray_t * get_parameterAnnotations() const
static JNINativeMethod methods[]
Table containing all native methods registered with the VM.
Definition: native.hpp:132
classinfo * get_clazz() const
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
Definition: native.cpp:242
JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_construct(JNIEnv *env, jobject _this, jobjectArray args)
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
static JavaString from_utf8(Utf8String)
Definition: string.cpp:184
JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMConstructor_declaredAnnotations(JNIEnv *env, jobject _this)
GNU Classpath java/lang/reflect/VMConstructor.
static java_handle_objectarray_t * get_parameterannotations(java_handle_bytearray_t *parameterAnnotations, methodinfo *m, classinfo *referer)
Definition: reflection.cpp:198
classinfo * get_Class() const
java_handle_bytearray_t * get_annotations() const
java_handle_objectarray_t * method_get_parametertypearray(methodinfo *m)
Definition: method.cpp:774
Utf8String signature
Definition: method.hpp:74
GNU Classpath java/lang/reflect/Constructor.
void set_declaredAnnotations(java_handle_t *value)
JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMConstructor_getSignature(JNIEnv *env, jobject _this)
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
java_handle_t * get_declaredAnnotations() const
JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterAnnotations(JNIEnv *env, jobject _this)
JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getExceptionTypes(JNIEnv *env, jobject _this)
s4 flags
Definition: method.hpp:70
java_handle_objectarray_t * method_get_exceptionarray(methodinfo *m)
Definition: method.cpp:824
void _Jv_java_lang_reflect_VMConstructor_init(void)
JNIEXPORT jobjectArray JNICALL Java_java_lang_reflect_VMConstructor_getParameterTypes(JNIEnv *env, jobject _this)
static VM * get_current()
Definition: vm.hpp:99
java_handle_t * get_cons() const
JNIEXPORT jint JNICALL Java_java_lang_reflect_VMConstructor_getModifiersInternal(JNIEnv *env, jobject _this)