1 /* native/vm/Field.c - java/lang/reflect/Field
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
31 $Id: Field.c 1803 2004-12-22 09:27:58Z jowenn $
36 #include "native/jni.h"
37 #include "native/native.h"
38 #include "native/include/java_lang_Object.h"
39 #include "native/include/java_lang_Class.h"
40 #include "native/include/java_lang_reflect_Field.h"
41 #include "vm/builtin.h"
42 #include "vm/exceptions.h"
43 #include "vm/loader.h"
44 #include "vm/tables.h"
45 #include "vm/loader.h"
46 #include "vm/global.h"
47 #include "vm/builtin.h"
48 #include "vm/jit/stacktrace.h"
49 #include "vm/exceptions.h"
54 #warning FIXE SET NATIVES
57 #if (defined(__ALPHA__) || defined(__I386__))
58 /*this = java_lang_reflect_Field, fi=fieldinfo, c=declaredClass (classinfo)*/
59 #define CHECKFIELDACCESS(this,fi,c,doret) \
60 /*log_text("Checking access rights");*/ \
61 if (!(getField(this,jboolean,getFieldID_critical(env,this->header.vftbl->class,"flag","Z")))) { \
63 struct methodinfo *callingMethod; \
65 if ((fi->flags & ACC_PUBLIC)==0) { \
66 callingMethod=cacao_callingMethod(); \
68 if ((fi->flags & ACC_PRIVATE)!=0) { \
69 if (c!=callingMethod->class) { \
73 if ((fi->flags & ACC_PROTECTED)!=0) { \
74 if (!builtin_isanysubclass(callingMethod->class, c)) { \
78 /* default visibility*/ \
79 if (c->packagename!=callingMethod->class->packagename) { \
87 *exceptionptr = new_exception(string_java_lang_IllegalAccessException); \
92 #define CHECKFIELDACCESS(this,fi,c,doret)
102 * Class: java/lang/reflect/Field
104 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
106 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
108 jfieldID target_fid; /* the JNI-fieldid of the wrapping object */
109 jfieldID fid; /* the JNI-fieldid of the field containing the value */
110 jobject o; /* the object for wrapping the primitive type */
111 classinfo *c = (classinfo *) this->declaringClass;
114 /* get the fieldid of the field represented by this Field-object */
115 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
116 /*fid = class_findfield_approx((classinfo *) this->declaringClass,javastring_toutf(this->name, false));*/
117 st = (fid->flags & ACC_STATIC); /* true if field is static */
120 CHECKFIELDACCESS(this,fid,c,return 0);
122 /* The fieldid is used to retrieve the value, for primitive types a new
123 object for wrapping the primitive type is created. */
125 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
127 /* create wrapping class */
128 c = class_java_lang_Integer;
130 /* get fieldid to store the value */
131 target_fid = (*env)->GetFieldID(env, c, "value", "I");
137 SetIntField(env,o,target_fid, (*env)->GetStaticIntField(env, c, fid));
140 SetIntField(env,o,target_fid, (*env)->GetIntField(env,(jobject) obj, fid));
142 /* return the wrapped object */
143 return (java_lang_Object *) o;
146 c = class_java_lang_Long;
148 target_fid = (*env)->GetFieldID(env, c, "value", "J");
153 SetLongField(env,o,target_fid, (*env)->GetStaticLongField(env, c, fid));
155 SetLongField(env,o,target_fid, (*env)->GetLongField(env,(jobject) obj, fid));
157 return (java_lang_Object *) o;
160 c = class_java_lang_Float;
162 target_fid = (*env)->GetFieldID(env, c, "value", "F");
167 SetFloatField(env,o,target_fid, (*env)->GetStaticFloatField(env, c, fid));
169 SetFloatField(env,o,target_fid, (*env)->GetFloatField(env, (jobject) obj, fid));
171 return (java_lang_Object *) o;
174 c = class_java_lang_Double;
176 target_fid = (*env)->GetFieldID(env, c, "value", "D");
181 SetDoubleField(env,o,target_fid, (*env)->GetStaticDoubleField(env, c, fid));
183 SetDoubleField(env,o,target_fid, (*env)->GetDoubleField(env, (jobject) obj, fid));
185 return (java_lang_Object *) o;
188 c = class_java_lang_Byte;
190 target_fid = (*env)->GetFieldID(env, c, "value", "B");
195 SetByteField(env,o,target_fid, (*env)->GetStaticByteField(env, c, fid));
197 SetByteField(env,o,target_fid, (*env)->GetByteField(env, (jobject) obj, fid));
199 return (java_lang_Object *) o;
202 c = class_java_lang_Character;
204 target_fid = (*env)->GetFieldID(env, c, "value", "C");
209 SetCharField(env,o,target_fid, (*env)->GetStaticCharField(env, c, fid));
211 SetCharField(env,o,target_fid, (*env)->GetCharField(env, (jobject) obj, fid));
213 return (java_lang_Object *) o;
216 c = class_java_lang_Short;
218 target_fid = (*env)->GetFieldID(env, c, "value", "S");
223 SetShortField(env,o,target_fid, (*env)->GetStaticShortField(env, c, fid));
225 SetShortField(env,o,target_fid, (*env)->GetShortField(env, (jobject) obj, fid));
227 return (java_lang_Object *) o;
230 c = class_java_lang_Boolean;
232 target_fid = (*env)->GetFieldID(env, c, "value", "Z");
237 SetBooleanField(env,o,target_fid, (*env)->GetStaticBooleanField(env, c, fid));
239 SetBooleanField(env,o,target_fid, (*env)->GetBooleanField(env, (jobject) obj, fid));
241 return (java_lang_Object *) o;
247 return (java_lang_Object*) (*env)->GetStaticObjectField(env, c, fid);
250 return (java_lang_Object*) (*env)->GetObjectField(env, (jobject) obj, fid);
253 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
260 * Class: java/lang/reflect/Field
262 * Signature: (Ljava/lang/Object;)Z
264 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
268 classinfo *c = (classinfo *) this->declaringClass;
271 /* check if the specified slot could be a valid field of this class*/
272 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
273 "declaring class: fieldscount mismatch");
275 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
276 CHECKFIELDACCESS(this,fid,c,return 0);
278 /* check if the field really has the same name and check if the type descriptor is not empty*/
279 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
280 "declaring class: field name mismatch");
281 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
283 /* check if obj would be needed (not static field), but is 0)*/
284 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
285 *exceptionptr = new_exception(string_java_lang_NullPointerException);
289 /*if (!(fid->flags & ACC_PUBLIC)) {
290 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
295 if (fid->flags & ACC_STATIC) {
296 /* initialize class if needed*/
297 class_init((classinfo*)this->declaringClass);
298 if (*exceptionptr) return 0;
300 utf_ptr = fid->descriptor->text;
302 case 'Z': return fid->value.i;
304 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
308 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
309 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
312 utf_ptr = fid->descriptor->text;
314 case 'Z':return getField(obj,jboolean,fid);
316 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
324 * Class: java/lang/reflect/Field
326 * Signature: (Ljava/lang/Object;)B
328 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
332 classinfo *c = (classinfo *) this->declaringClass;
335 /* check if the specified slot could be a valid field of this class*/
336 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
337 "declaring class: fieldscount mismatch");
339 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
341 CHECKFIELDACCESS(this,fid,c,return 0);
343 /* check if the field really has the same name and check if the type descriptor is not empty*/
344 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
345 "declaring class: field name mismatch");
346 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
348 /* check if obj would be needed (not static field), but is 0)*/
349 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
350 *exceptionptr = new_exception(string_java_lang_NullPointerException);
354 /* if (!(fid->flags & ACC_PUBLIC)) {
355 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
360 if (fid->flags & ACC_STATIC) {
361 /* initialize class if needed*/
362 class_init((classinfo*)this->declaringClass);
363 if (*exceptionptr) return 0;
365 utf_ptr = fid->descriptor->text;
367 case 'B': return fid->value.i;
369 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
373 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
374 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
377 utf_ptr = fid->descriptor->text;
379 case 'B':return getField(obj,jbyte,fid);
381 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
389 * Class: java/lang/reflect/Field
391 * Signature: (Ljava/lang/Object;)C
393 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
397 classinfo *c = (classinfo *) this->declaringClass;
400 /* check if the specified slot could be a valid field of this class*/
401 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
402 "declaring class: fieldscount mismatch");
404 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
405 CHECKFIELDACCESS(this,fid,c,return 0);
408 /* check if the field really has the same name and check if the type descriptor is not empty*/
409 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
410 "declaring class: field name mismatch");
411 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
413 /* check if obj would be needed (not static field), but is 0)*/
414 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
415 *exceptionptr = new_exception(string_java_lang_NullPointerException);
419 /*if (!(fid->flags & ACC_PUBLIC)) {
420 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
425 if (fid->flags & ACC_STATIC) {
426 /* initialize class if needed*/
427 class_init((classinfo*)this->declaringClass);
428 if (*exceptionptr) return 0;
430 utf_ptr = fid->descriptor->text;
432 case 'C': return fid->value.i;
434 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
438 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
439 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
442 utf_ptr = fid->descriptor->text;
444 case 'C':return getField(obj,jchar,fid);
446 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
454 * Class: java/lang/reflect/Field
456 * Signature: (Ljava/lang/Object;)D
458 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
462 classinfo *c = (classinfo *) this->declaringClass;
465 /* check if the specified slot could be a valid field of this class*/
466 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
467 "declaring class: fieldscount mismatch");
469 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
470 CHECKFIELDACCESS(this,fid,c,return 0);
473 /* check if the field really has the same name and check if the type descriptor is not empty*/
474 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
475 "declaring class: field name mismatch");
476 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
478 /* check if obj would be needed (not static field), but is 0)*/
479 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
480 *exceptionptr = new_exception(string_java_lang_NullPointerException);
484 /*if (!(fid->flags & ACC_PUBLIC)) {
485 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
490 if (fid->flags & ACC_STATIC) {
491 /* initialize class if needed*/
492 class_init((classinfo*)this->declaringClass);
493 if (*exceptionptr) return 0;
495 utf_ptr = fid->descriptor->text;
500 case 'I': return fid->value.i;
501 case 'F': return fid->value.f;
502 case 'D': return fid->value.d;
504 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
508 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
509 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
512 utf_ptr = fid->descriptor->text;
514 case 'B':return getField(obj,jbyte,fid);
515 case 'S':return getField(obj,jshort,fid);
516 case 'C':return getField(obj,jchar,fid);
517 case 'I':return getField(obj,jint,fid);
518 case 'D':return getField(obj,jdouble,fid);
520 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
528 * Class: java/lang/reflect/Field
530 * Signature: (Ljava/lang/Object;)F
532 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
536 classinfo *c = (classinfo *) this->declaringClass;
539 /* check if the specified slot could be a valid field of this class*/
540 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
541 "declaring class: fieldscount mismatch");
543 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
544 CHECKFIELDACCESS(this,fid,c,return 0);
547 /* check if the field really has the same name and check if the type descriptor is not empty*/
548 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
549 "declaring class: field name mismatch");
550 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
552 /* check if obj would be needed (not static field), but is 0)*/
553 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
554 *exceptionptr = new_exception(string_java_lang_NullPointerException);
558 /*if (!(fid->flags & ACC_PUBLIC)) {
559 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
564 if (fid->flags & ACC_STATIC) {
565 /* initialize class if needed*/
566 class_init((classinfo*)this->declaringClass);
567 if (*exceptionptr) return 0;
569 utf_ptr = fid->descriptor->text;
574 case 'I': return fid->value.i;
575 case 'F': return fid->value.f;
577 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
581 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
582 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
585 utf_ptr = fid->descriptor->text;
587 case 'B':return getField(obj,jbyte,fid);
588 case 'S':return getField(obj,jshort,fid);
589 case 'C':return getField(obj,jchar,fid);
590 case 'I':return getField(obj,jint,fid);
591 case 'F':return getField(obj,jfloat,fid);
593 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
601 * Class: java/lang/reflect/Field
603 * Signature: (Ljava/lang/Object;)I
605 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
609 classinfo *c = (classinfo *) this->declaringClass;
612 /* check if the specified slot could be a valid field of this class*/
613 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
614 "declaring class: fieldscount mismatch");
616 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
617 CHECKFIELDACCESS(this,fid,c,return 0);
619 /* check if the field really has the same name and check if the type descriptor is not empty*/
620 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
621 "declaring class: field name mismatch");
622 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
624 /* check if obj would be needed (not static field), but is 0)*/
625 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
626 *exceptionptr = new_exception(string_java_lang_NullPointerException);
630 /*if (!(fid->flags & ACC_PUBLIC)) {
631 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
636 if (fid->flags & ACC_STATIC) {
637 /* initialize class if needed*/
638 class_init((classinfo*)this->declaringClass);
639 if (*exceptionptr) return 0;
641 utf_ptr = fid->descriptor->text;
646 case 'I': return fid->value.i;
648 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
652 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
653 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
656 utf_ptr = fid->descriptor->text;
658 case 'B':return getField(obj,jbyte,fid);
659 case 'S':return getField(obj,jshort,fid);
660 case 'C':return getField(obj,jchar,fid);
661 case 'I':return getField(obj,jint,fid);
663 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
671 * Class: java/lang/reflect/Field
673 * Signature: (Ljava/lang/Object;)J
675 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
679 classinfo *c = (classinfo *) this->declaringClass;
682 /* check if the specified slot could be a valid field of this class*/
683 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
684 "declaring class: fieldscount mismatch");
686 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
687 CHECKFIELDACCESS(this,fid,c,return 0);
690 /* check if the field really has the same name and check if the type descriptor is not empty*/
691 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
692 "declaring class: field name mismatch");
693 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
695 /* check if obj would be needed (not static field), but is 0)*/
696 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
697 *exceptionptr = new_exception(string_java_lang_NullPointerException);
701 /*if (!(fid->flags & ACC_PUBLIC)) {
702 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
707 if (fid->flags & ACC_STATIC) {
708 /* initialize class if needed*/
709 class_init((classinfo*)this->declaringClass);
710 if (*exceptionptr) return 0;
712 utf_ptr = fid->descriptor->text;
717 case 'I': return fid->value.i;
718 case 'J': return fid->value.l;
720 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
724 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
725 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
728 utf_ptr = fid->descriptor->text;
730 case 'B':return getField(obj,jbyte,fid);
731 case 'S':return getField(obj,jshort,fid);
732 case 'C':return getField(obj,jchar,fid);
733 case 'I':return getField(obj,jint,fid);
734 case 'J':return getField(obj,jlong,fid);
736 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
744 * Class: java/lang/reflect/Field
746 * Signature: (Ljava/lang/Object;)S
748 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
752 classinfo *c = (classinfo *) this->declaringClass;
755 /* check if the specified slot could be a valid field of this class*/
756 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
757 "declaring class: fieldscount mismatch");
759 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
760 CHECKFIELDACCESS(this,fid,c,return 0);
763 /* check if the field really has the same name and check if the type descriptor is not empty*/
764 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
765 "declaring class: field name mismatch");
766 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
768 /* check if obj would be needed (not static field), but is 0)*/
769 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
770 *exceptionptr = new_exception(string_java_lang_NullPointerException);
774 /*if (!(fid->flags & ACC_PUBLIC)) {
775 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
780 if (fid->flags & ACC_STATIC) {
781 /* initialize class if needed*/
782 class_init((classinfo*)this->declaringClass);
783 if (*exceptionptr) return 0;
785 utf_ptr = fid->descriptor->text;
788 case 'S': return fid->value.i;
790 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
794 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
795 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
798 utf_ptr = fid->descriptor->text;
800 case 'B':return getField(obj,jbyte,fid);
801 case 'S':return getField(obj,jshort,fid);
803 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
811 * Class: java/lang/reflect/Field
813 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
815 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, java_lang_Object *val)
817 jfieldID source_fid; /* the field containing the value to be written */
818 jfieldID fid; /* the field to be written */
822 fid = class_findfield_approx((classinfo *) this->declaringClass,
823 javastring_toutf(this->name, false));
824 st = (fid->flags & ACC_STATIC); /* true if the field is static */
825 CHECKFIELDACCESS(this,fid,((classinfo *) this->declaringClass),return);
827 if (val && (st || obj)) {
829 c = val->header.vftbl->class;
831 /* The fieldid is used to set the new value, for primitive types the value
832 has to be retrieved from the wrapping object */
833 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
835 /* illegal argument specified */
836 if (c != class_java_lang_Integer)
838 /* determine the field to read the value */
839 source_fid = (*env)->GetFieldID(env, c, "value", "I");
843 /* set the new value */
846 (*env)->SetStaticIntField(env, c, fid, GetIntField(env, (jobject) val, source_fid));
849 (*env)->SetIntField(env, (jobject) obj, fid, GetIntField(env, (jobject) val, source_fid));
854 if (c != class_java_lang_Long)
856 source_fid = (*env)->GetFieldID(env, c, "value", "J");
861 (*env)->SetStaticLongField(env, c, fid, GetLongField(env, (jobject) val, source_fid));
863 (*env)->SetLongField(env, (jobject) obj, fid, GetLongField(env, (jobject) val, source_fid));
868 if (c != class_java_lang_Float)
870 source_fid = (*env)->GetFieldID(env, c, "value", "F");
875 (*env)->SetStaticFloatField(env, c, fid, GetFloatField(env, (jobject) val, source_fid));
877 (*env)->SetFloatField(env, (jobject) obj, fid, GetFloatField(env, (jobject) val, source_fid));
882 if (c != class_java_lang_Double)
884 source_fid = (*env)->GetFieldID(env, c, "value", "D");
885 if (!source_fid) break;
888 (*env)->SetStaticDoubleField(env, c, fid, GetDoubleField(env,(jobject) val,source_fid));
890 (*env)->SetDoubleField(env, (jobject) obj, fid, GetDoubleField(env,(jobject) val,source_fid));
895 if (c != class_java_lang_Byte)
897 source_fid = (*env)->GetFieldID(env, c, "value", "B");
902 (*env)->SetStaticByteField(env, c, fid, GetByteField(env, (jobject) val, source_fid));
904 (*env)->SetByteField(env, (jobject) obj, fid, GetByteField(env, (jobject) val, source_fid));
909 if (c != class_java_lang_Character)
911 source_fid = (*env)->GetFieldID(env, c, "value", "C");
916 (*env)->SetStaticCharField(env, c, fid, GetCharField(env, (jobject) val, source_fid));
918 (*env)->SetCharField(env, (jobject) obj, fid, GetCharField(env, (jobject) val, source_fid));
923 if (c != class_java_lang_Short)
925 source_fid = (*env)->GetFieldID(env, c, "value", "S");
930 (*env)->SetStaticShortField(env, c, fid, GetShortField(env, (jobject) val, source_fid));
932 (*env)->SetShortField(env, (jobject) obj, fid, GetShortField(env, (jobject) val, source_fid));
937 if (c != class_java_lang_Boolean)
939 source_fid = (*env)->GetFieldID(env, c, "value", "Z");
944 (*env)->SetStaticBooleanField(env, c, fid, GetBooleanField(env, (jobject) val, source_fid));
946 (*env)->SetBooleanField(env, (jobject) obj, fid, GetBooleanField(env, (jobject) val, source_fid));
953 (*env)->SetStaticObjectField(env, c, fid, (jobject) val);
955 (*env)->SetObjectField(env, (jobject) obj, fid, (jobject) val);
961 /* raise exception */
962 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
967 * Class: java/lang/reflect/Field
969 * Signature: (Ljava/lang/Object;Z)V
971 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
975 if (this->declaringClass && obj) {
976 fid = class_findfield_approx((classinfo *) this->declaringClass,
977 javastring_toutf(this->name, false));
980 (*env)->SetBooleanField(env, (jobject) obj, fid, val);
985 /* raise exception */
986 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
991 * Class: java/lang/reflect/Field
993 * Signature: (Ljava/lang/Object;B)V
995 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
999 if (this->declaringClass && obj) {
1000 fid = class_findfield_approx((classinfo *) this->declaringClass,
1001 javastring_toutf(this->name, false));
1004 (*env)->SetByteField(env, (jobject) obj, fid, val);
1009 /* raise exception */
1010 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1015 * Class: java/lang/reflect/Field
1017 * Signature: (Ljava/lang/Object;C)V
1019 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1023 if (this->declaringClass && obj) {
1024 fid = class_findfield_approx((classinfo *) this->declaringClass,
1025 javastring_toutf(this->name, false));
1028 (*env)->SetCharField(env, (jobject) obj, fid, val);
1033 /* raise exception */
1034 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1039 * Class: java/lang/reflect/Field
1041 * Signature: (Ljava/lang/Object;D)V
1043 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, double val)
1047 if (this->declaringClass && obj) {
1048 fid = class_findfield_approx((classinfo *) this->declaringClass,
1049 javastring_toutf(this->name, false));
1052 (*env)->SetDoubleField(env, (jobject) obj, fid, val);
1057 /* raise exception */
1058 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1063 * Class: java/lang/reflect/Field
1065 * Signature: (Ljava/lang/Object;F)V
1067 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, float val)
1071 if (this->declaringClass && obj) {
1072 fid = class_findfield_approx((classinfo *) this->declaringClass,
1073 javastring_toutf(this->name, false));
1076 (*env)->SetFloatField(env, (jobject) obj, fid, val);
1081 /* raise exception */
1082 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1087 * Class: java/lang/reflect/Field
1089 * Signature: (Ljava/lang/Object;I)V
1091 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1095 if (this->declaringClass && obj) {
1096 fid = class_findfield_approx((classinfo *) this->declaringClass,
1097 javastring_toutf(this->name, false));
1100 (*env)->SetIntField(env, (jobject) obj, fid, val);
1105 /* raise exception */
1106 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1111 * Class: java/lang/reflect/Field
1113 * Signature: (Ljava/lang/Object;J)V
1115 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s8 val)
1119 if (this->declaringClass && obj) {
1120 fid = class_findfield_approx((classinfo *) this->declaringClass,
1121 javastring_toutf(this->name, false));
1124 (*env)->SetLongField(env, (jobject) obj, fid, val);
1129 /* raise exception */
1130 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1135 * Class: java/lang/reflect/Field
1137 * Signature: (Ljava/lang/Object;S)V
1139 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1143 if (this->declaringClass && obj) {
1144 fid = class_findfield_approx((classinfo *) this->declaringClass,
1145 javastring_toutf(this->name, false));
1148 (*env)->SetShortField(env, (jobject) obj, fid, val);
1153 /* raise exception */
1154 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1159 * Class: java_lang_reflect_Field
1161 * Signature: ()Ljava/lang/Class;
1163 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
1165 utf *desc = (((classinfo *) this->declaringClass)->fields[this->slot]).descriptor;
1166 java_lang_Class *ret;
1170 ret=(java_lang_Class *) class_from_descriptor(desc->text, utf_end(desc), NULL, CLASSLOAD_LOAD);
1171 use_class_as_object((classinfo*)ret);
1177 * Class: java_lang_reflect_Field
1178 * Method: getModifiers
1181 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiers(JNIEnv *env, java_lang_reflect_Field *this)
1183 return (((classinfo *) this->declaringClass)->fields[this->slot]).flags;
1188 * These are local overrides for various environment variables in Emacs.
1189 * Please do not remove this and leave it at the end of the file, where
1190 * Emacs will automagically detect them.
1191 * ---------------------------------------------------------------------
1194 * indent-tabs-mode: t