Search in sources :

Example 71 with Lookup

use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.

the class MethodHandleAPI_privateLookupIn method test_privateLookupIn_TargetClass_callerLookup_DiffferentPackage_SameModule.

/**
 * privateLookupIn test for a target class and a caller lookup from different packages within the same module
 */
@Test(groups = { "level.sanity" })
public static void test_privateLookupIn_TargetClass_callerLookup_DiffferentPackage_SameModule() throws Throwable {
    Lookup mhprivateLookupIn = privateLookupIn(SameModuleExample.class, callerLookup);
    Assert.assertEquals(mhprivateLookupIn.lookupClass(), SameModuleExample.class);
    Assert.assertEquals(mhprivateLookupIn.lookupModes() & Lookup.PRIVATE, Lookup.PRIVATE);
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 72 with Lookup

use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.

the class MethodHandleAPI_privateLookupIn method test_privateLookupIn_NullcallerLookup.

/**
 * privateLookupIn test for a null caller lookup.
 */
@Test(expectedExceptions = NullPointerException.class, groups = { "level.sanity" })
public static void test_privateLookupIn_NullcallerLookup() throws Throwable {
    Lookup mhprivateLookupIn = privateLookupIn(Object.class, null);
    Assert.fail("The test case failed to detect a null caller lookup");
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 73 with Lookup

use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.

the class MethodHandleAPI_privateLookupIn method test_privateLookupIn_TargetClass_PrimitiveType.

/**
 * privateLookupIn test for a target class with a primitive type.
 */
@Test(expectedExceptions = IllegalArgumentException.class, groups = { "level.sanity" })
public static void test_privateLookupIn_TargetClass_PrimitiveType() throws Throwable {
    Lookup mhprivateLookupIn = privateLookupIn(int.class, callerLookup);
    Assert.fail("The test case failed to detect a target class with a primitive type");
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 74 with Lookup

use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.

the class LookupInTests method testLookup_in_Assert.

/**
 * Validates access restrictions stored in a new Lookup object created from the Lookup object of this class (LookupInTests)
 * where the new lookup class is org.testng.Assert.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_in_Assert() throws Throwable {
    Lookup newLookup = localLookup.in(Assert.class);
    assertClassAndMode(newLookup, Assert.class, MODULE_PUBLIC_MODE);
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 75 with Lookup

use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.

the class Find_InvokeTracker method test_FindSpecial_Public_SamePackage_Overridden_InnerClass_Nested_Level2.

/**
 * findSpecial test using a public overridden method belonging to a second level inner class
 * which is a child of a first level inner class (the lookup class) under the same outer class.
 * The resultant method handle is bound to LookupAPITests_Find (this class).
 * @throws Throwable
 */
@Test(groups = { "level.extended" })
public void test_FindSpecial_Public_SamePackage_Overridden_InnerClass_Nested_Level2() throws Throwable {
    SamePackageExample spe = new SamePackageExample();
    SamePackageInnerClass spe_inner1 = spe.new SamePackageInnerClass();
    Lookup publicLookup = spe_inner1.getLookup();
    boolean iaeThrown = false;
    try {
        publicLookup.findSpecial(SamePackageExample.SamePackageInnerClass2.SamePackageInnerClass2_Nested_Level2_SubOf_Inner1.class, "addPublicInner", MethodType.methodType(int.class, int.class, int.class), LookupAPITests_Find.class);
    } catch (IllegalAccessException e) {
        iaeThrown = true;
    }
    assert (iaeThrown);
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) SamePackageInnerClass(com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass) Test(org.testng.annotations.Test)

Aggregations

Lookup (java.lang.invoke.MethodHandles.Lookup)216 Test (org.testng.annotations.Test)176 MethodHandle (java.lang.invoke.MethodHandle)96 MethodHandles.publicLookup (java.lang.invoke.MethodHandles.publicLookup)39 Method (java.lang.reflect.Method)36 SamePackageInnerClass (com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass)17 MutableCallSite (java.lang.invoke.MutableCallSite)11 MethodHandles (java.lang.invoke.MethodHandles)9 SamePackageInnerClass_Nested_Level2 (com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2)7 PackageExamples (examples.PackageExamples)7 MethodHandles.constant (java.lang.invoke.MethodHandles.constant)4 MethodHandles.dropArguments (java.lang.invoke.MethodHandles.dropArguments)4 MethodHandles.exactInvoker (java.lang.invoke.MethodHandles.exactInvoker)4 MethodHandles.foldArguments (java.lang.invoke.MethodHandles.foldArguments)4 MethodType.methodType (java.lang.invoke.MethodType.methodType)4 Constructor (java.lang.reflect.Constructor)4 ArrayList (java.util.ArrayList)4 Objects (java.util.Objects)4 Function (java.util.function.Function)4 ToDoubleFunction (java.util.function.ToDoubleFunction)4