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