本文整理汇总了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);
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
示例9: MethodResolver
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
public MethodResolver() {
this(MethodHandles.publicLookup());
}
示例10: getLookup
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Override
public Lookup getLookup() {
return MethodHandles.publicLookup();
}
示例11: isPublicLookup
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
private static boolean isPublicLookup(final Lookup lookup) {
return lookup == MethodHandles.publicLookup();
}
示例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);
}
示例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);
}
示例14: getLookup
import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
private static MethodHandles.Lookup getLookup(final boolean publicLookup) {
return publicLookup? MethodHandles.publicLookup() : MY_LOOKUP;
}