use of java.lang.invoke.SwitchPoint in project robolectric by robolectric.
the class ShadowInvalidator method invalidateClasses.
public synchronized void invalidateClasses(Collection<String> classNames) {
if (classNames.isEmpty())
return;
SwitchPoint[] points = new SwitchPoint[classNames.size()];
int i = 0;
for (String className : classNames) {
SwitchPoint switchPoint = switchPoints.put(className, null);
if (switchPoint == null)
switchPoint = DUMMY;
points[i++] = switchPoint;
}
SwitchPoint.invalidateAll(points);
}
use of java.lang.invoke.SwitchPoint in project groovy by apache.
the class ReevaluatingReference method replacePayLoad.
private T replacePayLoad() {
T payload = valueSupplier.get();
MethodHandle ref = MethodHandles.constant(clazzRef.get(), payload);
SwitchPoint sp = validationSupplier.apply(payload);
returnRef = sp.guardWithTest(ref, FALLBACK_HANDLE);
return payload;
}
use of java.lang.invoke.SwitchPoint in project robolectric by robolectric.
the class InvokeDynamicSupport method bindWithFallback.
private static MethodHandle bindWithFallback(MethodHandle mh, RoboCallSite site, MethodHandle fallback) {
SwitchPoint switchPoint = getInvalidator(site.getCaller());
MethodType type = site.type();
MethodHandle boundFallback = foldArguments(exactInvoker(type), fallback.bindTo(site));
mh = switchPoint.guardWithTest(mh.asType(type), boundFallback);
site.setTarget(mh);
return mh;
}
use of java.lang.invoke.SwitchPoint in project robolectric by robolectric.
the class SandboxClassLoaderTest method loadClass.
private Class<?> loadClass(Class<?> clazz) throws ClassNotFoundException {
if (classLoader == null) {
classLoader = new SandboxClassLoader(configureBuilder().build());
}
setStaticField(classLoader.loadClass(InvokeDynamicSupport.class.getName()), "INTERCEPTORS", new Interceptors(Collections.<Interceptor>emptyList()));
setStaticField(classLoader.loadClass(Shadow.class.getName()), "SHADOW_IMPL", newInstance(classLoader.loadClass(ShadowImpl.class.getName())));
ShadowInvalidator invalidator = Mockito.mock(ShadowInvalidator.class);
when(invalidator.getSwitchPoint(any(Class.class))).thenReturn(new SwitchPoint());
String className = RobolectricInternals.class.getName();
Class<?> robolectricInternalsClass = ReflectionHelpers.loadClass(classLoader, className);
ReflectionHelpers.setStaticField(robolectricInternalsClass, "classHandler", classHandler);
ReflectionHelpers.setStaticField(robolectricInternalsClass, "shadowInvalidator", invalidator);
return classLoader.loadClass(clazz.getName());
}
Aggregations