1 /* src/native/vm/reflect.c - helper functions for java/lang/reflect
3 Copyright (C) 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
8 This file is part of CACAO.
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.
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.
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
25 $Id: java_lang_Class.c 8132 2007-06-22 11:15:47Z twisti $
34 #include "native/jni.h"
35 #include "native/native.h"
37 /* keep this order of the native includes */
39 #include "native/include/java_lang_String.h"
41 #if defined(WITH_CLASSPATH_SUN)
42 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
44 #include "native/include/java_lang_ClassLoader.h"
46 #include "native/include/java_lang_Object.h"
47 #include "native/include/java_lang_Class.h"
48 #include "native/include/java_lang_reflect_Constructor.h"
49 #include "native/include/java_lang_reflect_Field.h"
50 #include "native/include/java_lang_reflect_Method.h"
52 #include "native/vm/java_lang_String.h"
53 #include "native/vm/reflect.h"
55 #include "vm/builtin.h"
56 #include "vm/global.h"
57 #include "vm/stringlocal.h"
59 #include "vmcore/method.h"
62 /* reflect_constructor_new *****************************************************
64 Allocates a new java.lang.reflect.Constructor object and
65 initializes the fields with the method passed.
67 *******************************************************************************/
69 java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m)
73 java_lang_reflect_Constructor *rc;
76 /* get declaring class */
78 c = (classinfo *) m->class;
80 /* allocate a new object */
82 o = builtin_new(class_java_lang_reflect_Constructor);
87 /* initialize instance fields */
89 rc = (java_lang_reflect_Constructor *) o;
91 /* calculate the slot */
93 slot = m - c->methods;
95 #if defined(WITH_CLASSPATH_GNU)
97 rc->clazz = (java_lang_Class *) c;
100 #elif defined(WITH_CLASSPATH_SUN)
102 rc->clazz = (java_lang_Class *) c;
103 rc->parameterTypes = method_get_parametertypearray(m);
104 rc->exceptionTypes = method_get_exceptionarray(m);
105 rc->modifiers = m->flags & ACC_CLASS_REFLECT_MASK;
107 rc->signature = m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL;
108 rc->annotations = NULL;
109 rc->parameterAnnotations = NULL;
112 # error unknown classpath configuration
119 /* reflect_field_new ***********************************************************
121 Allocates a new java.lang.reflect.Field object and initializes the
122 fields with the field passed.
124 *******************************************************************************/
126 java_lang_reflect_Field *reflect_field_new(fieldinfo *f)
129 java_objectheader *o;
130 java_lang_reflect_Field *rf;
133 /* get declaring class */
135 c = (classinfo *) f->class;
137 /* allocate a new object */
139 o = builtin_new(class_java_lang_reflect_Field);
144 /* initialize instance fields */
146 rf = (java_lang_reflect_Field *) o;
148 /* calculate the slot */
150 slot = f - c->fields;
152 #if defined(WITH_CLASSPATH_GNU)
154 rf->clazz = (java_lang_Class *) c;
156 /* The name needs to be interned */
157 /* XXX implement me better! */
159 rf->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(f->name));
162 #elif defined(WITH_CLASSPATH_SUN)
164 rf->clazz = (java_lang_Class *) c;
166 /* The name needs to be interned */
167 /* XXX implement me better! */
169 rf->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(f->name));
170 rf->type = (java_lang_Class *) field_get_type(f);
171 rf->modifiers = f->flags;
173 rf->signature = f->signature ? (java_lang_String *) javastring_new(f->signature) : NULL;
174 rf->annotations = NULL;
177 # error unknown classpath configuration
184 /* reflect_method_new **********************************************************
186 Allocates a new java.lang.reflect.Method object and initializes the
187 fields with the method passed.
189 *******************************************************************************/
191 java_lang_reflect_Method *reflect_method_new(methodinfo *m)
194 java_objectheader *o;
195 java_lang_reflect_Method *rm;
198 /* get declaring class */
200 c = (classinfo *) m->class;
202 /* allocate a new object */
204 o = builtin_new(class_java_lang_reflect_Method);
209 /* initialize instance fields */
211 rm = (java_lang_reflect_Method *) o;
213 /* calculate the slot */
215 slot = m - c->methods;
217 #if defined(WITH_CLASSPATH_GNU)
219 rm->clazz = (java_lang_Class *) m->class;
221 /* The name needs to be interned */
222 /* XXX implement me better! */
224 rm->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(m->name));
227 #elif defined(WITH_CLASSPATH_SUN)
229 rm->clazz = (java_lang_Class *) m->class;
231 /* The name needs to be interned */
232 /* XXX implement me better! */
234 rm->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(m->name));
235 rm->parameterTypes = method_get_parametertypearray(m);
236 rm->returnType = (java_lang_Class *) method_returntype_get(m);
237 rm->exceptionTypes = method_get_exceptionarray(m);
238 rm->modifiers = m->flags & ACC_CLASS_REFLECT_MASK;
240 rm->signature = m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL;
241 rm->annotations = NULL;
242 rm->parameterAnnotations = NULL;
243 rm->annotationDefault = NULL;
246 # error unknown classpath configuration
254 * These are local overrides for various environment variables in Emacs.
255 * Please do not remove this and leave it at the end of the file, where
256 * Emacs will automagically detect them.
257 * ---------------------------------------------------------------------
260 * indent-tabs-mode: t
264 * vim:noexpandtab:sw=4:ts=4: