* src/native/vm/sun/jvm.c (JVM_GetEnclosingMethodInfo): Implemented.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 5 Dec 2007 12:55:47 +0000 (13:55 +0100)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 5 Dec 2007 12:55:47 +0000 (13:55 +0100)
* src/vmcore/class.c (class_get_enclosingmethod): New function.
* src/vmcore/class.h: Likewise.

src/native/vm/sun/jvm.c
src/vmcore/class.c
src/vmcore/class.h

index 91f490382052078a1329fe5b935db4f722677e98..0cf10dc127dc39bcc27cfa82c4f01be5a9ee1a66 100644 (file)
@@ -3143,7 +3143,32 @@ jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
 
 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
 {
-       log_println("JVM_GetEnclosingMethodInfo: IMPLEMENT ME!");
+       classinfo                 *c;
+       methodinfo                *m;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass);
+
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       if ((c == NULL) || class_is_primitive(c))
+               return NULL;
+
+       m = class_get_enclosingmethod(c);
+
+       if (m == NULL)
+               return NULL;
+
+       oa = builtin_anewarray(3, class_java_lang_Object);
+
+       if (oa == NULL)
+               return NULL;
+
+       array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->class));
+       array_objectarray_element_set(oa, 1, javastring_new(m->name));
+       array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
+
+       return (jobjectArray) oa;
 }
 
 
index 1e5d2f30480be57d3dc19c1921c682cbb1a1b209..c0b1c9e9f1082d2acfb225c25d34e10fc6c49037 100644 (file)
@@ -1781,6 +1781,50 @@ classinfo *class_get_enclosingclass(classinfo *c)
 }
 
 
+/* class_get_enclosingmethod ***************************************************
+
+   Return the enclosing method for the given class.
+
+   IN:
+       c ... class to return the enclosing method for
+
+   RETURN:
+       methodinfo of the enclosing method
+
+*******************************************************************************/
+
+methodinfo *class_get_enclosingmethod(classinfo *c)
+{
+       constant_nameandtype *cn;
+       classinfo            *ec;
+       methodinfo           *m;
+
+       /* get enclosing class and method */
+
+       ec = class_get_enclosingclass(c);
+       cn = c->enclosingmethod;
+
+       /* check for enclosing class and method */
+
+       if (ec == NULL)
+               return NULL;
+
+       if (cn == NULL)
+               return NULL;
+
+       /* find method in enclosing class */
+
+       m = class_findmethod(ec, cn->name, cn->descriptor);
+
+       if (m == NULL) {
+               exceptions_throw_internalerror("Enclosing method doesn't exist");
+               return NULL;
+       }
+
+       return m;
+}
+
+
 /* class_get_interfaces ********************************************************
 
    Return an array of interfaces of the given class.
index 6d4ab0627e096a5498d8253cfa7c293415dd692e..e3b194b33b793cdc464aad53f381e6add57c1a65 100644 (file)
@@ -496,6 +496,7 @@ classinfo                 *class_get_componenttype(classinfo *c);
 java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOnly);
 classinfo                 *class_get_declaringclass(classinfo *c);
 classinfo                 *class_get_enclosingclass(classinfo *c);
+methodinfo                *class_get_enclosingmethod(classinfo *c);
 java_handle_objectarray_t *class_get_interfaces(classinfo *c);
 java_handle_bytearray_t   *class_get_annotations(classinfo *c);
 int32_t                    class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib);