1 /* src/native/vm/gnu/java_lang_reflect_Field.c
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
33 #include "native/jni.h"
34 #include "native/llni.h"
35 #include "native/native.h"
37 #include "native/include/java_lang_Boolean.h"
38 #include "native/include/java_lang_Byte.h"
39 #include "native/include/java_lang_Character.h"
40 #include "native/include/java_lang_Short.h"
41 #include "native/include/java_lang_Integer.h"
42 #include "native/include/java_lang_Long.h"
43 #include "native/include/java_lang_Float.h"
44 #include "native/include/java_lang_Double.h"
45 #include "native/include/java_lang_Object.h"
46 #include "native/include/java_lang_Class.h"
47 #include "native/include/java_lang_String.h"
49 #include "native/include/java_lang_reflect_Field.h"
51 #if defined(ENABLE_ANNOTATIONS)
52 #include "native/include/java_util_Map.h"
53 #include "native/include/sun_reflect_ConstantPool.h"
54 #include "native/vm/reflect.h"
57 #include "vm/access.h"
58 #include "vm/builtin.h"
59 #include "vm/exceptions.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/primitive.h"
63 #include "vm/resolve.h"
64 #include "vm/stringlocal.h"
66 #include "vm/jit/stacktrace.h"
68 #include "vmcore/loader.h"
69 #include "vmcore/utf8.h"
72 /* native methods implemented by this file ************************************/
74 static JNINativeMethod methods[] = {
75 { "getModifiersInternal", "()I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getModifiersInternal },
76 { "getType", "()Ljava/lang/Class;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getType },
77 { "get", "(Ljava/lang/Object;)Ljava/lang/Object;", (void *) (intptr_t) &Java_java_lang_reflect_Field_get },
78 { "getBoolean", "(Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_java_lang_reflect_Field_getBoolean },
79 { "getByte", "(Ljava/lang/Object;)B", (void *) (intptr_t) &Java_java_lang_reflect_Field_getByte },
80 { "getChar", "(Ljava/lang/Object;)C", (void *) (intptr_t) &Java_java_lang_reflect_Field_getChar },
81 { "getShort", "(Ljava/lang/Object;)S", (void *) (intptr_t) &Java_java_lang_reflect_Field_getShort },
82 { "getInt", "(Ljava/lang/Object;)I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getInt },
83 { "getLong", "(Ljava/lang/Object;)J", (void *) (intptr_t) &Java_java_lang_reflect_Field_getLong },
84 { "getFloat", "(Ljava/lang/Object;)F", (void *) (intptr_t) &Java_java_lang_reflect_Field_getFloat },
85 { "getDouble", "(Ljava/lang/Object;)D", (void *) (intptr_t) &Java_java_lang_reflect_Field_getDouble },
86 { "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_set },
87 { "setBoolean", "(Ljava/lang/Object;Z)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setBoolean },
88 { "setByte", "(Ljava/lang/Object;B)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setByte },
89 { "setChar", "(Ljava/lang/Object;C)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setChar },
90 { "setShort", "(Ljava/lang/Object;S)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setShort },
91 { "setInt", "(Ljava/lang/Object;I)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setInt },
92 { "setLong", "(Ljava/lang/Object;J)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setLong },
93 { "setFloat", "(Ljava/lang/Object;F)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setFloat },
94 { "setDouble", "(Ljava/lang/Object;D)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setDouble },
95 { "getSignature", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getSignature },
96 #if defined(ENABLE_ANNOTATIONS)
97 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (intptr_t) &Java_java_lang_reflect_Field_declaredAnnotations },
102 /* _Jv_java_lang_reflect_Field_init ********************************************
104 Register native functions.
106 *******************************************************************************/
108 void _Jv_java_lang_reflect_Field_init(void)
112 u = utf_new_char("java/lang/reflect/Field");
114 native_method_register(u, methods, NATIVE_METHODS_COUNT);
118 /* _field_access_check *********************************************************
120 Checks if the field can be accessed.
123 true......field can be accessed, or
124 false.....otherwise (maybe an Exception was thrown).
126 *******************************************************************************/
128 static bool _field_access_check(java_lang_reflect_Field *this,
129 fieldinfo *f, classinfo *c, java_handle_t *o)
133 /* check if we should bypass security checks (AccessibleObject) */
135 LLNI_field_get_val(this, flag, flag);
137 /* this function is always called like this:
138 java.lang.reflect.Field.xxx (Native Method)
141 if (!access_check_field(f, 0))
145 /* some general checks */
147 if (f->flags & ACC_STATIC) {
148 /* initialize class if required */
150 if (!(c->state & CLASS_INITIALIZED))
151 if (!initialize_class(c))
154 /* everything is ok */
159 /* obj is required for not-static fields */
162 exceptions_throw_nullpointerexception();
166 if (builtin_instanceof(o, c))
172 exceptions_throw_illegalargumentexception();
177 /* _field_get_type *************************************************************
179 Returns the content of the given field.
181 *******************************************************************************/
183 #define _FIELD_GET_TYPE(name, type, uniontype) \
184 static inline type _field_get_##name(fieldinfo *f, java_lang_Object *o) \
187 if (f->flags & ACC_STATIC) { \
188 ret = f->value->uniontype; \
190 LLNI_CRITICAL_START; \
191 ret = *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset); \
197 static inline java_handle_t *_field_get_handle(fieldinfo *f, java_lang_Object *o)
204 if (f->flags & ACC_STATIC) {
207 obj = *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset);
210 hdl = LLNI_WRAP(obj);
217 _FIELD_GET_TYPE(int, int32_t, i)
218 _FIELD_GET_TYPE(long, int64_t, l)
219 _FIELD_GET_TYPE(float, float, f)
220 _FIELD_GET_TYPE(double, double, d)
223 /* _field_set_type *************************************************************
225 Sets the content of the given field to the given value.
227 *******************************************************************************/
229 #define _FIELD_SET_TYPE(name, type, uniontype) \
230 static inline void _field_set_##name(fieldinfo *f, java_lang_Object *o, type value) \
232 if (f->flags & ACC_STATIC) { \
233 f->value->uniontype = value; \
235 LLNI_CRITICAL_START; \
236 *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = value; \
241 static inline void _field_set_handle(fieldinfo *f, java_lang_Object *o, java_handle_t *value)
245 if (f->flags & ACC_STATIC) {
246 f->value->a = LLNI_DIRECT(value);
248 *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = LLNI_DIRECT(value);
254 _FIELD_SET_TYPE(int, int32_t, i)
255 _FIELD_SET_TYPE(long, int64_t, l)
256 _FIELD_SET_TYPE(float, float, f)
257 _FIELD_SET_TYPE(double, double, d)
261 * Class: java/lang/reflect/Field
262 * Method: getModifiersInternal
265 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
271 LLNI_field_get_cls(this, clazz, c);
272 LLNI_field_get_val(this, slot , slot);
273 f = &(c->fields[slot]);
280 * Class: java/lang/reflect/Field
282 * Signature: ()Ljava/lang/Class;
284 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
291 LLNI_field_get_cls(this, clazz, c);
292 LLNI_field_get_val(this, slot , slot);
293 desc = c->fields[slot].parseddesc;
298 if (!resolve_class_from_typedesc(desc, true, false, &ret))
301 return LLNI_classinfo_wrap(ret);
306 * Class: java/lang/reflect/Field
308 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
310 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
316 java_handle_t *object;
318 LLNI_field_get_cls(this, clazz, c);
319 LLNI_field_get_val(this, slot , slot);
320 f = &c->fields[slot];
322 /* check if the field can be accessed */
324 if (!_field_access_check(this, f, c, (java_handle_t *) o))
327 switch (f->parseddesc->decltype) {
328 case PRIMITIVETYPE_BOOLEAN:
329 case PRIMITIVETYPE_BYTE:
330 case PRIMITIVETYPE_CHAR:
331 case PRIMITIVETYPE_SHORT:
332 case PRIMITIVETYPE_INT:
333 value.i = _field_get_int(f, o);
336 case PRIMITIVETYPE_LONG:
337 value.l = _field_get_long(f, o);
340 case PRIMITIVETYPE_FLOAT:
341 value.f = _field_get_float(f, o);
344 case PRIMITIVETYPE_DOUBLE:
345 value.d = _field_get_double(f, o);
349 return (java_lang_Object *) _field_get_handle(f, o);
352 /* Now box the primitive types. */
354 object = primitive_box(f->parseddesc->decltype, value);
356 return (java_lang_Object *) object;
361 * Class: java/lang/reflect/Field
363 * Signature: (Ljava/lang/Object;)Z
365 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
371 /* get the class and the field */
373 LLNI_field_get_cls(this, clazz, c);
374 LLNI_field_get_val(this, slot , slot);
375 f = &c->fields[slot];
377 /* check if the field can be accessed */
379 if (!_field_access_check(this, f, c, (java_handle_t *) o))
382 /* check the field type and return the value */
384 switch (f->parseddesc->decltype) {
385 case PRIMITIVETYPE_BOOLEAN:
386 return (int32_t) _field_get_int(f, o);
388 exceptions_throw_illegalargumentexception();
395 * Class: java/lang/reflect/Field
397 * Signature: (Ljava/lang/Object;)B
399 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
405 /* get the class and the field */
407 LLNI_field_get_cls(this, clazz, c);
408 LLNI_field_get_val(this, slot , slot);
409 f = &c->fields[slot];
411 /* check if the field can be accessed */
413 if (!_field_access_check(this, f, c, (java_handle_t *) o))
416 /* check the field type and return the value */
418 switch (f->parseddesc->decltype) {
419 case PRIMITIVETYPE_BYTE:
420 return (int32_t) _field_get_int(f, o);
422 exceptions_throw_illegalargumentexception();
429 * Class: java/lang/reflect/Field
431 * Signature: (Ljava/lang/Object;)C
433 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
439 /* get the class and the field */
441 LLNI_field_get_cls(this, clazz, c);
442 LLNI_field_get_val(this, slot , slot);
443 f = &c->fields[slot];
445 /* check if the field can be accessed */
447 if (!_field_access_check(this, f, c, (java_handle_t *) o))
450 /* check the field type and return the value */
452 switch (f->parseddesc->decltype) {
453 case PRIMITIVETYPE_CHAR:
454 return (int32_t) _field_get_int(f, o);
456 exceptions_throw_illegalargumentexception();
463 * Class: java/lang/reflect/Field
465 * Signature: (Ljava/lang/Object;)S
467 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
473 /* get the class and the field */
475 LLNI_field_get_cls(this, clazz, c);
476 LLNI_field_get_val(this, slot , slot);
477 f = &c->fields[slot];
479 /* check if the field can be accessed */
481 if (!_field_access_check(this, f, c, (java_handle_t *) o))
484 /* check the field type and return the value */
486 switch (f->parseddesc->decltype) {
487 case PRIMITIVETYPE_BYTE:
488 case PRIMITIVETYPE_SHORT:
489 return (int32_t) _field_get_int(f, o);
491 exceptions_throw_illegalargumentexception();
498 * Class: java/lang/reflect/Field
500 * Signature: (Ljava/lang/Object;)I
502 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
508 /* get the class and the field */
510 LLNI_field_get_cls(this, clazz, c);
511 LLNI_field_get_val(this, slot , slot);
512 f = &c->fields[slot];
514 /* check if the field can be accessed */
516 if (!_field_access_check(this, f, c, (java_handle_t *) o))
519 /* check the field type and return the value */
521 switch (f->parseddesc->decltype) {
522 case PRIMITIVETYPE_BYTE:
523 case PRIMITIVETYPE_CHAR:
524 case PRIMITIVETYPE_SHORT:
525 case PRIMITIVETYPE_INT:
526 return (int32_t) _field_get_int(f, o);
528 exceptions_throw_illegalargumentexception();
535 * Class: java/lang/reflect/Field
537 * Signature: (Ljava/lang/Object;)J
539 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
545 /* get the class and the field */
547 LLNI_field_get_cls(this, clazz, c);
548 LLNI_field_get_val(this, slot , slot);
549 f = &c->fields[slot];
551 /* check if the field can be accessed */
553 if (!_field_access_check(this, f, c, (java_handle_t *) o))
556 /* check the field type and return the value */
558 switch (f->parseddesc->decltype) {
559 case PRIMITIVETYPE_BYTE:
560 case PRIMITIVETYPE_CHAR:
561 case PRIMITIVETYPE_SHORT:
562 case PRIMITIVETYPE_INT:
563 return (int64_t) _field_get_int(f, o);
564 case PRIMITIVETYPE_LONG:
565 return (int64_t) _field_get_long(f, o);
567 exceptions_throw_illegalargumentexception();
574 * Class: java/lang/reflect/Field
576 * Signature: (Ljava/lang/Object;)F
578 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
584 /* get the class and the field */
586 LLNI_field_get_cls(this, clazz, c);
587 LLNI_field_get_val(this, slot , slot);
588 f = &c->fields[slot];
590 /* check if the field can be accessed */
592 if (!_field_access_check(this, f, c, (java_handle_t *) o))
595 /* check the field type and return the value */
597 switch (f->parseddesc->decltype) {
598 case PRIMITIVETYPE_BYTE:
599 case PRIMITIVETYPE_CHAR:
600 case PRIMITIVETYPE_SHORT:
601 case PRIMITIVETYPE_INT:
602 return (float) _field_get_int(f, o);
603 case PRIMITIVETYPE_LONG:
604 return (float) _field_get_long(f, o);
605 case PRIMITIVETYPE_FLOAT:
606 return (float) _field_get_float(f, o);
608 exceptions_throw_illegalargumentexception();
615 * Class: java/lang/reflect/Field
617 * Signature: (Ljava/lang/Object;)D
619 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
625 /* get the class and the field */
627 LLNI_field_get_cls(this, clazz, c);
628 LLNI_field_get_val(this, slot , slot);
629 f = &c->fields[slot];
631 /* check if the field can be accessed */
633 if (!_field_access_check(this, f, c, (java_handle_t *) o))
636 /* check the field type and return the value */
638 switch (f->parseddesc->decltype) {
639 case PRIMITIVETYPE_BYTE:
640 case PRIMITIVETYPE_CHAR:
641 case PRIMITIVETYPE_SHORT:
642 case PRIMITIVETYPE_INT:
643 return (double) _field_get_int(f, o);
644 case PRIMITIVETYPE_LONG:
645 return (double) _field_get_long(f, o);
646 case PRIMITIVETYPE_FLOAT:
647 return (double) _field_get_float(f, o);
648 case PRIMITIVETYPE_DOUBLE:
649 return (double) _field_get_double(f, o);
651 exceptions_throw_illegalargumentexception();
658 * Class: java/lang/reflect/Field
660 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
662 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
670 /* get the class and the field */
672 LLNI_field_get_cls(this, clazz, dc);
673 LLNI_field_get_val(this, slot , slot);
674 df = &dc->fields[slot];
676 /* check if the field can be accessed */
678 if (!_field_access_check(this, df, dc, (java_handle_t *) o))
681 /* get the source classinfo from the object */
686 LLNI_class_get(value, sc);
688 /* The fieldid is used to set the new value, for primitive
689 types the value has to be retrieved from the wrapping
692 switch (df->parseddesc->decltype) {
693 case PRIMITIVETYPE_BOOLEAN: {
696 /* determine the field to read the value */
698 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
701 switch (sf->parseddesc->decltype) {
702 case PRIMITIVETYPE_BOOLEAN:
703 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
706 exceptions_throw_illegalargumentexception();
710 _field_set_int(df, o, val);
714 case PRIMITIVETYPE_BYTE: {
717 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
720 switch (sf->parseddesc->decltype) {
721 case PRIMITIVETYPE_BYTE:
722 LLNI_field_get_val((java_lang_Byte *) value, value, val);
725 exceptions_throw_illegalargumentexception();
729 _field_set_int(df, o, val);
733 case PRIMITIVETYPE_CHAR: {
736 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
739 switch (sf->parseddesc->decltype) {
740 case PRIMITIVETYPE_CHAR:
741 LLNI_field_get_val((java_lang_Character *) value, value, val);
744 exceptions_throw_illegalargumentexception();
748 _field_set_int(df, o, val);
752 case PRIMITIVETYPE_SHORT: {
755 /* get field only by name, it can be one of B, S */
757 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
760 switch (sf->parseddesc->decltype) {
761 case PRIMITIVETYPE_BYTE:
762 LLNI_field_get_val((java_lang_Byte *) value, value, val);
764 case PRIMITIVETYPE_SHORT:
765 LLNI_field_get_val((java_lang_Short *) value, value, val);
768 exceptions_throw_illegalargumentexception();
772 _field_set_int(df, o, val);
776 case PRIMITIVETYPE_INT: {
779 /* get field only by name, it can be one of B, S, C, I */
781 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
784 switch (sf->parseddesc->decltype) {
785 case PRIMITIVETYPE_BYTE:
786 LLNI_field_get_val((java_lang_Byte *) value, value, val);
788 case PRIMITIVETYPE_CHAR:
789 LLNI_field_get_val((java_lang_Character *) value, value, val);
791 case PRIMITIVETYPE_SHORT:
792 LLNI_field_get_val((java_lang_Short *) value, value, val);
794 case PRIMITIVETYPE_INT:
795 LLNI_field_get_val((java_lang_Integer *) value, value, val);
798 exceptions_throw_illegalargumentexception();
802 _field_set_int(df, o, val);
806 case PRIMITIVETYPE_LONG: {
809 /* get field only by name, it can be one of B, S, C, I, J */
811 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
814 switch (sf->parseddesc->decltype) {
815 case PRIMITIVETYPE_BYTE:
816 LLNI_field_get_val((java_lang_Byte *) value, value, val);
818 case PRIMITIVETYPE_CHAR:
819 LLNI_field_get_val((java_lang_Character *) value, value, val);
821 case PRIMITIVETYPE_SHORT:
822 LLNI_field_get_val((java_lang_Short *) value, value, val);
824 case PRIMITIVETYPE_INT:
825 LLNI_field_get_val((java_lang_Integer *) value, value, val);
827 case PRIMITIVETYPE_LONG:
828 LLNI_field_get_val((java_lang_Long *) value, value, val);
831 exceptions_throw_illegalargumentexception();
835 _field_set_long(df, o, val);
839 case PRIMITIVETYPE_FLOAT: {
842 /* get field only by name, it can be one of B, S, C, I, J, F */
844 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
847 switch (sf->parseddesc->decltype) {
848 case PRIMITIVETYPE_BYTE:
849 LLNI_field_get_val((java_lang_Byte *) value, value, val);
851 case PRIMITIVETYPE_CHAR:
852 LLNI_field_get_val((java_lang_Character *) value, value, val);
854 case PRIMITIVETYPE_SHORT:
855 LLNI_field_get_val((java_lang_Short *) value, value, val);
857 case PRIMITIVETYPE_INT:
858 LLNI_field_get_val((java_lang_Integer *) value, value, val);
860 case PRIMITIVETYPE_LONG:
861 LLNI_field_get_val((java_lang_Long *) value, value, val);
863 case PRIMITIVETYPE_FLOAT:
864 LLNI_field_get_val((java_lang_Float *) value, value, val);
867 exceptions_throw_illegalargumentexception();
871 _field_set_float(df, o, val);
875 case PRIMITIVETYPE_DOUBLE: {
878 /* get field only by name, it can be one of B, S, C, I, J, F, D */
880 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
883 switch (sf->parseddesc->decltype) {
884 case PRIMITIVETYPE_BYTE:
885 LLNI_field_get_val((java_lang_Byte *) value, value, val);
887 case PRIMITIVETYPE_CHAR:
888 LLNI_field_get_val((java_lang_Character *) value, value, val);
890 case PRIMITIVETYPE_SHORT:
891 LLNI_field_get_val((java_lang_Short *) value, value, val);
893 case PRIMITIVETYPE_INT:
894 LLNI_field_get_val((java_lang_Integer *) value, value, val);
896 case PRIMITIVETYPE_LONG:
897 LLNI_field_get_val((java_lang_Long *) value, value, val);
899 case PRIMITIVETYPE_FLOAT:
900 LLNI_field_get_val((java_lang_Float *) value, value, val);
902 case PRIMITIVETYPE_DOUBLE:
903 LLNI_field_get_val((java_lang_Double *) value, value, val);
906 exceptions_throw_illegalargumentexception();
910 _field_set_double(df, o, val);
915 /* check if value is an instance of the destination class */
918 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
921 _field_set_handle(df, o, (java_handle_t *) value);
925 /* raise exception */
927 exceptions_throw_illegalargumentexception();
932 * Class: java/lang/reflect/Field
934 * Signature: (Ljava/lang/Object;Z)V
936 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
942 /* get the class and the field */
944 LLNI_field_get_cls(this, clazz, c);
945 LLNI_field_get_val(this, slot , slot);
946 f = &c->fields[slot];
948 /* check if the field can be accessed */
950 if (!_field_access_check(this, f, c, (java_handle_t *) o))
953 /* check the field type and set the value */
955 switch (f->parseddesc->decltype) {
956 case PRIMITIVETYPE_BOOLEAN:
957 _field_set_int(f, o, value);
960 exceptions_throw_illegalargumentexception();
968 * Class: java/lang/reflect/Field
970 * Signature: (Ljava/lang/Object;B)V
972 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
978 /* get the class and the field */
980 LLNI_field_get_cls(this, clazz, c);
981 LLNI_field_get_val(this, slot , slot);
982 f = &c->fields[slot];
984 /* check if the field can be accessed */
986 if (!_field_access_check(this, f, c, (java_handle_t *) o))
989 /* check the field type and set the value */
991 switch (f->parseddesc->decltype) {
992 case PRIMITIVETYPE_BYTE:
993 case PRIMITIVETYPE_SHORT:
994 case PRIMITIVETYPE_INT:
995 _field_set_int(f, o, value);
997 case PRIMITIVETYPE_LONG:
998 _field_set_long(f, o, value);
1000 case PRIMITIVETYPE_FLOAT:
1001 _field_set_float(f, o, value);
1003 case PRIMITIVETYPE_DOUBLE:
1004 _field_set_double(f, o, value);
1007 exceptions_throw_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 *o, int32_t value)
1025 /* get the class and the field */
1027 LLNI_field_get_cls(this, clazz, c);
1028 LLNI_field_get_val(this, slot , slot);
1029 f = &c->fields[slot];
1031 /* check if the field can be accessed */
1033 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1036 /* check the field type and set the value */
1038 switch (f->parseddesc->decltype) {
1039 case PRIMITIVETYPE_CHAR:
1040 case PRIMITIVETYPE_INT:
1041 _field_set_int(f, o, value);
1043 case PRIMITIVETYPE_LONG:
1044 _field_set_long(f, o, value);
1046 case PRIMITIVETYPE_FLOAT:
1047 _field_set_float(f, o, value);
1049 case PRIMITIVETYPE_DOUBLE:
1050 _field_set_double(f, o, value);
1053 exceptions_throw_illegalargumentexception();
1061 * Class: java/lang/reflect/Field
1063 * Signature: (Ljava/lang/Object;S)V
1065 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1071 /* get the class and the field */
1073 LLNI_field_get_cls(this, clazz, c);
1074 LLNI_field_get_val(this, slot , slot);
1075 f = &c->fields[slot];
1077 /* check if the field can be accessed */
1079 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1082 /* check the field type and set the value */
1084 switch (f->parseddesc->decltype) {
1085 case PRIMITIVETYPE_SHORT:
1086 case PRIMITIVETYPE_INT:
1087 _field_set_int(f, o, value);
1089 case PRIMITIVETYPE_LONG:
1090 _field_set_long(f, o, value);
1092 case PRIMITIVETYPE_FLOAT:
1093 _field_set_float(f, o, value);
1095 case PRIMITIVETYPE_DOUBLE:
1096 _field_set_double(f, o, value);
1099 exceptions_throw_illegalargumentexception();
1107 * Class: java/lang/reflect/Field
1109 * Signature: (Ljava/lang/Object;I)V
1111 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1117 /* get the class and the field */
1119 LLNI_field_get_cls(this, clazz, c);
1120 LLNI_field_get_val(this, slot , slot);
1121 f = &c->fields[slot];
1123 /* check if the field can be accessed */
1125 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1128 /* check the field type and set the value */
1130 switch (f->parseddesc->decltype) {
1131 case PRIMITIVETYPE_INT:
1132 _field_set_int(f, o, value);
1134 case PRIMITIVETYPE_LONG:
1135 _field_set_long(f, o, value);
1137 case PRIMITIVETYPE_FLOAT:
1138 _field_set_float(f, o, value);
1140 case PRIMITIVETYPE_DOUBLE:
1141 _field_set_double(f, o, value);
1144 exceptions_throw_illegalargumentexception();
1152 * Class: java/lang/reflect/Field
1154 * Signature: (Ljava/lang/Object;J)V
1156 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int64_t value)
1162 /* get the class and the field */
1164 LLNI_field_get_cls(this, clazz, c);
1165 LLNI_field_get_val(this, slot , slot);
1166 f = &c->fields[slot];
1168 /* check if the field can be accessed */
1170 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1173 /* check the field type and set the value */
1175 switch (f->parseddesc->decltype) {
1176 case PRIMITIVETYPE_LONG:
1177 _field_set_long(f, o, value);
1179 case PRIMITIVETYPE_FLOAT:
1180 _field_set_float(f, o, value);
1182 case PRIMITIVETYPE_DOUBLE:
1183 _field_set_double(f, o, value);
1186 exceptions_throw_illegalargumentexception();
1194 * Class: java/lang/reflect/Field
1196 * Signature: (Ljava/lang/Object;F)V
1198 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1204 /* get the class and the field */
1206 LLNI_field_get_cls(this, clazz, c);
1207 LLNI_field_get_val(this, slot , slot);
1208 f = &c->fields[slot];
1210 /* check if the field can be accessed */
1212 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1215 /* check the field type and set the value */
1217 switch (f->parseddesc->decltype) {
1218 case PRIMITIVETYPE_FLOAT:
1219 _field_set_float(f, o, value);
1221 case PRIMITIVETYPE_DOUBLE:
1222 _field_set_double(f, o, value);
1225 exceptions_throw_illegalargumentexception();
1233 * Class: java/lang/reflect/Field
1235 * Signature: (Ljava/lang/Object;D)V
1237 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1243 /* get the class and the field */
1245 LLNI_field_get_cls(this, clazz, c);
1246 LLNI_field_get_val(this, slot , slot);
1247 f = &c->fields[slot];
1249 /* check if the field can be accessed */
1251 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1254 /* check the field type and set the value */
1256 switch (f->parseddesc->decltype) {
1257 case PRIMITIVETYPE_DOUBLE:
1258 _field_set_double(f, o, value);
1261 exceptions_throw_illegalargumentexception();
1269 * Class: java/lang/reflect/Field
1270 * Method: getSignature
1271 * Signature: ()Ljava/lang/String;
1273 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1280 /* get the class and the field */
1282 LLNI_field_get_cls(this, clazz, c);
1283 LLNI_field_get_val(this, slot , slot);
1284 f = &c->fields[slot];
1286 if (f->signature == NULL)
1289 o = javastring_new(f->signature);
1291 /* in error case o is NULL */
1293 return (java_lang_String *) o;
1297 #if defined(ENABLE_ANNOTATIONS)
1299 * Class: java/lang/reflect/Field
1300 * Method: declaredAnnotations
1301 * Signature: ()Ljava/util/Map;
1303 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
1305 java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
1306 java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
1307 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
1308 classinfo *referer = NULL; /* class, which calles the annotation parser */
1309 /* (for the parameter 'referer' of vm_call_method()) */
1311 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
1313 /* are the annotations parsed yet? */
1314 if (declaredAnnotations == NULL) {
1315 LLNI_field_get_ref(this, annotations, annotations);
1316 LLNI_field_get_ref(this, clazz, declaringClass);
1317 LLNI_class_get(this, referer);
1319 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
1321 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
1324 return declaredAnnotations;
1330 * These are local overrides for various environment variables in Emacs.
1331 * Please do not remove this and leave it at the end of the file, where
1332 * Emacs will automagically detect them.
1333 * ---------------------------------------------------------------------
1336 * indent-tabs-mode: t
1340 * vim:noexpandtab:sw=4:ts=4: