- we now build a libnat.a
[cacao.git] / nat / Constructor.c
1 /* class: java/lang/reflect/Constructor */
2
3
4 #include "jni.h"
5 #include "builtin.h"
6 #include "loader.h"
7 #include "native.h"
8 #include "tables.h"
9 #include "asmpart.h"
10 #include "java_lang_Class.h"
11 #include "java_lang_reflect_Constructor.h"
12
13
14 /*
15  * Class:     java/lang/reflect/Constructor
16  * Method:    newInstance
17  * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
18  */
19 JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative( JNIEnv *env ,  struct java_lang_reflect_Constructor* this, 
20         java_objectarray* parameters,struct java_lang_Class* clazz, s4 par3)
21 {
22
23 #warning fix me for parameters float/double and long long  parameters
24
25         methodinfo *m;
26         java_objectheader *o;
27
28         
29 /*      log_text("Java_java_lang_reflect_Constructor_constructNative called");
30         utf_display(((struct classinfo*)clazz)->name);*/
31         printf("\n");
32
33         /* find initializer */
34
35         if (!parameters) {
36                 if (this->parameterTypes->header.size!=0) {
37                         log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative(1)");
38 #warning throw an exception here
39                         return 0;
40                 }
41         } else
42         if (this->parameterTypes->header.size!=parameters->header.size) {
43                 log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative(2)");
44 #warning throw an exception here
45                 return 0;
46         }
47
48         if (this->slot>=((classinfo*)clazz)->methodscount) {
49                 log_text("illegal index in methods table");
50                 return 0;
51         }
52
53         o = builtin_new (clazz);         /*          create object */
54         if (!o) {
55                 log_text("Objet instance could not be created");
56                 return NULL;
57         }
58         
59 /*      log_text("o!=NULL\n");*/
60
61
62         m = &((classinfo*)clazz)->methods[this->slot];
63         if (!((m->name == utf_new_char("<init>")) && 
64                   (m->descriptor == create_methodsig(this->parameterTypes,"V"))))
65         {
66                 if (verbose) {
67                         sprintf(logtext, "Warning: class has no instance-initializer of specified type: ");
68                         utf_sprint(logtext + strlen(logtext), ((struct classinfo*)clazz)->name);
69                         dolog();
70                         utf_display( create_methodsig(this->parameterTypes,"V"));
71                         printf("\n");
72                         class_showconstantpool(clazz);
73                         }
74 #warning throw an exception here, although this should never happen
75                 return o;
76                 }
77
78 /*      log_text("calling initializer");*/
79         /* call initializer */
80
81         switch (this->parameterTypes->header.size) {
82                 case 0: exceptionptr=asm_calljavamethod (m, o, NULL, NULL, NULL);
83                         break;
84                 case 1: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], NULL, NULL);
85                         break;
86                 case 2: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], NULL);
87                         break;
88                 case 3: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], 
89                                 parameters->data[2]);
90                         break;
91                 default:
92                         log_text("Not supported number of arguments in Java_java_lang_reflect_Constructor");
93         }
94         return o;
95 }
96
97 /*
98  * Class:     java_lang_reflect_Constructor
99  * Method:    getModifiers
100  * Signature: ()I
101  */
102 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiers (JNIEnv *env ,  struct java_lang_reflect_Constructor* this ) {
103         log_text("Java_java_lang_reflect_Constructor_getModifiers called");
104         classinfo *c=(classinfo*)(this->clazz);
105         if ((this->slot<0) || (this->slot>=c->methodscount))
106                 panic("error illegal slot for method in class (getReturnType)");
107         return (c->methods[this->slot]).flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
108 }
109
110
111 /*
112  * These are local overrides for various environment variables in Emacs.
113  * Please do not remove this and leave it at the end of the file, where
114  * Emacs will automagically detect them.
115  * ---------------------------------------------------------------------
116  * Local variables:
117  * mode: c
118  * indent-tabs-mode: t
119  * c-basic-offset: 4
120  * tab-width: 4
121  * End:
122  */