Пример #1
0
/*
* Class:     java_lang_VMClassRegistry
* Method:    getEnclosingClass
* Signature: (Ljava/lang/Class;)Ljava/lang/Class;
*/
JNIEXPORT jclass JNICALL Java_java_lang_VMClassRegistry_getEnclosingClass
(JNIEnv *, jclass, jclass jclazz)
{
    assert(jclazz);
    Class* clazz = jclass_to_struct_Class(jclazz);
    unsigned idx = clazz->get_enclosing_class_index();
    if (!idx) {
        idx = clazz->get_declaring_class_index();
    }
    if (idx) {
        Class* outer_clss = clazz->_resolve_class(VM_Global_State::loader_env, idx);
        if (outer_clss) {
            return struct_Class_to_jclass(outer_clss);
        }
        if (!exn_raised()) {
            exn_raise_object(clazz->get_constant_pool().get_error_cause(idx));
        }
    } 
    return NULL;
}
Пример #2
0
/*
* Class:     java_lang_VMClassRegistry
* Method:    getEnclosingMember
* Signature: (Ljava/lang/Class;)Ljava/lang/reflect/Member;
*/
JNIEXPORT jobject JNICALL Java_java_lang_VMClassRegistry_getEnclosingMember
(JNIEnv *jenv, jclass, jclass jclazz)
{
    assert(jclazz);
    Class* clazz = jclass_to_struct_Class(jclazz);
    unsigned method_idx = clazz->get_enclosing_method_index();
    if (method_idx) {
        unsigned c_idx = clazz->get_enclosing_class_index();
        ASSERT(c_idx, ("No class for enclosing method"));
        Class* outer_clss = clazz->_resolve_class(VM_Global_State::loader_env, c_idx);
        if (outer_clss) 
        {
            String* name = clazz->get_constant_pool().get_name_and_type_name(method_idx);
            String* desc = clazz->get_constant_pool().get_name_and_type_descriptor(method_idx);

            TRACE("Looking for enclosing method: class="<<outer_clss->get_name()->bytes 
                <<"; name="<<name->bytes<<"; desc="<<desc->bytes);

            Method* enclosing = outer_clss->lookup_method(name, desc);
            if (enclosing) 
            {
                if (enclosing->is_init()) 
                {
                    return reflection_reflect_constructor(jenv, enclosing);
                } 
                else if (!enclosing->is_clinit()) 
                {
                    return reflection_reflect_method(jenv, enclosing);
                }
            } else {
                //FIXME: check RI compatibility, provide detailed message
                ThrowNew_Quick(jenv, "java/lang/NoSuchMethodException", 
                    "Invalid enclosing method declared");
            }
        } else if (!exn_raised()) {
            exn_raise_object(clazz->get_constant_pool().get_error_cause(c_idx));
        }
    } 
    return NULL;
}