本文整理匯總了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;
}