use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testPublicInstanceMethod.
/**
* Test a public instance method reference
*/
@Test
public void testPublicInstanceMethod() {
try {
Class declaringClass = String.class;
String methodName = "length";
MethodType methodType = MethodType.methodType(int.class);
MethodHandle methodHandle = MethodHandles.lookup().findVirtual(declaringClass, methodName, methodType);
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
checkMethodHandleInfo(info, declaringClass, MethodType.methodType(int.class), Modifier.PUBLIC, methodName, MethodHandleInfo.REF_invokeVirtual);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
}
use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testFieldSetter.
/**
* Test a field setter handle
*/
@Test
public void testFieldSetter() {
try {
Class declaringClass = this.getClass();
String fieldName = "fieldSetterTestString";
MethodHandle methodHandle = MethodHandles.lookup().findSetter(declaringClass, fieldName, String.class);
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
checkMethodHandleInfo(info, declaringClass, MethodType.methodType(void.class, String.class), Modifier.PUBLIC, fieldName, MethodHandleInfo.REF_putField);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
}
use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testSpecial.
/**
* Test a special handle
*/
@Test
public void testSpecial() {
try {
Class<?> declaringClass = TestMethodHandleInfo.class;
String methodName = "testSpecial";
MethodType methodType = MethodType.methodType(void.class);
MethodHandle methodHandle = MethodHandles.lookup().findSpecial(declaringClass, methodName, methodType, TestMethodHandleInfo.class);
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
checkMethodHandleInfo(info, declaringClass, methodType, Modifier.PUBLIC, methodName, MethodHandleInfo.REF_invokeSpecial);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
}
use of java.lang.invoke.MethodHandleInfo in project jdk8u_jdk by JetBrains.
the class DummyFieldHolder method doTest.
private static void doTest(MethodHandle mh, TestMethodData testMethod) {
MethodHandleInfo mhi = LOOKUP.revealDirect(mh);
System.out.printf("%s.%s: %s, nominal refKind: %s, actual refKind: %s\n", testMethod.clazz.getName(), testMethod.name, testMethod.methodType, referenceKindToString(testMethod.referenceKind), referenceKindToString(mhi.getReferenceKind()));
assertEquals(testMethod.name, mhi.getName());
assertEquals(testMethod.methodType, mhi.getMethodType());
assertEquals(testMethod.declaringClass, mhi.getDeclaringClass());
assertEquals(testMethod.referenceKind == REF_invokeSpecial, isInvokeSpecial(mh));
assertRefKindEquals(testMethod.referenceKind, mhi.getReferenceKind());
}
use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testInterface.
/**
* Test an interface handle
*/
@Test
public void testInterface() {
/*
* This class is a subclass of junit.framework.TestCase which
* implements the junit.framework.Test interface. The latter
* declares the 'public abstract int countTestCases()' method
*/
try {
// Class declaringClass = org.testng.junit.JUnit3TestClass.class;
// String methodName = "getInstanceCount";
Class declaringClass = junit.framework.Test.class;
String methodName = "countTestCases";
MethodHandle methodHandle = MethodHandles.lookup().findVirtual(declaringClass, methodName, MethodType.methodType(int.class));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
checkMethodHandleInfo(info, declaringClass, MethodType.methodType(int.class), Modifier.PUBLIC | Modifier.ABSTRACT, methodName, MethodHandleInfo.REF_invokeInterface);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
}
Aggregations