/*
 * Class:     java/lang/reflect/VMMethod
 * Method:    getDefaultValue
 * Signature: ()Ljava/lang/Object;
 *
 * Parses the annotation default value and returnes it (boxed, if it's a primitive).
 */
JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMMethod_getDefaultValue(JNIEnv *env, jobject _this)
{
	static methodinfo *m_parseAnnotationDefault   = NULL; /* parser method (will be chached, therefore static) */
	Utf8String         utf_parseAnnotationDefault = NULL; /* parser method name                                */
	Utf8String         utf_desc        = NULL;            /* parser method descriptor (signature)              */

	if (_this == NULL) {
		exceptions_throw_nullpointerexception();
		return NULL;
	}

	// TODO Use a constructor.
	java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);

	if (h == NULL)
		return NULL;

	sun_reflect_ConstantPool cp(h);
	
	java_lang_reflect_VMMethod rvmm(_this);
	classinfo* declaringClass = rvmm.get_clazz();
	cp.set_constantPoolOop(declaringClass);

	/* only resolve the parser method the first time */
	if (m_parseAnnotationDefault == NULL) {
		utf_parseAnnotationDefault = Utf8String::from_utf8("parseAnnotationDefault");
		utf_desc = Utf8String::from_utf8(
			"(Ljava/lang/reflect/Method;[BLsun/reflect/ConstantPool;)"
			"Ljava/lang/Object;");

		if (utf_parseAnnotationDefault == NULL || utf_desc == NULL) {
			/* out of memory */
			return NULL;
		}

		classinfo *referer = rvmm.get_Class();

		m_parseAnnotationDefault = class_resolveclassmethod(
			class_sun_reflect_annotation_AnnotationParser,
			utf_parseAnnotationDefault,
			utf_desc,
			referer,
			true);

		if (m_parseAnnotationDefault == NULL) {
			/* method not found */
			return NULL;
		}
	}

	java_lang_reflect_Method rm(rvmm.get_m());
	java_handle_bytearray_t* annotationDefault = rvmm.get_annotationDefault();

	java_handle_t* result = vm_call_method(m_parseAnnotationDefault, NULL, rm.get_handle(), annotationDefault, cp.get_handle());

	return (jobject) result;
}
Ejemplo n.º 2
0
}


/*
 * Class:     java/lang/Class
 * Method:    newInstance
 * Signature: ()Ljava/lang/Object;
 */
JNIEXPORT java_lang_Object* JNICALL Java_java_lang_Class_newInstance(JNIEnv *env, java_lang_Class* this)
{
	classinfo         *c;
	java_objectheader *o;

	c = (classinfo *) this;

	o = native_new_and_init(c);

	return (java_lang_Object *) o;
}


/*
 * Class:     java/lang/Class
 * Method:    isInstance
 * Signature: (Ljava/lang/Object;)Z
 */
JNIEXPORT s4 JNICALL Java_java_lang_Class_isInstance(JNIEnv *env, java_lang_Class *this, java_lang_Object *obj)
{
	return _Jv_java_lang_Class_isInstance(this, obj);
}