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 1765 2004-12-15 17:25:04Z 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"
50 * Class: java/lang/reflect/Field
52 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
54 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
56 jfieldID target_fid; /* the JNI-fieldid of the wrapping object */
57 jfieldID fid; /* the JNI-fieldid of the field containing the value */
58 jobject o; /* the object for wrapping the primitive type */
59 classinfo *c = (classinfo *) this->declaringClass;
60 int st = (this->flag & ACC_STATIC); /* true if field is static */
62 /* get the fieldid of the field represented by this Field-object */
63 fid = class_findfield_approx((classinfo *) this->declaringClass,javastring_toutf(this->name, false));
65 /* The fieldid is used to retrieve the value, for primitive types a new
66 object for wrapping the primitive type is created. */
68 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
70 /* create wrapping class */
71 c = class_java_lang_Integer;
73 /* get fieldid to store the value */
74 target_fid = (*env)->GetFieldID(env, c, "value", "I");
80 SetIntField(env,o,target_fid, (*env)->GetStaticIntField(env, c, fid));
83 SetIntField(env,o,target_fid, (*env)->GetIntField(env,(jobject) obj, fid));
85 /* return the wrapped object */
86 return (java_lang_Object *) o;
89 c = class_java_lang_Long;
91 target_fid = (*env)->GetFieldID(env, c, "value", "J");
96 SetLongField(env,o,target_fid, (*env)->GetStaticLongField(env, c, fid));
98 SetLongField(env,o,target_fid, (*env)->GetLongField(env,(jobject) obj, fid));
100 return (java_lang_Object *) o;
103 c = class_java_lang_Float;
105 target_fid = (*env)->GetFieldID(env, c, "value", "F");
110 SetFloatField(env,o,target_fid, (*env)->GetStaticFloatField(env, c, fid));
112 SetFloatField(env,o,target_fid, (*env)->GetFloatField(env, (jobject) obj, fid));
114 return (java_lang_Object *) o;
117 c = class_java_lang_Double;
119 target_fid = (*env)->GetFieldID(env, c, "value", "D");
124 SetDoubleField(env,o,target_fid, (*env)->GetStaticDoubleField(env, c, fid));
126 SetDoubleField(env,o,target_fid, (*env)->GetDoubleField(env, (jobject) obj, fid));
128 return (java_lang_Object *) o;
131 c = class_java_lang_Byte;
133 target_fid = (*env)->GetFieldID(env, c, "value", "B");
138 SetByteField(env,o,target_fid, (*env)->GetStaticByteField(env, c, fid));
140 SetByteField(env,o,target_fid, (*env)->GetByteField(env, (jobject) obj, fid));
142 return (java_lang_Object *) o;
145 c = class_java_lang_Character;
147 target_fid = (*env)->GetFieldID(env, c, "value", "C");
152 SetCharField(env,o,target_fid, (*env)->GetStaticCharField(env, c, fid));
154 SetCharField(env,o,target_fid, (*env)->GetCharField(env, (jobject) obj, fid));
156 return (java_lang_Object *) o;
159 c = class_java_lang_Short;
161 target_fid = (*env)->GetFieldID(env, c, "value", "S");
166 SetShortField(env,o,target_fid, (*env)->GetStaticShortField(env, c, fid));
168 SetShortField(env,o,target_fid, (*env)->GetShortField(env, (jobject) obj, fid));
170 return (java_lang_Object *) o;
173 c = class_java_lang_Boolean;
175 target_fid = (*env)->GetFieldID(env, c, "value", "Z");
180 SetBooleanField(env,o,target_fid, (*env)->GetStaticBooleanField(env, c, fid));
182 SetBooleanField(env,o,target_fid, (*env)->GetBooleanField(env, (jobject) obj, fid));
184 return (java_lang_Object *) o;
190 return (java_lang_Object*) (*env)->GetStaticObjectField(env, c, fid);
193 return (java_lang_Object*) (*env)->GetObjectField(env, (jobject) obj, fid);
196 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
203 * Class: java/lang/reflect/Field
205 * Signature: (Ljava/lang/Object;)Z
207 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
211 if (this->declaringClass && obj) {
212 /* get the fieldid represented by the field-object */
213 fid = class_findfield_approx((classinfo *) this->declaringClass,
214 javastring_toutf(this->name, false));
217 /* call the JNI-function to retrieve the field */
218 return (*env)->GetBooleanField(env, (jobject) obj, fid);
221 /* raise exception */
222 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
229 * Class: java/lang/reflect/Field
231 * Signature: (Ljava/lang/Object;)B
233 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
239 /* check if the specified slot could be a valid field of this class*/
240 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
241 "declaring class: fieldscount mismatch");
243 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
245 /* check if the field really has the same name and check if the type descriptor is not empty*/
246 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
247 "declaring class: field name mismatch");
248 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
250 /* check if obj would be needed (not static field), but is 0)*/
251 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
252 *exceptionptr = new_exception(string_java_lang_NullPointerException);
256 /* if (!(fid->flags & ACC_PUBLIC)) {
257 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
262 if (fid->flags & ACC_STATIC) {
263 /* initialize class if needed*/
264 class_init((classinfo*)this->declaringClass);
265 if (*exceptionptr) return 0;
267 utf_ptr = fid->descriptor->text;
269 case 'B': return fid->value.i;
271 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
275 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
276 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
279 utf_ptr = fid->descriptor->text;
281 case 'B':return getField(obj,jbyte,fid);
283 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
291 * Class: java/lang/reflect/Field
293 * Signature: (Ljava/lang/Object;)C
295 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
301 /* check if the specified slot could be a valid field of this class*/
302 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
303 "declaring class: fieldscount mismatch");
305 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
307 /* check if the field really has the same name and check if the type descriptor is not empty*/
308 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
309 "declaring class: field name mismatch");
310 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
312 /* check if obj would be needed (not static field), but is 0)*/
313 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
314 *exceptionptr = new_exception(string_java_lang_NullPointerException);
318 /*if (!(fid->flags & ACC_PUBLIC)) {
319 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
324 if (fid->flags & ACC_STATIC) {
325 /* initialize class if needed*/
326 class_init((classinfo*)this->declaringClass);
327 if (*exceptionptr) return 0;
329 utf_ptr = fid->descriptor->text;
331 case 'C': return fid->value.i;
333 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
337 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
338 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
341 utf_ptr = fid->descriptor->text;
343 case 'C':return getField(obj,jchar,fid);
345 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
353 * Class: java/lang/reflect/Field
355 * Signature: (Ljava/lang/Object;)D
357 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
363 /* check if the specified slot could be a valid field of this class*/
364 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
365 "declaring class: fieldscount mismatch");
367 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
369 /* check if the field really has the same name and check if the type descriptor is not empty*/
370 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
371 "declaring class: field name mismatch");
372 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
374 /* check if obj would be needed (not static field), but is 0)*/
375 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
376 *exceptionptr = new_exception(string_java_lang_NullPointerException);
380 /*if (!(fid->flags & ACC_PUBLIC)) {
381 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
386 if (fid->flags & ACC_STATIC) {
387 /* initialize class if needed*/
388 class_init((classinfo*)this->declaringClass);
389 if (*exceptionptr) return 0;
391 utf_ptr = fid->descriptor->text;
396 case 'I': return fid->value.i;
397 case 'F': return fid->value.f;
398 case 'D': return fid->value.d;
400 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
404 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
405 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
408 utf_ptr = fid->descriptor->text;
410 case 'B':return getField(obj,jbyte,fid);
411 case 'S':return getField(obj,jshort,fid);
412 case 'C':return getField(obj,jchar,fid);
413 case 'I':return getField(obj,jint,fid);
414 case 'D':return getField(obj,jdouble,fid);
416 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
424 * Class: java/lang/reflect/Field
426 * Signature: (Ljava/lang/Object;)F
428 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
434 /* check if the specified slot could be a valid field of this class*/
435 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
436 "declaring class: fieldscount mismatch");
438 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
440 /* check if the field really has the same name and check if the type descriptor is not empty*/
441 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
442 "declaring class: field name mismatch");
443 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
445 /* check if obj would be needed (not static field), but is 0)*/
446 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
447 *exceptionptr = new_exception(string_java_lang_NullPointerException);
451 /*if (!(fid->flags & ACC_PUBLIC)) {
452 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
457 if (fid->flags & ACC_STATIC) {
458 /* initialize class if needed*/
459 class_init((classinfo*)this->declaringClass);
460 if (*exceptionptr) return 0;
462 utf_ptr = fid->descriptor->text;
467 case 'I': return fid->value.i;
468 case 'F': return fid->value.f;
470 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
474 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
475 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
478 utf_ptr = fid->descriptor->text;
480 case 'B':return getField(obj,jbyte,fid);
481 case 'S':return getField(obj,jshort,fid);
482 case 'C':return getField(obj,jchar,fid);
483 case 'I':return getField(obj,jint,fid);
484 case 'F':return getField(obj,jfloat,fid);
486 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
494 * Class: java/lang/reflect/Field
496 * Signature: (Ljava/lang/Object;)I
498 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
504 /* check if the specified slot could be a valid field of this class*/
505 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
506 "declaring class: fieldscount mismatch");
508 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
510 /* check if the field really has the same name and check if the type descriptor is not empty*/
511 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
512 "declaring class: field name mismatch");
513 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
515 /* check if obj would be needed (not static field), but is 0)*/
516 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
517 *exceptionptr = new_exception(string_java_lang_NullPointerException);
521 /*if (!(fid->flags & ACC_PUBLIC)) {
522 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
527 if (fid->flags & ACC_STATIC) {
528 /* initialize class if needed*/
529 class_init((classinfo*)this->declaringClass);
530 if (*exceptionptr) return 0;
532 utf_ptr = fid->descriptor->text;
537 case 'I': return fid->value.i;
539 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
543 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
544 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
547 utf_ptr = fid->descriptor->text;
549 case 'B':return getField(obj,jbyte,fid);
550 case 'S':return getField(obj,jshort,fid);
551 case 'C':return getField(obj,jchar,fid);
552 case 'I':return getField(obj,jint,fid);
554 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
562 * Class: java/lang/reflect/Field
564 * Signature: (Ljava/lang/Object;)J
566 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
572 /* check if the specified slot could be a valid field of this class*/
573 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
574 "declaring class: fieldscount mismatch");
576 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
578 /* check if the field really has the same name and check if the type descriptor is not empty*/
579 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
580 "declaring class: field name mismatch");
581 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
583 /* check if obj would be needed (not static field), but is 0)*/
584 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
585 *exceptionptr = new_exception(string_java_lang_NullPointerException);
589 /*if (!(fid->flags & ACC_PUBLIC)) {
590 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
595 if (fid->flags & ACC_STATIC) {
596 /* initialize class if needed*/
597 class_init((classinfo*)this->declaringClass);
598 if (*exceptionptr) return 0;
600 utf_ptr = fid->descriptor->text;
605 case 'I': return fid->value.i;
606 case 'J': return fid->value.l;
608 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
612 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
613 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
616 utf_ptr = fid->descriptor->text;
618 case 'B':return getField(obj,jbyte,fid);
619 case 'S':return getField(obj,jshort,fid);
620 case 'C':return getField(obj,jchar,fid);
621 case 'I':return getField(obj,jint,fid);
622 case 'J':return getField(obj,jlong,fid);
624 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
632 * Class: java/lang/reflect/Field
634 * Signature: (Ljava/lang/Object;)S
636 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
642 /* check if the specified slot could be a valid field of this class*/
643 if (this->slot>((classinfo*)this->declaringClass)->fieldscount) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
644 "declaring class: fieldscount mismatch");
646 fid=&((classinfo*)this->declaringClass)->fields[this->slot]; /*get field*/
648 /* check if the field really has the same name and check if the type descriptor is not empty*/
649 if (fid->name!=javastring_toutf(this->name,false)) throw_cacao_exception_exit(string_java_lang_IncompatibleClassChangeError,
650 "declaring class: field name mismatch");
651 if (fid->descriptor->blength<1) panic("Type-Descriptor is empty");
653 /* check if obj would be needed (not static field), but is 0)*/
654 if ((!(fid->flags & ACC_STATIC)) && (obj==0)) {
655 *exceptionptr = new_exception(string_java_lang_NullPointerException);
659 /*if (!(fid->flags & ACC_PUBLIC)) {
660 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
665 if (fid->flags & ACC_STATIC) {
666 /* initialize class if needed*/
667 class_init((classinfo*)this->declaringClass);
668 if (*exceptionptr) return 0;
670 utf_ptr = fid->descriptor->text;
673 case 'S': return fid->value.i;
675 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
679 if (!builtin_instanceof((java_objectheader*)obj,(classinfo*)this->declaringClass)) {
680 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
683 utf_ptr = fid->descriptor->text;
685 case 'B':return getField(obj,jbyte,fid);
686 case 'S':return getField(obj,jshort,fid);
688 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
696 * Class: java/lang/reflect/Field
698 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
700 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, java_lang_Object *val)
702 jfieldID source_fid; /* the field containing the value to be written */
703 jfieldID fid; /* the field to be written */
705 int st = (this->flag & ACC_STATIC); /* true if the field is static */
707 fid = class_findfield_approx((classinfo *) this->declaringClass,
708 javastring_toutf(this->name, false));
710 if (val && (st || obj)) {
712 c = val->header.vftbl->class;
714 /* The fieldid is used to set the new value, for primitive types the value
715 has to be retrieved from the wrapping object */
716 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
718 /* illegal argument specified */
719 if (c != class_java_lang_Integer)
721 /* determine the field to read the value */
722 source_fid = (*env)->GetFieldID(env, c, "value", "I");
726 /* set the new value */
729 (*env)->SetStaticIntField(env, c, fid, GetIntField(env, (jobject) val, source_fid));
732 (*env)->SetIntField(env, (jobject) obj, fid, GetIntField(env, (jobject) val, source_fid));
737 if (c != class_java_lang_Long)
739 source_fid = (*env)->GetFieldID(env, c, "value", "J");
744 (*env)->SetStaticLongField(env, c, fid, GetLongField(env, (jobject) val, source_fid));
746 (*env)->SetLongField(env, (jobject) obj, fid, GetLongField(env, (jobject) val, source_fid));
751 if (c != class_java_lang_Float)
753 source_fid = (*env)->GetFieldID(env, c, "value", "F");
758 (*env)->SetStaticFloatField(env, c, fid, GetFloatField(env, (jobject) val, source_fid));
760 (*env)->SetFloatField(env, (jobject) obj, fid, GetFloatField(env, (jobject) val, source_fid));
765 if (c != class_java_lang_Double)
767 source_fid = (*env)->GetFieldID(env, c, "value", "D");
768 if (!source_fid) break;
771 (*env)->SetStaticDoubleField(env, c, fid, GetDoubleField(env,(jobject) val,source_fid));
773 (*env)->SetDoubleField(env, (jobject) obj, fid, GetDoubleField(env,(jobject) val,source_fid));
778 if (c != class_java_lang_Byte)
780 source_fid = (*env)->GetFieldID(env, c, "value", "B");
785 (*env)->SetStaticByteField(env, c, fid, GetByteField(env, (jobject) val, source_fid));
787 (*env)->SetByteField(env, (jobject) obj, fid, GetByteField(env, (jobject) val, source_fid));
792 if (c != class_java_lang_Character)
794 source_fid = (*env)->GetFieldID(env, c, "value", "C");
799 (*env)->SetStaticCharField(env, c, fid, GetCharField(env, (jobject) val, source_fid));
801 (*env)->SetCharField(env, (jobject) obj, fid, GetCharField(env, (jobject) val, source_fid));
806 if (c != class_java_lang_Short)
808 source_fid = (*env)->GetFieldID(env, c, "value", "S");
813 (*env)->SetStaticShortField(env, c, fid, GetShortField(env, (jobject) val, source_fid));
815 (*env)->SetShortField(env, (jobject) obj, fid, GetShortField(env, (jobject) val, source_fid));
820 if (c != class_java_lang_Boolean)
822 source_fid = (*env)->GetFieldID(env, c, "value", "Z");
827 (*env)->SetStaticBooleanField(env, c, fid, GetBooleanField(env, (jobject) val, source_fid));
829 (*env)->SetBooleanField(env, (jobject) obj, fid, GetBooleanField(env, (jobject) val, source_fid));
836 (*env)->SetStaticObjectField(env, c, fid, (jobject) val);
838 (*env)->SetObjectField(env, (jobject) obj, fid, (jobject) val);
844 /* raise exception */
845 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
850 * Class: java/lang/reflect/Field
852 * Signature: (Ljava/lang/Object;Z)V
854 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
858 if (this->declaringClass && obj) {
859 fid = class_findfield_approx((classinfo *) this->declaringClass,
860 javastring_toutf(this->name, false));
863 (*env)->SetBooleanField(env, (jobject) obj, fid, val);
868 /* raise exception */
869 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
874 * Class: java/lang/reflect/Field
876 * Signature: (Ljava/lang/Object;B)V
878 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
882 if (this->declaringClass && obj) {
883 fid = class_findfield_approx((classinfo *) this->declaringClass,
884 javastring_toutf(this->name, false));
887 (*env)->SetByteField(env, (jobject) obj, fid, val);
892 /* raise exception */
893 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
898 * Class: java/lang/reflect/Field
900 * Signature: (Ljava/lang/Object;C)V
902 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
906 if (this->declaringClass && obj) {
907 fid = class_findfield_approx((classinfo *) this->declaringClass,
908 javastring_toutf(this->name, false));
911 (*env)->SetCharField(env, (jobject) obj, fid, val);
916 /* raise exception */
917 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
922 * Class: java/lang/reflect/Field
924 * Signature: (Ljava/lang/Object;D)V
926 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, double val)
930 if (this->declaringClass && obj) {
931 fid = class_findfield_approx((classinfo *) this->declaringClass,
932 javastring_toutf(this->name, false));
935 (*env)->SetDoubleField(env, (jobject) obj, fid, val);
940 /* raise exception */
941 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
946 * Class: java/lang/reflect/Field
948 * Signature: (Ljava/lang/Object;F)V
950 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, float val)
954 if (this->declaringClass && obj) {
955 fid = class_findfield_approx((classinfo *) this->declaringClass,
956 javastring_toutf(this->name, false));
959 (*env)->SetFloatField(env, (jobject) obj, fid, val);
964 /* raise exception */
965 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
970 * Class: java/lang/reflect/Field
972 * Signature: (Ljava/lang/Object;I)V
974 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
978 if (this->declaringClass && obj) {
979 fid = class_findfield_approx((classinfo *) this->declaringClass,
980 javastring_toutf(this->name, false));
983 (*env)->SetIntField(env, (jobject) obj, fid, val);
988 /* raise exception */
989 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
994 * Class: java/lang/reflect/Field
996 * Signature: (Ljava/lang/Object;J)V
998 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s8 val)
1002 if (this->declaringClass && obj) {
1003 fid = class_findfield_approx((classinfo *) this->declaringClass,
1004 javastring_toutf(this->name, false));
1007 (*env)->SetLongField(env, (jobject) obj, fid, val);
1012 /* raise exception */
1013 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1018 * Class: java/lang/reflect/Field
1020 * Signature: (Ljava/lang/Object;S)V
1022 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
1026 if (this->declaringClass && obj) {
1027 fid = class_findfield_approx((classinfo *) this->declaringClass,
1028 javastring_toutf(this->name, false));
1031 (*env)->SetShortField(env, (jobject) obj, fid, val);
1036 /* raise exception */
1037 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1042 * Class: java_lang_reflect_Field
1044 * Signature: ()Ljava/lang/Class;
1046 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
1048 utf *desc = (((classinfo *) this->declaringClass)->fields[this->slot]).descriptor;
1049 java_lang_Class *ret;
1053 ret=(java_lang_Class *) class_from_descriptor(desc->text, utf_end(desc), NULL, CLASSLOAD_LOAD);
1054 use_class_as_object(ret);
1060 * Class: java_lang_reflect_Field
1061 * Method: getModifiers
1064 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiers(JNIEnv *env, java_lang_reflect_Field *this)
1066 return (((classinfo *) this->declaringClass)->fields[this->slot]).flags;
1071 * These are local overrides for various environment variables in Emacs.
1072 * Please do not remove this and leave it at the end of the file, where
1073 * Emacs will automagically detect them.
1074 * ---------------------------------------------------------------------
1077 * indent-tabs-mode: t