Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/reflection.h |    1 +
 include/vm/types.h      |    1 +
 vm/jato.c               |    1 +
 vm/reflection.c         |   29 +++++++++++++++++++++++++++++
 vm/types.c              |   22 +++++++++++++---------
 5 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/include/vm/reflection.h b/include/vm/reflection.h
index ebfd0fe..8e5f307 100644
--- a/include/vm/reflection.h
+++ b/include/vm/reflection.h
@@ -31,6 +31,7 @@ struct vm_object *native_vmclass_get_interfaces(struct 
vm_object *clazz);
 struct vm_object *native_vmclass_get_superclass(struct vm_object *clazz);
 struct vm_object *native_field_get(struct vm_object *this, struct vm_object 
*o);
 jint native_field_get_modifiers_internal(struct vm_object *this);
+struct vm_object *native_field_gettype(struct vm_object *this);
 
 struct vm_object *
 native_method_invokenative(struct vm_object *method, struct vm_object *o,
diff --git a/include/vm/types.h b/include/vm/types.h
index 93fbb33..368729d 100644
--- a/include/vm/types.h
+++ b/include/vm/types.h
@@ -36,6 +36,7 @@ int vmtype_to_bytecode_type(enum vm_type);
 int get_vmtype_size(enum vm_type);
 const char *get_vm_type_name(enum vm_type);
 const char *parse_method_args(const char *, enum vm_type *, char **);
+const char *parse_type(const char *, enum vm_type *, char **);
 unsigned int count_java_arguments(const char *);
 
 static inline bool vm_type_is_float(enum vm_type type)
diff --git a/vm/jato.c b/vm/jato.c
index bf67188..9009334 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", "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),
        DEFINE_NATIVE("jato/internal/VM", "enableFault", 
&native_vm_enable_fault),
diff --git a/vm/reflection.c b/vm/reflection.c
index c9846f8..154e86e 100644
--- a/vm/reflection.c
+++ b/vm/reflection.c
@@ -701,3 +701,32 @@ native_method_invokenative(struct vm_object *method, 
struct vm_object *o,
        signal_new_exception(vm_java_lang_IllegalArgumentException, NULL);
        return NULL;
 }
+
+struct vm_object *native_field_gettype(struct vm_object *this)
+{
+       struct vm_field *vmf;
+
+       if (!this) {
+               signal_new_exception(vm_java_lang_NullPointerException, NULL);
+               return 0;
+       }
+
+       vmf = vm_object_to_vm_field(this);
+       if (!vmf)
+               return 0;
+
+       enum vm_type vmtype;
+       char *type_name;
+
+       if (!parse_type(vmf->type, &vmtype, &type_name)) {
+               warn("type parsing failed");
+               return NULL;
+       }
+
+       struct vm_class *vmc = vm_type_to_class(type_name, vmtype);
+
+       if (vm_class_ensure_init(vmc))
+               return NULL;
+
+       return vmc->object;
+}
diff --git a/vm/types.c b/vm/types.c
index 39e3d45..08a2e4a 100644
--- a/vm/types.c
+++ b/vm/types.c
@@ -161,20 +161,15 @@ const char *get_vm_type_name(enum vm_type type) {
        return vm_type_names[type];
 }
 
-const char *parse_method_args(const char *type_str, enum vm_type *vmtype,
-                             char **name_p)
+const char *parse_type(const char *type_str, enum vm_type *vmtype,
+                      char **name_p)
 {
-       const char *type_name_start;
-
-       if (*type_str == '(')
-               type_str++;
-
-       type_name_start = type_str;
+       const char *type_name_start = type_str;
 
        if (name_p)
                *name_p = NULL;
 
-       if (*type_str == ')')
+       if (!type_str || *type_str == ')')
                return NULL;
 
        if (*type_str == '[') {
@@ -217,6 +212,15 @@ const char *parse_method_args(const char *type_str, enum 
vm_type *vmtype,
        return type_str;
 }
 
+const char *parse_method_args(const char *type_str, enum vm_type *vmtype,
+                             char **name_p)
+{
+       if (*type_str == '(')
+               type_str++;
+
+       return parse_type(type_str, vmtype, name_p);
+}
+
 unsigned int count_java_arguments(const char *type)
 {
        unsigned int count;
-- 
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

Reply via email to