use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testNonPublicJSR292Method.
/**
* Test a non-public JSR 292 handle.
* These should be filtered out by MethodHandles.lookup().revealDirect()
* and we should not get a MethodHandleInfo for them.
*/
@Test
public void testNonPublicJSR292Method() throws Throwable {
try {
Method method = MethodHandleProxies.class.getDeclaredMethod("isObjectMethod", Method.class);
method.setAccessible(true);
MethodHandle methodHandle = MethodHandles.lookup().unreflect(method);
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
Assert.fail("MethodHandles.lookup().revealDirect() should have returned null because MethodHandleProxies.isObjectMethod() is a non-public method in the java.lang.invoke package.");
} catch (IllegalArgumentException e) {
// Success!
}
}
use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testPublicStaticMethod.
/**
* Test a public static method reference
*/
@Test
public void testPublicStaticMethod() {
try {
Class declaringClass = System.class;
MethodType methodType = MethodType.methodType(String.class, String.class);
String methodName = "getenv";
MethodHandle methodHandle = MethodHandles.lookup().findStatic(declaringClass, methodName, methodType);
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
checkMethodHandleInfo(info, declaringClass, methodType, Modifier.PUBLIC | Modifier.STATIC, methodName, MethodHandleInfo.REF_invokeStatic);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
}
use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testStaticFieldSetter.
/**
* Test a static field setter handle
*/
@Test
public void testStaticFieldSetter() {
try {
Class<?> declaringClass = this.getClass();
String fieldName = "staticFieldSetterTestString";
MethodHandle methodHandle = MethodHandles.lookup().findStaticSetter(declaringClass, fieldName, String.class);
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
checkMethodHandleInfo(info, declaringClass, MethodType.methodType(void.class, String.class), Modifier.PUBLIC | Modifier.STATIC, fieldName, MethodHandleInfo.REF_putStatic);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
}
use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class TestMethodHandleInfo method testFieldGetter.
/**
* Test a field getter handle
*/
@Test
public void testFieldGetter() {
try {
Class<?> declaringClass = this.getClass();
String fieldName = "fieldGetterTestInt";
MethodHandle methodHandle = MethodHandles.lookup().findGetter(declaringClass, fieldName, int.class);
MethodHandleInfo info = MethodHandles.lookup().revealDirect(methodHandle);
checkMethodHandleInfo(info, declaringClass, MethodType.methodType(int.class), Modifier.PUBLIC | Modifier.VOLATILE, fieldName, MethodHandleInfo.REF_getField);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getLocalizedMessage());
}
}
use of java.lang.invoke.MethodHandleInfo in project openj9 by eclipse.
the class Test_MethodHandle method testMethodDescribeConstableGeneralSub.
private void testMethodDescribeConstableGeneralSub(String testName, MethodHandle handle, MethodHandles.Lookup resolveLookup) throws Throwable {
MethodHandleDesc handleDesc = handle.describeConstable().orElseThrow();
/* verify that descriptor can be resolved. If not ReflectiveOperationException will be thrown. */
MethodHandle resolvedHandle = (MethodHandle) handleDesc.resolveConstantDesc(resolveLookup);
/* verify that resolved MethodType is the same as original */
MethodHandleInfo oInfo = MethodHandles.lookup().revealDirect(handle);
MethodHandleInfo rInfo = MethodHandles.lookup().revealDirect(resolvedHandle);
logger.debug(testName + ": Descriptor of original MethodHandle " + oInfo.getMethodType().descriptorString() + " descriptor of MethodHandleDesc is: " + rInfo.getMethodType().descriptorString());
Assert.assertTrue(oInfo.getMethodType().equals(rInfo.getMethodType()));
Assert.assertTrue(oInfo.getDeclaringClass().equals(rInfo.getDeclaringClass()));
Assert.assertTrue(oInfo.getName().equals(rInfo.getName()));
Assert.assertEquals(oInfo.getModifiers(), rInfo.getModifiers());
Assert.assertEquals(oInfo.getReferenceKind(), rInfo.getReferenceKind());
}
Aggregations