Search in sources :

Example 6 with MethodHandleInfo

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());
    }
}
Also used : MethodType(java.lang.invoke.MethodType) MethodHandleInfo(java.lang.invoke.MethodHandleInfo) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 7 with MethodHandleInfo

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());
    }
}
Also used : MethodHandleInfo(java.lang.invoke.MethodHandleInfo) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 8 with MethodHandleInfo

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());
    }
}
Also used : MethodType(java.lang.invoke.MethodType) MethodHandleInfo(java.lang.invoke.MethodHandleInfo) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 9 with MethodHandleInfo

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());
}
Also used : MethodHandleInfo(java.lang.invoke.MethodHandleInfo)

Example 10 with MethodHandleInfo

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());
    }
}
Also used : Test(org.testng.annotations.Test) MethodHandleInfo(java.lang.invoke.MethodHandleInfo) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Aggregations

MethodHandleInfo (java.lang.invoke.MethodHandleInfo)15 MethodHandle (java.lang.invoke.MethodHandle)13 Test (org.testng.annotations.Test)11 MethodType (java.lang.invoke.MethodType)5 MethodHandleDesc (java.lang.constant.MethodHandleDesc)1 Executable (java.lang.reflect.Executable)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1