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 [0] java.lang.reflect.Field.xxx (Native Method)
142 if (!access_check_field(f, 1))
146 /* some general checks */
148 if (f->flags & ACC_STATIC) {
149 /* initialize class if required */
151 if (!(c->state & CLASS_INITIALIZED))
152 if (!initialize_class(c))
155 /* everything is ok */
160 /* obj is required for not-static fields */
163 exceptions_throw_nullpointerexception();
167 if (builtin_instanceof(o, c))
173 exceptions_throw_illegalargumentexception();
178 /* _field_get_type *************************************************************
180 Returns the content of the given field.
182 *******************************************************************************/
184 #define _FIELD_GET_TYPE(name, type, uniontype) \
185 static inline type _field_get_##name(fieldinfo *f, java_lang_Object *o) \
188 if (f->flags & ACC_STATIC) { \
189 ret = f->value->uniontype; \
191 LLNI_CRITICAL_START; \
192 ret = *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset); \
198 static inline java_handle_t *_field_get_handle(fieldinfo *f, java_lang_Object *o)
205 if (f->flags & ACC_STATIC) {
208 obj = *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset);
211 hdl = LLNI_WRAP(obj);
218 _FIELD_GET_TYPE(int, int32_t, i)
219 _FIELD_GET_TYPE(long, int64_t, l)
220 _FIELD_GET_TYPE(float, float, f)
221 _FIELD_GET_TYPE(double, double, d)
224 /* _field_set_type *************************************************************
226 Sets the content of the given field to the given value.
228 *******************************************************************************/
230 #define _FIELD_SET_TYPE(name, type, uniontype) \
231 static inline void _field_set_##name(fieldinfo *f, java_lang_Object *o, type value) \
233 if (f->flags & ACC_STATIC) { \
234 f->value->uniontype = value; \
236 LLNI_CRITICAL_START; \
237 *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = value; \
242 static inline void _field_set_handle(fieldinfo *f, java_lang_Object *o, java_handle_t *value)
246 if (f->flags & ACC_STATIC) {
247 f->value->a = LLNI_DIRECT(value);
249 *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = LLNI_DIRECT(value);
255 _FIELD_SET_TYPE(int, int32_t, i)
256 _FIELD_SET_TYPE(long, int64_t, l)
257 _FIELD_SET_TYPE(float, float, f)
258 _FIELD_SET_TYPE(double, double, d)
262 * Class: java/lang/reflect/Field
263 * Method: getModifiersInternal
266 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
272 LLNI_field_get_cls(this, clazz, c);
273 LLNI_field_get_val(this, slot , slot);
274 f = &(c->fields[slot]);
281 * Class: java/lang/reflect/Field
283 * Signature: ()Ljava/lang/Class;
285 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
292 LLNI_field_get_cls(this, clazz, c);
293 LLNI_field_get_val(this, slot , slot);
294 desc = c->fields[slot].parseddesc;
299 if (!resolve_class_from_typedesc(desc, true, false, &ret))
302 return LLNI_classinfo_wrap(ret);
307 * Class: java/lang/reflect/Field
309 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
311 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
317 java_handle_t *object;
319 LLNI_field_get_cls(this, clazz, c);
320 LLNI_field_get_val(this, slot , slot);
321 f = &c->fields[slot];
323 /* check if the field can be accessed */
325 if (!_field_access_check(this, f, c, (java_handle_t *) o))
328 switch (f->parseddesc->decltype) {
329 case PRIMITIVETYPE_BOOLEAN:
330 case PRIMITIVETYPE_BYTE:
331 case PRIMITIVETYPE_CHAR:
332 case PRIMITIVETYPE_SHORT:
333 case PRIMITIVETYPE_INT:
334 value.i = _field_get_int(f, o);
337 case PRIMITIVETYPE_LONG:
338 value.l = _field_get_long(f, o);
341 case PRIMITIVETYPE_FLOAT:
342 value.f = _field_get_float(f, o);
345 case PRIMITIVETYPE_DOUBLE:
346 value.d = _field_get_double(f, o);
350 return (java_lang_Object *) _field_get_handle(f, o);
353 /* Now box the primitive types. */
355 object = primitive_box(f->parseddesc->decltype, value);
357 return (java_lang_Object *) object;
362 * Class: java/lang/reflect/Field
364 * Signature: (Ljava/lang/Object;)Z
366 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
372 /* get the class and the field */
374 LLNI_field_get_cls(this, clazz, c);
375 LLNI_field_get_val(this, slot , slot);
376 f = &c->fields[slot];
378 /* check if the field can be accessed */
380 if (!_field_access_check(this, f, c, (java_handle_t *) o))
383 /* check the field type and return the value */
385 switch (f->parseddesc->decltype) {
386 case PRIMITIVETYPE_BOOLEAN:
387 return (int32_t) _field_get_int(f, o);
389 exceptions_throw_illegalargumentexception();
396 * Class: java/lang/reflect/Field
398 * Signature: (Ljava/lang/Object;)B
400 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
406 /* get the class and the field */
408 LLNI_field_get_cls(this, clazz, c);
409 LLNI_field_get_val(this, slot , slot);
410 f = &c->fields[slot];
412 /* check if the field can be accessed */
414 if (!_field_access_check(this, f, c, (java_handle_t *) o))
417 /* check the field type and return the value */
419 switch (f->parseddesc->decltype) {
420 case PRIMITIVETYPE_BYTE:
421 return (int32_t) _field_get_int(f, o);
423 exceptions_throw_illegalargumentexception();
430 * Class: java/lang/reflect/Field
432 * Signature: (Ljava/lang/Object;)C
434 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
440 /* get the class and the field */
442 LLNI_field_get_cls(this, clazz, c);
443 LLNI_field_get_val(this, slot , slot);
444 f = &c->fields[slot];
446 /* check if the field can be accessed */
448 if (!_field_access_check(this, f, c, (java_handle_t *) o))
451 /* check the field type and return the value */
453 switch (f->parseddesc->decltype) {
454 case PRIMITIVETYPE_CHAR:
455 return (int32_t) _field_get_int(f, o);
457 exceptions_throw_illegalargumentexception();
464 * Class: java/lang/reflect/Field
466 * Signature: (Ljava/lang/Object;)S
468 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
474 /* get the class and the field */
476 LLNI_field_get_cls(this, clazz, c);
477 LLNI_field_get_val(this, slot , slot);
478 f = &c->fields[slot];
480 /* check if the field can be accessed */
482 if (!_field_access_check(this, f, c, (java_handle_t *) o))
485 /* check the field type and return the value */
487 switch (f->parseddesc->decltype) {
488 case PRIMITIVETYPE_BYTE:
489 case PRIMITIVETYPE_SHORT:
490 return (int32_t) _field_get_int(f, o);
492 exceptions_throw_illegalargumentexception();
499 * Class: java/lang/reflect/Field
501 * Signature: (Ljava/lang/Object;)I
503 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
509 /* get the class and the field */
511 LLNI_field_get_cls(this, clazz, c);
512 LLNI_field_get_val(this, slot , slot);
513 f = &c->fields[slot];
515 /* check if the field can be accessed */
517 if (!_field_access_check(this, f, c, (java_handle_t *) o))
520 /* check the field type and return the value */
522 switch (f->parseddesc->decltype) {
523 case PRIMITIVETYPE_BYTE:
524 case PRIMITIVETYPE_CHAR:
525 case PRIMITIVETYPE_SHORT:
526 case PRIMITIVETYPE_INT:
527 return (int32_t) _field_get_int(f, o);
529 exceptions_throw_illegalargumentexception();
536 * Class: java/lang/reflect/Field
538 * Signature: (Ljava/lang/Object;)J
540 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
546 /* get the class and the field */
548 LLNI_field_get_cls(this, clazz, c);
549 LLNI_field_get_val(this, slot , slot);
550 f = &c->fields[slot];
552 /* check if the field can be accessed */
554 if (!_field_access_check(this, f, c, (java_handle_t *) o))
557 /* check the field type and return the value */
559 switch (f->parseddesc->decltype) {
560 case PRIMITIVETYPE_BYTE:
561 case PRIMITIVETYPE_CHAR:
562 case PRIMITIVETYPE_SHORT:
563 case PRIMITIVETYPE_INT:
564 return (int64_t) _field_get_int(f, o);
565 case PRIMITIVETYPE_LONG:
566 return (int64_t) _field_get_long(f, o);
568 exceptions_throw_illegalargumentexception();
575 * Class: java/lang/reflect/Field
577 * Signature: (Ljava/lang/Object;)F
579 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
585 /* get the class and the field */
587 LLNI_field_get_cls(this, clazz, c);
588 LLNI_field_get_val(this, slot , slot);
589 f = &c->fields[slot];
591 /* check if the field can be accessed */
593 if (!_field_access_check(this, f, c, (java_handle_t *) o))
596 /* check the field type and return the value */
598 switch (f->parseddesc->decltype) {
599 case PRIMITIVETYPE_BYTE:
600 case PRIMITIVETYPE_CHAR:
601 case PRIMITIVETYPE_SHORT:
602 case PRIMITIVETYPE_INT:
603 return (float) _field_get_int(f, o);
604 case PRIMITIVETYPE_LONG:
605 return (float) _field_get_long(f, o);
606 case PRIMITIVETYPE_FLOAT:
607 return (float) _field_get_float(f, o);
609 exceptions_throw_illegalargumentexception();
616 * Class: java/lang/reflect/Field
618 * Signature: (Ljava/lang/Object;)D
620 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
626 /* get the class and the field */
628 LLNI_field_get_cls(this, clazz, c);
629 LLNI_field_get_val(this, slot , slot);
630 f = &c->fields[slot];
632 /* check if the field can be accessed */
634 if (!_field_access_check(this, f, c, (java_handle_t *) o))
637 /* check the field type and return the value */
639 switch (f->parseddesc->decltype) {
640 case PRIMITIVETYPE_BYTE:
641 case PRIMITIVETYPE_CHAR:
642 case PRIMITIVETYPE_SHORT:
643 case PRIMITIVETYPE_INT:
644 return (double) _field_get_int(f, o);
645 case PRIMITIVETYPE_LONG:
646 return (double) _field_get_long(f, o);
647 case PRIMITIVETYPE_FLOAT:
648 return (double) _field_get_float(f, o);
649 case PRIMITIVETYPE_DOUBLE:
650 return (double) _field_get_double(f, o);
652 exceptions_throw_illegalargumentexception();
659 * Class: java/lang/reflect/Field
661 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
663 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
671 /* get the class and the field */
673 LLNI_field_get_cls(this, clazz, dc);
674 LLNI_field_get_val(this, slot , slot);
675 df = &dc->fields[slot];
677 /* check if the field can be accessed */
679 if (!_field_access_check(this, df, dc, (java_handle_t *) o))
682 /* get the source classinfo from the object */
687 LLNI_class_get(value, sc);
689 /* The fieldid is used to set the new value, for primitive
690 types the value has to be retrieved from the wrapping
693 switch (df->parseddesc->decltype) {
694 case PRIMITIVETYPE_BOOLEAN: {
697 /* determine the field to read the value */
699 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
702 switch (sf->parseddesc->decltype) {
703 case PRIMITIVETYPE_BOOLEAN:
704 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
707 exceptions_throw_illegalargumentexception();
711 _field_set_int(df, o, val);
715 case PRIMITIVETYPE_BYTE: {
718 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
721 switch (sf->parseddesc->decltype) {
722 case PRIMITIVETYPE_BYTE:
723 LLNI_field_get_val((java_lang_Byte *) value, value, val);
726 exceptions_throw_illegalargumentexception();
730 _field_set_int(df, o, val);
734 case PRIMITIVETYPE_CHAR: {
737 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
740 switch (sf->parseddesc->decltype) {
741 case PRIMITIVETYPE_CHAR:
742 LLNI_field_get_val((java_lang_Character *) value, value, val);
745 exceptions_throw_illegalargumentexception();
749 _field_set_int(df, o, val);
753 case PRIMITIVETYPE_SHORT: {
756 /* get field only by name, it can be one of B, S */
758 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
761 switch (sf->parseddesc->decltype) {
762 case PRIMITIVETYPE_BYTE:
763 LLNI_field_get_val((java_lang_Byte *) value, value, val);
765 case PRIMITIVETYPE_SHORT:
766 LLNI_field_get_val((java_lang_Short *) value, value, val);
769 exceptions_throw_illegalargumentexception();
773 _field_set_int(df, o, val);
777 case PRIMITIVETYPE_INT: {
780 /* get field only by name, it can be one of B, S, C, I */
782 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
785 switch (sf->parseddesc->decltype) {
786 case PRIMITIVETYPE_BYTE:
787 LLNI_field_get_val((java_lang_Byte *) value, value, val);
789 case PRIMITIVETYPE_CHAR:
790 LLNI_field_get_val((java_lang_Character *) value, value, val);
792 case PRIMITIVETYPE_SHORT:
793 LLNI_field_get_val((java_lang_Short *) value, value, val);
795 case PRIMITIVETYPE_INT:
796 LLNI_field_get_val((java_lang_Integer *) value, value, val);
799 exceptions_throw_illegalargumentexception();
803 _field_set_int(df, o, val);
807 case PRIMITIVETYPE_LONG: {
810 /* get field only by name, it can be one of B, S, C, I, J */
812 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
815 switch (sf->parseddesc->decltype) {
816 case PRIMITIVETYPE_BYTE:
817 LLNI_field_get_val((java_lang_Byte *) value, value, val);
819 case PRIMITIVETYPE_CHAR:
820 LLNI_field_get_val((java_lang_Character *) value, value, val);
822 case PRIMITIVETYPE_SHORT:
823 LLNI_field_get_val((java_lang_Short *) value, value, val);
825 case PRIMITIVETYPE_INT:
826 LLNI_field_get_val((java_lang_Integer *) value, value, val);
828 case PRIMITIVETYPE_LONG:
829 LLNI_field_get_val((java_lang_Long *) value, value, val);
832 exceptions_throw_illegalargumentexception();
836 _field_set_long(df, o, val);
840 case PRIMITIVETYPE_FLOAT: {
843 /* get field only by name, it can be one of B, S, C, I, J, F */
845 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
848 switch (sf->parseddesc->decltype) {
849 case PRIMITIVETYPE_BYTE:
850 LLNI_field_get_val((java_lang_Byte *) value, value, val);
852 case PRIMITIVETYPE_CHAR:
853 LLNI_field_get_val((java_lang_Character *) value, value, val);
855 case PRIMITIVETYPE_SHORT:
856 LLNI_field_get_val((java_lang_Short *) value, value, val);
858 case PRIMITIVETYPE_INT:
859 LLNI_field_get_val((java_lang_Integer *) value, value, val);
861 case PRIMITIVETYPE_LONG:
862 LLNI_field_get_val((java_lang_Long *) value, value, val);
864 case PRIMITIVETYPE_FLOAT:
865 LLNI_field_get_val((java_lang_Float *) value, value, val);
868 exceptions_throw_illegalargumentexception();
872 _field_set_float(df, o, val);
876 case PRIMITIVETYPE_DOUBLE: {
879 /* get field only by name, it can be one of B, S, C, I, J, F, D */
881 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
884 switch (sf->parseddesc->decltype) {
885 case PRIMITIVETYPE_BYTE:
886 LLNI_field_get_val((java_lang_Byte *) value, value, val);
888 case PRIMITIVETYPE_CHAR:
889 LLNI_field_get_val((java_lang_Character *) value, value, val);
891 case PRIMITIVETYPE_SHORT:
892 LLNI_field_get_val((java_lang_Short *) value, value, val);
894 case PRIMITIVETYPE_INT:
895 LLNI_field_get_val((java_lang_Integer *) value, value, val);
897 case PRIMITIVETYPE_LONG:
898 LLNI_field_get_val((java_lang_Long *) value, value, val);
900 case PRIMITIVETYPE_FLOAT:
901 LLNI_field_get_val((java_lang_Float *) value, value, val);
903 case PRIMITIVETYPE_DOUBLE:
904 LLNI_field_get_val((java_lang_Double *) value, value, val);
907 exceptions_throw_illegalargumentexception();
911 _field_set_double(df, o, val);
916 /* check if value is an instance of the destination class */
919 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
922 _field_set_handle(df, o, (java_handle_t *) value);
926 /* raise exception */
928 exceptions_throw_illegalargumentexception();
933 * Class: java/lang/reflect/Field
935 * Signature: (Ljava/lang/Object;Z)V
937 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
943 /* get the class and the field */
945 LLNI_field_get_cls(this, clazz, c);
946 LLNI_field_get_val(this, slot , slot);
947 f = &c->fields[slot];
949 /* check if the field can be accessed */
951 if (!_field_access_check(this, f, c, (java_handle_t *) o))
954 /* check the field type and set the value */
956 switch (f->parseddesc->decltype) {
957 case PRIMITIVETYPE_BOOLEAN:
958 _field_set_int(f, o, value);
961 exceptions_throw_illegalargumentexception();
969 * Class: java/lang/reflect/Field
971 * Signature: (Ljava/lang/Object;B)V
973 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
979 /* get the class and the field */
981 LLNI_field_get_cls(this, clazz, c);
982 LLNI_field_get_val(this, slot , slot);
983 f = &c->fields[slot];
985 /* check if the field can be accessed */
987 if (!_field_access_check(this, f, c, (java_handle_t *) o))
990 /* check the field type and set the value */
992 switch (f->parseddesc->decltype) {
993 case PRIMITIVETYPE_BYTE:
994 case PRIMITIVETYPE_SHORT:
995 case PRIMITIVETYPE_INT:
996 _field_set_int(f, o, value);
998 case PRIMITIVETYPE_LONG:
999 _field_set_long(f, o, value);
1001 case PRIMITIVETYPE_FLOAT:
1002 _field_set_float(f, o, value);
1004 case PRIMITIVETYPE_DOUBLE:
1005 _field_set_double(f, o, value);
1008 exceptions_throw_illegalargumentexception();
1016 * Class: java/lang/reflect/Field
1018 * Signature: (Ljava/lang/Object;C)V
1020 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1026 /* get the class and the field */
1028 LLNI_field_get_cls(this, clazz, c);
1029 LLNI_field_get_val(this, slot , slot);
1030 f = &c->fields[slot];
1032 /* check if the field can be accessed */
1034 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1037 /* check the field type and set the value */
1039 switch (f->parseddesc->decltype) {
1040 case PRIMITIVETYPE_CHAR:
1041 case PRIMITIVETYPE_INT:
1042 _field_set_int(f, o, value);
1044 case PRIMITIVETYPE_LONG:
1045 _field_set_long(f, o, value);
1047 case PRIMITIVETYPE_FLOAT:
1048 _field_set_float(f, o, value);
1050 case PRIMITIVETYPE_DOUBLE:
1051 _field_set_double(f, o, value);
1054 exceptions_throw_illegalargumentexception();
1062 * Class: java/lang/reflect/Field
1064 * Signature: (Ljava/lang/Object;S)V
1066 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1072 /* get the class and the field */
1074 LLNI_field_get_cls(this, clazz, c);
1075 LLNI_field_get_val(this, slot , slot);
1076 f = &c->fields[slot];
1078 /* check if the field can be accessed */
1080 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1083 /* check the field type and set the value */
1085 switch (f->parseddesc->decltype) {
1086 case PRIMITIVETYPE_SHORT:
1087 case PRIMITIVETYPE_INT:
1088 _field_set_int(f, o, value);
1090 case PRIMITIVETYPE_LONG:
1091 _field_set_long(f, o, value);
1093 case PRIMITIVETYPE_FLOAT:
1094 _field_set_float(f, o, value);
1096 case PRIMITIVETYPE_DOUBLE:
1097 _field_set_double(f, o, value);
1100 exceptions_throw_illegalargumentexception();
1108 * Class: java/lang/reflect/Field
1110 * Signature: (Ljava/lang/Object;I)V
1112 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1118 /* get the class and the field */
1120 LLNI_field_get_cls(this, clazz, c);
1121 LLNI_field_get_val(this, slot , slot);
1122 f = &c->fields[slot];
1124 /* check if the field can be accessed */
1126 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1129 /* check the field type and set the value */
1131 switch (f->parseddesc->decltype) {
1132 case PRIMITIVETYPE_INT:
1133 _field_set_int(f, o, value);
1135 case PRIMITIVETYPE_LONG:
1136 _field_set_long(f, o, value);
1138 case PRIMITIVETYPE_FLOAT:
1139 _field_set_float(f, o, value);
1141 case PRIMITIVETYPE_DOUBLE:
1142 _field_set_double(f, o, value);
1145 exceptions_throw_illegalargumentexception();
1153 * Class: java/lang/reflect/Field
1155 * Signature: (Ljava/lang/Object;J)V
1157 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int64_t value)
1163 /* get the class and the field */
1165 LLNI_field_get_cls(this, clazz, c);
1166 LLNI_field_get_val(this, slot , slot);
1167 f = &c->fields[slot];
1169 /* check if the field can be accessed */
1171 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1174 /* check the field type and set the value */
1176 switch (f->parseddesc->decltype) {
1177 case PRIMITIVETYPE_LONG:
1178 _field_set_long(f, o, value);
1180 case PRIMITIVETYPE_FLOAT:
1181 _field_set_float(f, o, value);
1183 case PRIMITIVETYPE_DOUBLE:
1184 _field_set_double(f, o, value);
1187 exceptions_throw_illegalargumentexception();
1195 * Class: java/lang/reflect/Field
1197 * Signature: (Ljava/lang/Object;F)V
1199 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1205 /* get the class and the field */
1207 LLNI_field_get_cls(this, clazz, c);
1208 LLNI_field_get_val(this, slot , slot);
1209 f = &c->fields[slot];
1211 /* check if the field can be accessed */
1213 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1216 /* check the field type and set the value */
1218 switch (f->parseddesc->decltype) {
1219 case PRIMITIVETYPE_FLOAT:
1220 _field_set_float(f, o, value);
1222 case PRIMITIVETYPE_DOUBLE:
1223 _field_set_double(f, o, value);
1226 exceptions_throw_illegalargumentexception();
1234 * Class: java/lang/reflect/Field
1236 * Signature: (Ljava/lang/Object;D)V
1238 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1244 /* get the class and the field */
1246 LLNI_field_get_cls(this, clazz, c);
1247 LLNI_field_get_val(this, slot , slot);
1248 f = &c->fields[slot];
1250 /* check if the field can be accessed */
1252 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1255 /* check the field type and set the value */
1257 switch (f->parseddesc->decltype) {
1258 case PRIMITIVETYPE_DOUBLE:
1259 _field_set_double(f, o, value);
1262 exceptions_throw_illegalargumentexception();
1270 * Class: java/lang/reflect/Field
1271 * Method: getSignature
1272 * Signature: ()Ljava/lang/String;
1274 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1281 /* get the class and the field */
1283 LLNI_field_get_cls(this, clazz, c);
1284 LLNI_field_get_val(this, slot , slot);
1285 f = &c->fields[slot];
1287 if (f->signature == NULL)
1290 o = javastring_new(f->signature);
1292 /* in error case o is NULL */
1294 return (java_lang_String *) o;
1298 #if defined(ENABLE_ANNOTATIONS)
1300 * Class: java/lang/reflect/Field
1301 * Method: declaredAnnotations
1302 * Signature: ()Ljava/util/Map;
1304 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
1306 java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
1307 java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
1308 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
1309 classinfo *referer = NULL; /* class, which calles the annotation parser */
1310 /* (for the parameter 'referer' of vm_call_method()) */
1312 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
1314 /* are the annotations parsed yet? */
1315 if (declaredAnnotations == NULL) {
1316 LLNI_field_get_ref(this, annotations, annotations);
1317 LLNI_field_get_ref(this, clazz, declaringClass);
1318 LLNI_class_get(this, referer);
1320 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
1322 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
1325 return declaredAnnotations;
1331 * These are local overrides for various environment variables in Emacs.
1332 * Please do not remove this and leave it at the end of the file, where
1333 * Emacs will automagically detect them.
1334 * ---------------------------------------------------------------------
1337 * indent-tabs-mode: t
1341 * vim:noexpandtab:sw=4:ts=4: