當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodHandles.publicLookup方法代碼示例

本文整理匯總了Java中java.lang.invoke.MethodHandles.publicLookup方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodHandles.publicLookup方法的具體用法?Java MethodHandles.publicLookup怎麽用?Java MethodHandles.publicLookup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.invoke.MethodHandles的用法示例。


在下文中一共展示了MethodHandles.publicLookup方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPublicLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
/**
 * MethodHandles.publicLookup()
 *
 * [A0] has PUBLIC|UNCONDITIONAL access
 */
public void testPublicLookup() throws Exception {
    Lookup lookup = MethodHandles.publicLookup();
    assertTrue(lookup.lookupModes() == (PUBLIC|UNCONDITIONAL)); // A0

    // m1
    findConstructor(lookup, p1_Type1, void.class);
    findConstructorExpectingIAE(lookup, p2_Type2, void.class);

    // m2
    findConstructor(lookup, q1_Type1, void.class);
    findConstructorExpectingIAE(lookup, q2_Type2, void.class);

    // java.base
    findConstructor(lookup, Object.class, void.class);
    findConstructorExpectingIAE(lookup, x500NameClass, void.class, String.class);

    // unnamed
    findConstructor(lookup, unnamedClass, void.class);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:Main.java

示例2: testAutoLoadedLinkerInvoked

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
private static void testAutoLoadedLinkerInvoked(final Object target, final String methodName) {
    final DynamicLinkerFactory factory = newDynamicLinkerFactory(false);
    final DynamicLinker linker = factory.createLinker();

    // we should still get one error due to untrusted dynamic linker exporter!
    checkOneAutoLoadingError(factory);

    final MethodType mt = MethodType.methodType(Object.class, Object.class);
    final CallSiteDescriptor testDescriptor = new CallSiteDescriptor(MethodHandles.publicLookup(),
            GET.withNamespace(StandardNamespace.METHOD).named(methodName), mt);
    final CallSite cs = linker.link(new SimpleRelinkableCallSite(testDescriptor));

    TrustedGuardingDynamicLinkerExporter.enable();
    try {
        cs.getTarget().invoke(target);
        // The linker was loaded and it observed our invocation
        Assert.assertTrue(TrustedGuardingDynamicLinkerExporter.isLastCallSiteDescriptor(testDescriptor));
    } catch (final Throwable th) {
        throw new RuntimeException(th);
    } finally {
        TrustedGuardingDynamicLinkerExporter.disable();
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:DynamicLinkerFactoryTest.java

示例3: getCurrentLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
private static Lookup getCurrentLookup() {
    final LinkRequest currentRequest = AccessController.doPrivileged(new PrivilegedAction<LinkRequest>() {
        @Override
        public LinkRequest run() {
            return LinkerServicesImpl.getCurrentLinkRequest();
        }
    });
    return currentRequest == null ? MethodHandles.publicLookup() : currentRequest.getCallSiteDescriptor().getLookup();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:NashornLinker.java

示例4: callMethodHandle

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
void callMethodHandle() {
    MethodHandles.Lookup lookup = MethodHandles.publicLookup();
    try {
        MethodHandle mh = lookup.findStatic(GetCallerClassTest.class,
                                            "staticGetCallerClass",
                                            methodType);
        mh.invokeExact(walker, ReflectionTest.class, expectUOE);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:GetCallerClassTest.java

示例5: callMethodHandleRefl

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
void callMethodHandleRefl() {
    MethodHandles.Lookup lookup = MethodHandles.publicLookup();
    try {
        MethodHandle mh = lookup.findStatic(GetCallerClassTest.class,
                                            "reflectiveGetCallerClass",
                                            methodType);
        mh.invokeExact(walker, ReflectionTest.class, expectUOE);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:GetCallerClassTest.java

示例6: testPublicLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
/**
 * Test dropLookupMode on the public Lookup.
 */
public void testPublicLookup() {
    final Lookup publicLookup = MethodHandles.publicLookup();
    final Class<?> lc = publicLookup.lookupClass();
    assertTrue(publicLookup.lookupModes() == (PUBLIC|UNCONDITIONAL));

    Lookup lookup = publicLookup.dropLookupMode(PRIVATE);
    assertTrue(lookup.lookupClass() == lc);
    assertTrue(lookup.lookupModes() == PUBLIC);

    lookup = publicLookup.dropLookupMode(PROTECTED);
    assertTrue(lookup.lookupClass() == lc);
    assertTrue(lookup.lookupModes() == PUBLIC);

    lookup = publicLookup.dropLookupMode(PACKAGE);
    assertTrue(lookup.lookupClass() == lc);
    assertTrue(lookup.lookupModes() == PUBLIC);

    lookup = publicLookup.dropLookupMode(MODULE);
    assertTrue(lookup.lookupClass() == lc);
    assertTrue(lookup.lookupModes() == PUBLIC);

    lookup = publicLookup.dropLookupMode(PUBLIC);
    assertTrue(lookup.lookupClass() == lc);
    assertTrue(lookup.lookupModes() == 0);

    lookup = publicLookup.dropLookupMode(UNCONDITIONAL);
    assertTrue(lookup.lookupClass() == lc);
    assertTrue(lookup.lookupModes() == PUBLIC);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:DropLookupModeTest.java

示例7: getLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
/**
 * Returns the lookup secured by this {@code SecureLookupSupplier}.
 * @return the lookup secured by this {@code SecureLookupSupplier}.
 * @throws SecurityException if the secured lookup isn't the
 * {@link MethodHandles#publicLookup()}, and a security manager is present,
 * and a check for {@code RuntimePermission("dynalink.getLookup")} fails.
 */
public final Lookup getLookup() {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null && lookup != MethodHandles.publicLookup()) {
        sm.checkPermission(GET_LOOKUP_PERMISSION);
    }
    return lookup;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:SecureLookupSupplier.java

示例8: getCurrentLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
static Lookup getCurrentLookup() {
    final SecureLookupSupplier lookupSupplier = threadLookupSupplier.get();
    if (lookupSupplier != null) {
        return lookupSupplier.getLookup();
    }
    return MethodHandles.publicLookup();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:LinkerServicesImpl.java

示例9: MethodResolver

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
public MethodResolver() {
    this(MethodHandles.publicLookup());
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:4,代碼來源:MethodResolver.java

示例10: getLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Override
public Lookup getLookup() {
    return MethodHandles.publicLookup();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:5,代碼來源:AbstractCallSiteDescriptor.java

示例11: isPublicLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
private static boolean isPublicLookup(final Lookup lookup) {
    return lookup == MethodHandles.publicLookup();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:4,代碼來源:CallSiteDescriptorFactory.java

示例12: testPublicLookupSameModule

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
@Test(expectedExceptions = {IllegalAccessException.class})
public void testPublicLookupSameModule() throws Exception {
    Lookup caller = MethodHandles.publicLookup();
    Lookup lookup = MethodHandles.privateLookupIn(publicType, caller);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:PrivateLookupInTests.java

示例13: createLinkRequest

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
private static LinkRequest createLinkRequest(final Operation operation, final MethodType methodType, final Object source) {
    return new SimpleLinkRequest(new CallSiteDescriptor(MethodHandles.publicLookup(), operation,
            methodType), false, source);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:NativeObject.java

示例14: getLookup

import java.lang.invoke.MethodHandles; //導入方法依賴的package包/類
private static MethodHandles.Lookup getLookup(final boolean publicLookup) {
    return publicLookup? MethodHandles.publicLookup() : MY_LOOKUP;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:LookupTest.java


注:本文中的java.lang.invoke.MethodHandles.publicLookup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。