* src/native/vm/reflect.c: Fixed includes.
[cacao.git] / src / native / vm / reflect.c
1 /* src/native/vm/reflect.c - helper functions for java/lang/reflect
2
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
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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: java_lang_Class.c 8132 2007-06-22 11:15:47Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <stdint.h>
33
34 #include "native/jni.h"
35 #include "native/native.h"
36
37 /* keep this order of the native includes */
38
39 #include "native/include/java_lang_String.h"
40
41 #if defined(WITH_CLASSPATH_SUN)
42 # include "native/include/java_nio_ByteBuffer.h"        /* required by j.l.CL */
43 #endif
44 #include "native/include/java_lang_ClassLoader.h"
45
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"
51
52 #include "native/vm/java_lang_String.h"
53 #include "native/vm/reflect.h"
54
55 #include "vm/builtin.h"
56 #include "vm/global.h"
57 #include "vm/stringlocal.h"
58
59 #include "vmcore/method.h"
60
61
62 /* reflect_constructor_new *****************************************************
63
64    Allocates a new java.lang.reflect.Constructor object and
65    initializes the fields with the method passed.
66
67 *******************************************************************************/
68
69 java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m)
70 {
71         classinfo                     *c;
72         java_objectheader             *o;
73         java_lang_reflect_Constructor *rc;
74         int32_t                        slot;
75
76         /* get declaring class */
77
78         c = (classinfo *) m->class;
79
80         /* allocate a new object */
81
82         o = builtin_new(class_java_lang_reflect_Constructor);
83
84         if (o == NULL)
85                 return NULL;
86
87         /* initialize instance fields */
88
89         rc = (java_lang_reflect_Constructor *) o;
90
91         /* calculate the slot */
92
93         slot = m - c->methods;
94
95 #if defined(WITH_CLASSPATH_GNU)
96
97         rc->clazz                = (java_lang_Class *) c;
98         rc->slot                 = slot;
99
100 #elif defined(WITH_CLASSPATH_SUN)
101
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;
106         rc->slot                 = slot;
107         rc->signature            = m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL;
108         rc->annotations          = NULL;
109         rc->parameterAnnotations = NULL;
110
111 #else
112 # error unknown classpath configuration
113 #endif
114
115         return rc;
116 }
117
118
119 /* reflect_field_new ***********************************************************
120
121    Allocates a new java.lang.reflect.Field object and initializes the
122    fields with the field passed.
123
124 *******************************************************************************/
125
126 java_lang_reflect_Field *reflect_field_new(fieldinfo *f)
127 {
128         classinfo               *c;
129         java_objectheader       *o;
130         java_lang_reflect_Field *rf;
131         int32_t                  slot;
132
133         /* get declaring class */
134
135         c = (classinfo *) f->class;
136
137         /* allocate a new object */
138
139         o = builtin_new(class_java_lang_reflect_Field);
140
141         if (o == NULL)
142                 return NULL;
143
144         /* initialize instance fields */
145
146         rf = (java_lang_reflect_Field *) o;
147
148         /* calculate the slot */
149
150         slot = f - c->fields;
151
152 #if defined(WITH_CLASSPATH_GNU)
153
154         rf->clazz = (java_lang_Class *) c;
155
156         /* The name needs to be interned */
157         /* XXX implement me better! */
158
159         rf->name           = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(f->name));
160         rf->slot           = slot;
161
162 #elif defined(WITH_CLASSPATH_SUN)
163
164         rf->clazz          = (java_lang_Class *) c;
165
166         /* The name needs to be interned */
167         /* XXX implement me better! */
168
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;
172         rf->slot           = slot;
173         rf->signature      = f->signature ? (java_lang_String *) javastring_new(f->signature) : NULL;
174         rf->annotations    = NULL;
175
176 #else
177 # error unknown classpath configuration
178 #endif
179
180         return rf;
181 }
182
183
184 /* reflect_method_new **********************************************************
185
186    Allocates a new java.lang.reflect.Method object and initializes the
187    fields with the method passed.
188
189 *******************************************************************************/
190
191 java_lang_reflect_Method *reflect_method_new(methodinfo *m)
192 {
193         classinfo                *c;
194         java_objectheader        *o;
195         java_lang_reflect_Method *rm;
196         int32_t                   slot;
197
198         /* get declaring class */
199
200         c = (classinfo *) m->class;
201
202         /* allocate a new object */
203
204         o = builtin_new(class_java_lang_reflect_Method);
205
206         if (o == NULL)
207                 return NULL;
208
209         /* initialize instance fields */
210
211         rm = (java_lang_reflect_Method *) o;
212
213         /* calculate the slot */
214
215         slot = m - c->methods;
216
217 #if defined(WITH_CLASSPATH_GNU)
218
219         rm->clazz                = (java_lang_Class *) m->class;
220
221         /* The name needs to be interned */
222         /* XXX implement me better! */
223
224         rm->name                 = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(m->name));
225         rm->slot                 = slot;
226
227 #elif defined(WITH_CLASSPATH_SUN)
228
229         rm->clazz                = (java_lang_Class *) m->class;
230
231         /* The name needs to be interned */
232         /* XXX implement me better! */
233
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;
239         rm->slot                 = slot;
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;
244
245 #else
246 # error unknown classpath configuration
247 #endif
248
249         return rm;
250 }
251
252
253 /*
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  * ---------------------------------------------------------------------
258  * Local variables:
259  * mode: c
260  * indent-tabs-mode: t
261  * c-basic-offset: 4
262  * tab-width: 4
263  * End:
264  * vim:noexpandtab:sw=4:ts=4:
265  */