* Removed all Id tags.
[cacao.git] / src / native / vm / reflect.c
index 9281c70d1303b28ced37226e7bc3e5d72af70e31..72b268ab6f590094a162bd38cbaaf8890fb251ff 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: reflect.c 8305 2007-08-15 13:49:26Z panzi $
-
 */
 
 
@@ -60,7 +58,6 @@
 #include "native/include/java_lang_reflect_Field.h"
 #include "native/include/java_lang_reflect_Method.h"
 
-#include "native/vm/java_lang_String.h"
 #include "native/vm/reflect.h"
 
 #include "vm/builtin.h"
@@ -83,39 +80,10 @@ java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m)
        java_handle_t                 *o;
        java_lang_reflect_Constructor *rc;
        int32_t                        slot;
-       java_bytearray                *annotations          = NULL;
-       java_bytearray                *parameterAnnotations = NULL;
-       annotation_bytearray_t        *ba                   = NULL;
-
-#if defined(ENABLE_ANNOTATIONS)
-       /* get annotations */
-       ba = method_get_annotations(m);
-
-       if (ba != NULL) {
-               annotations = builtin_newarray_byte(ba->size);
-
-               if (annotations == NULL)
-                       return NULL;
-               
-               MCOPY(annotations->data, ba->data, uint8_t, ba->size);
-       }
-       
-       /* get parameter annotations */
-       ba = method_get_parameterannotations(m);
-
-       if (ba != NULL) {
-               parameterAnnotations = builtin_newarray_byte(ba->size);
-
-               if (parameterAnnotations == NULL)
-                       return NULL;
-               
-               MCOPY(parameterAnnotations->data, ba->data, uint8_t, ba->size);
-       }
-#endif
 
        /* get declaring class */
 
-       c = (classinfo *) m->class;
+       c = m->class;
 
        /* allocate a new object */
 
@@ -136,8 +104,8 @@ java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m)
 
        LLNI_field_set_cls(rc, clazz               , c);
        LLNI_field_set_val(rc, slot                , slot);
-       LLNI_field_set_ref(rc, annotations         , annotations);
-       LLNI_field_set_ref(rc, parameterAnnotations, parameterAnnotations);
+       LLNI_field_set_ref(rc, annotations         , method_get_annotations(m));
+       LLNI_field_set_ref(rc, parameterAnnotations, method_get_parameterannotations(m));
 
 #elif defined(WITH_CLASSPATH_SUN)
 
@@ -147,8 +115,8 @@ java_lang_reflect_Constructor *reflect_constructor_new(methodinfo *m)
        LLNI_field_set_val(rc, modifiers           , m->flags & ACC_CLASS_REFLECT_MASK);
        LLNI_field_set_val(rc, slot                , slot);
        LLNI_field_set_ref(rc, signature           , m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL);
-       LLNI_field_set_ref(rc, annotations         , annotations);
-       LLNI_field_set_ref(rc, parameterAnnotations, parameterAnnotations);
+       LLNI_field_set_ref(rc, annotations         , method_get_annotations(m));
+       LLNI_field_set_ref(rc, parameterAnnotations, method_get_parameterannotations(m));
 
 #else
 # error unknown classpath configuration
@@ -171,26 +139,10 @@ java_lang_reflect_Field *reflect_field_new(fieldinfo *f)
        java_handle_t           *o;
        java_lang_reflect_Field *rf;
        int32_t                  slot;
-       java_bytearray          *annotations = NULL;
-       annotation_bytearray_t  *ba          = NULL;
-
-#if defined(ENABLE_ANNOTATIONS)
-       /* get annotations */
-       ba = field_get_annotations(f);
-
-       if (ba != NULL) {
-               annotations = builtin_newarray_byte(ba->size);
-
-               if (annotations == NULL)
-                       return NULL;
-               
-               MCOPY(annotations->data, ba->data, uint8_t, ba->size);
-       }
-#endif
 
        /* get declaring class */
 
-       c = (classinfo *) f->class;
+       c = f->class;
 
        /* allocate a new object */
 
@@ -214,9 +166,9 @@ java_lang_reflect_Field *reflect_field_new(fieldinfo *f)
        /* The name needs to be interned */
        /* XXX implement me better! */
 
-       LLNI_field_set_ref(rf, name          , _Jv_java_lang_String_intern((java_lang_String *) javastring_new(f->name)));
+       LLNI_field_set_ref(rf, name          , javastring_intern((java_lang_String *) javastring_new(f->name)));
        LLNI_field_set_val(rf, slot          , slot);
-       LLNI_field_set_ref(rf, annotations   , annotations);
+       LLNI_field_set_ref(rf, annotations   , field_get_annotations(f));
 
 #elif defined(WITH_CLASSPATH_SUN)
 
@@ -225,12 +177,12 @@ java_lang_reflect_Field *reflect_field_new(fieldinfo *f)
        /* The name needs to be interned */
        /* XXX implement me better! */
 
-       LLNI_field_set_ref(rf, name          , _Jv_java_lang_String_intern((java_lang_String *) javastring_new(f->name)));
+       LLNI_field_set_ref(rf, name          , javastring_intern((java_lang_String *) javastring_new(f->name)));
        LLNI_field_set_cls(rf, type          , (java_lang_Class *) field_get_type(f));
        LLNI_field_set_val(rf, modifiers     , f->flags);
        LLNI_field_set_val(rf, slot          , slot);
        LLNI_field_set_ref(rf, signature     , f->signature ? (java_lang_String *) javastring_new(f->signature) : NULL);
-       LLNI_field_set_ref(rf, annotations   , annotations);
+       LLNI_field_set_ref(rf, annotations   , field_get_annotations(f));
 
 #else
 # error unknown classpath configuration
@@ -253,52 +205,10 @@ java_lang_reflect_Method *reflect_method_new(methodinfo *m)
        java_handle_t            *o;
        java_lang_reflect_Method *rm;
        int32_t                   slot;
-       java_bytearray           *annotations          = NULL;
-       java_bytearray           *parameterAnnotations = NULL;
-       java_bytearray           *annotationDefault    = NULL;
-       annotation_bytearray_t   *ba                   = NULL;
-
-#if defined(ENABLE_ANNOTATIONS)
-       /* get annotations */
-       ba = method_get_annotations(m);
-
-       if (ba != NULL) {
-               annotations = builtin_newarray_byte(ba->size);
-
-               if (annotations == NULL)
-                       return NULL;
-               
-               MCOPY(annotations->data, ba->data, uint8_t, ba->size);
-       }
-       
-       /* get parameter annotations */
-       ba = method_get_parameterannotations(m);
-
-       if (ba != NULL) {
-               parameterAnnotations = builtin_newarray_byte(ba->size);
-
-               if (parameterAnnotations == NULL)
-                       return NULL;
-               
-               MCOPY(parameterAnnotations->data, ba->data, uint8_t, ba->size);
-       }
-
-       /* get annotation default value */
-       ba = method_get_annotationdefault(m);
-
-       if (ba != NULL) {
-               annotationDefault = builtin_newarray_byte(ba->size);
-
-               if (annotationDefault == NULL)
-                       return NULL;
-               
-               MCOPY(annotationDefault->data, ba->data, uint8_t, ba->size);
-       }
-#endif
 
        /* get declaring class */
 
-       c = (classinfo *) m->class;
+       c = m->class;
 
        /* allocate a new object */
 
@@ -322,29 +232,29 @@ java_lang_reflect_Method *reflect_method_new(methodinfo *m)
        /* The name needs to be interned */
        /* XXX implement me better! */
 
-       LLNI_field_set_ref(rm, name                , _Jv_java_lang_String_intern((java_lang_String *) javastring_new(m->name)));
+       LLNI_field_set_ref(rm, name                , javastring_intern((java_lang_String *) javastring_new(m->name)));
        LLNI_field_set_val(rm, slot                , slot);
-       LLNI_field_set_ref(rm, annotations         , annotations);
-       LLNI_field_set_ref(rm, parameterAnnotations, parameterAnnotations);
-       LLNI_field_set_ref(rm, annotationDefault   , annotationDefault);
+       LLNI_field_set_ref(rm, annotations         , method_get_annotations(m));
+       LLNI_field_set_ref(rm, parameterAnnotations, method_get_parameterannotations(m));
+       LLNI_field_set_ref(rm, annotationDefault   , method_get_annotationdefault(m));
 
 #elif defined(WITH_CLASSPATH_SUN)
 
-       LLNI_field_set_cls(rm, clazz               , (java_lang_Class *) m->class);
+       LLNI_field_set_cls(rm, clazz               , m->class);
 
        /* The name needs to be interned */
        /* XXX implement me better! */
 
-       rm->name                 = _Jv_java_lang_String_intern((java_lang_String *) javastring_new(m->name));
-       rm->parameterTypes       = method_get_parametertypearray(m);
-       rm->returnType           = (java_lang_Class *) method_returntype_get(m);
-       rm->exceptionTypes       = method_get_exceptionarray(m);
-       rm->modifiers            = m->flags & ACC_CLASS_REFLECT_MASK;
-       rm->slot                 = slot;
-       rm->signature            = m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL;
-       rm->annotations          = annotations;
-       rm->parameterAnnotations = parameterAnnotations;
-       rm->annotationDefault    = annotationDefault;
+       LLNI_field_set_ref(rm, name                , javastring_intern((java_lang_String *) javastring_new(m->name)));
+       LLNI_field_set_ref(rm, parameterTypes      , method_get_parametertypearray(m));
+       LLNI_field_set_cls(rm, returnType          , (java_lang_Class *) method_returntype_get(m));
+       LLNI_field_set_ref(rm, exceptionTypes      , method_get_exceptionarray(m));
+       LLNI_field_set_val(rm, modifiers           , m->flags & ACC_CLASS_REFLECT_MASK);
+       LLNI_field_set_val(rm, slot                , slot);
+       LLNI_field_set_ref(rm, signature           , m->signature ? (java_lang_String *) javastring_new(m->signature) : NULL);
+       LLNI_field_set_ref(rm, annotations         , method_get_annotations(m));
+       LLNI_field_set_ref(rm, parameterAnnotations, method_get_parameterannotations(m));
+       LLNI_field_set_ref(rm, annotationDefault   , method_get_annotationdefault(m));
 
 #else
 # error unknown classpath configuration
@@ -357,15 +267,15 @@ java_lang_reflect_Method *reflect_method_new(methodinfo *m)
 #if defined(WITH_CLASSPATH_GNU) && defined(ENABLE_ANNOTATIONS)
 /* reflect_get_declaredannotatios *********************************************
 
-   Returns a java.util.Map<Class, Annotation> of the declared
-   annotations.
+   Returns a java.util.Map<Class<? extends Annotation>, Annotation>
+   of the declared annotations.
 
 *******************************************************************************/
 
 struct java_util_Map* reflect_get_declaredannotatios(
-       java_bytearray       *annotations,
-       java_lang_Class      *declaringClass,
-       classinfo            *referer)
+       java_handle_bytearray_t *annotations,
+       java_lang_Class         *declaringClass,
+       classinfo               *referer)
 {
        static methodinfo        *m_parseAnnotations   = NULL;
        utf                      *utf_parseAnnotations = NULL;
@@ -421,7 +331,7 @@ struct java_util_Map* reflect_get_declaredannotatios(
 
 *******************************************************************************/
 
-java_objectarray* reflect_get_parameterannotations(
+java_handle_objectarray_t* reflect_get_parameterannotations(
        java_handle_t     *parameterAnnotations,
        int32_t            slot,
        java_lang_Class   *declaringClass,
@@ -452,7 +362,7 @@ java_objectarray* reflect_get_parameterannotations(
 
        /* get parameter count */
 
-       c = (classinfo *)declaringClass;
+       c = LLNI_classinfo_unwrap(declaringClass);
        m = &(c->methods[slot]);
 
        numParameters = method_get_parametercount(m);
@@ -503,7 +413,7 @@ java_objectarray* reflect_get_parameterannotations(
                }
        }
 
-       return (java_objectarray*)vm_call_method(
+       return (java_handle_objectarray_t*)vm_call_method(
                m_parseParameterAnnotations, NULL, parameterAnnotations,
                constantPool, declaringClass, numParameters);
 }