merge from gnuclasspath branch. I hope I didn't miss or revert any modifications...
[cacao.git] / src / native / vm / Constructor.c
1 /* class: java/lang/reflect/Constructor */
2
3
4 /*
5  * Class:     java/lang/reflect/Constructor
6  * Method:    newInstance
7  * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
8  */
9 JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative( JNIEnv *env ,  struct java_lang_reflect_Constructor* this, 
10         java_objectarray* parameters,struct java_lang_Class* clazz, s4 par3)
11 {
12
13 #warning fix me for parameters float/double and long long  parameters
14
15         methodinfo *m;
16         java_objectheader *o = builtin_new (clazz);         /*          create object */
17
18         
19 /*      log_text("Java_java_lang_reflect_Constructor_constructNative called");
20         utf_display(((struct classinfo*)clazz)->name);
21         printf("\n");*/
22         if (!o) return NULL;
23         
24 /*      printf("o!=NULL\n");*/
25         /* find initializer */
26
27         if (!parameters) {
28                 if (this->parameterTypes->header.size!=0) {
29                         log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative");
30 #warning throw an exception here
31                         return 0;
32                 }
33         } else
34         if (this->parameterTypes->header.size!=parameters->header.size) {
35                 log_text("Parameter count mismatch in Java_java_lang_reflect_Constructor_constructNative");
36 #warning throw an exception here
37                 return 0;
38         }
39
40         m = &((classinfo*)clazz)->methods[this->slot];
41         if (!((m->name == utf_new_char("<init>")) && 
42                   (m->descriptor == create_methodsig(this->parameterTypes,"V"))))
43         {
44                 if (verbose) {
45                         sprintf(logtext, "Warning: class has no instance-initializer of specified type: ");
46                         utf_sprint(logtext + strlen(logtext), ((struct classinfo*)clazz)->name);
47                         dolog();
48                         utf_display( create_methodsig(this->parameterTypes,"V"));
49                         printf("\n");
50                         class_showconstantpool(clazz);
51                         }
52 #warning throw an exception here, although this should never happen
53                 return o;
54                 }
55
56         /* call initializer */
57
58         switch (this->parameterTypes->header.size) {
59                 case 0: exceptionptr=asm_calljavamethod (m, o, NULL, NULL, NULL);
60                         break;
61                 case 1: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], NULL, NULL);
62                         break;
63                 case 2: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], NULL);
64                         break;
65                 case 3: exceptionptr=asm_calljavamethod (m, o, parameters->data[0], parameters->data[1], 
66                                 parameters->data[2]);
67                         break;
68                 default:
69                         log_text("Not supported number of arguments in Java_java_lang_reflect_Constructor");
70         }
71         return o;
72 }
73
74 /*
75  * Class:     java_lang_reflect_Constructor
76  * Method:    getModifiers
77  * Signature: ()I
78  */
79 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiers (JNIEnv *env ,  struct java_lang_reflect_Constructor* this ) {
80         return (this->flag);
81 }