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 $
36 #include "native/jni.h"
37 #include "native/native.h"
39 /* keep this order of the native includes */
41 #include "native/include/java_lang_String.h"
43 #if defined(ENABLE_JAVASE)
44 # if defined(WITH_CLASSPATH_SUN)
45 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
47 # include "native/include/java_lang_ClassLoader.h"
50 #include "native/include/java_lang_Object.h"
51 #include "native/include/java_lang_Class.h"
53 #if defined(ENABLE_JAVASE)
54 # include "native/include/java_lang_reflect_Constructor.h"
55 # include "native/include/java_lang_reflect_Field.h"
56 # include "native/include/java_lang_reflect_Method.h"
59 #include "native/vm/reflect.h"
61 #include "vm/builtin.h"
62 #include "vm/global.h"
64 #include "vmcore/method.h"
67 /* reflect_constructor_new *****************************************************
69 Allocates a new java.lang.reflect.Constructor object and
70 initializes the fields with the method passed.
72 *******************************************************************************/
74 java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m)
78 java_lang_reflect_Constructor *rc;
81 /* get declaring class */
83 c = (classinfo *) m->class;
85 /* allocate a new object */
87 o = builtin_new(class_java_lang_reflect_Constructor);
92 /* initialize instance fields */
94 rc = (java_lang_reflect_Constructor *) o;
96 /* calculate the slot */
98 slot = m - c->methods;
100 #if defined(WITH_CLASSPATH_GNU)
102 rc->clazz = (java_lang_Class *) c;
105 #elif defined(WITH_CLASSPATH_SUN)
107 rc->clazz = (java_lang_Class *) c;
108 rc->parameterTypes = method_get_parametertypearray(m);
109 rc->exceptionTypes = method_get_exceptionarray(m);
110 rc->modifiers = m->flags & ACC_CLASS_REFLECT_MASK;
112 rc->signature = m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL;
113 rc->annotations = NULL;
114 rc->parameterAnnotations = NULL;
117 # error unknown classpath configuration
124 /* reflect_field_new ***********************************************************
126 Allocates a new java.lang.reflect.Field object and initializes the
127 fields with the field passed.
129 *******************************************************************************/
131 java_lang_reflect_Field *reflect_field_new(fieldinfo *f)
134 java_objectheader *o;
135 java_lang_reflect_Field *rf;
138 /* get declaring class */
140 c = (classinfo *) f->class;
142 /* allocate a new object */
144 o = builtin_new(class_java_lang_reflect_Field);
149 /* initialize instance fields */
151 rf = (java_lang_reflect_Field *) o;
153 /* calculate the slot */
155 slot = f - c->fields;
157 #if defined(WITH_CLASSPATH_GNU)
159 rf->clazz = (java_lang_Class *) c;
161 /* The name needs to be interned */
162 /* XXX implement me better! */
164 rf->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(f->name));
167 #elif defined(WITH_CLASSPATH_SUN)
169 rf->clazz = (java_lang_Class *) c;
171 /* The name needs to be interned */
172 /* XXX implement me better! */
174 rf->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(f->name));
175 rf->type = (java_lang_Class *) field_get_type(f);
176 rf->modifiers = f->flags;
178 rf->signature = f->signature ? (java_lang_String *) javastring_new(f->signature) : NULL;
179 rf->annotations = NULL;
182 # error unknown classpath configuration
189 /* reflect_method_new **********************************************************
191 Allocates a new java.lang.reflect.Method object and initializes the
192 fields with the method passed.
194 *******************************************************************************/
196 java_lang_reflect_Method *reflect_method_new(methodinfo *m)
199 java_objectheader *o;
200 java_lang_reflect_Method *rm;
203 /* get declaring class */
205 c = (classinfo *) m->class;
207 /* allocate a new object */
209 o = builtin_new(class_java_lang_reflect_Method);
214 /* initialize instance fields */
216 rm = (java_lang_reflect_Method *) o;
218 /* calculate the slot */
220 slot = m - c->methods;
222 #if defined(WITH_CLASSPATH_GNU)
224 rm->clazz = (java_lang_Class *) m->class;
226 /* The name needs to be interned */
227 /* XXX implement me better! */
229 rm->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(m->name));
232 #elif defined(WITH_CLASSPATH_SUN)
234 rm->clazz = (java_lang_Class *) m->class;
236 /* The name needs to be interned */
237 /* XXX implement me better! */
239 rm->name = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(m->name));
240 rm->parameterTypes = method_get_parametertypearray(m);
241 rm->returnType = (java_lang_Class *) method_returntype_get(m);
242 rm->exceptionTypes = method_get_exceptionarray(m);
243 rm->modifiers = m->flags & ACC_CLASS_REFLECT_MASK;
245 rm->signature = m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL;
246 rm->annotations = NULL;
247 rm->parameterAnnotations = NULL;
248 rm->annotationDefault = NULL;
251 # error unknown classpath configuration
259 * These are local overrides for various environment variables in Emacs.
260 * Please do not remove this and leave it at the end of the file, where
261 * Emacs will automagically detect them.
262 * ---------------------------------------------------------------------
265 * indent-tabs-mode: t
269 * vim:noexpandtab:sw=4:ts=4: