Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- include/vm/reflection.h | 1 + vm/jato.c | 1 + vm/reflection.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/include/vm/reflection.h b/include/vm/reflection.h index 8e5f307..f9c709a 100644 --- a/include/vm/reflection.h +++ b/include/vm/reflection.h @@ -38,5 +38,6 @@ native_method_invokenative(struct vm_object *method, struct vm_object *o, struct vm_object *args, struct vm_object *declaringClass, jint slot); +void native_field_set(struct vm_object *this, struct vm_object *o, struct vm_object *value_obj); #endif /* __JATO_VM_REFLECTION_H */ diff --git a/vm/jato.c b/vm/jato.c index 9009334..e1fd13c 100644 --- a/vm/jato.c +++ b/vm/jato.c @@ -863,6 +863,7 @@ static struct vm_native natives[] = { DEFINE_NATIVE("java/lang/reflect/Constructor", "constructNative", &native_constructor_construct_native), DEFINE_NATIVE("java/lang/reflect/Field", "get", &native_field_get), DEFINE_NATIVE("java/lang/reflect/Field", "getModifiersInternal", native_field_get_modifiers_internal), + DEFINE_NATIVE("java/lang/reflect/Field", "set", &native_field_set), DEFINE_NATIVE("java/lang/reflect/Field", "getType", &native_field_gettype), DEFINE_NATIVE("java/lang/reflect/Method", "getParameterTypes", &native_method_get_parameter_types), DEFINE_NATIVE("java/lang/reflect/Method", "invokeNative", &native_method_invokenative), diff --git a/vm/reflection.c b/vm/reflection.c index 5ca70b2..1eecf99 100644 --- a/vm/reflection.c +++ b/vm/reflection.c @@ -653,6 +653,53 @@ static int unwrap_and_set_field(void *field_ptr, enum vm_type type, return 0; } +void native_field_set(struct vm_object *this, struct vm_object *o, + struct vm_object *value_obj) +{ + struct vm_field *vmf; + + if (!this) { + signal_new_exception(vm_java_lang_NullPointerException, NULL); + return; + } + + vmf = vm_object_to_vm_field(this); + if (!vmf) + return; + + /* + * TODO: "If this Field enforces access control, your runtime + * context is evaluated, and you may have an + * IllegalAccessException if you could not access this field + * in similar compiled code". (java/lang/reflect/Field.java) + */ + + enum vm_type type = vm_field_type(vmf); + + if (vm_field_is_static(vmf)) { + unwrap_and_set_field(vmf->class->static_values + vmf->offset, + type, value_obj); + } else { + /* + * If o is null, you get a NullPointerException, and + * if it is incompatible with the declaring class of + * the field, you get an IllegalArgumentException. + */ + if (!o) { + signal_new_exception(vm_java_lang_NullPointerException, + NULL); + return; + } + + if (o->class != vmf->class) { + signal_new_exception(vm_java_lang_IllegalArgumentException, NULL); + return; + } + + unwrap_and_set_field(&o->fields[vmf->offset], type, value_obj); + } +} + static int marshall_call_arguments(struct vm_method *vmm, unsigned long *args, struct vm_object *args_array) { -- 1.6.0.6 ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel