当前位置: 首页>>代码示例>>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;未经允许,请勿转载。