net.fushizen.invokedynamic.proxy.DefaultInvocationHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of invokedynamic-proxy Show documentation
Show all versions of invokedynamic-proxy Show documentation
A Java runtime proxy class generator using invokedynamic for better performance and more capabilities
than the standard Java proxies.
package net.fushizen.invokedynamic.proxy;
import java.lang.invoke.*;
class DefaultInvocationHandler implements DynamicInvocationHandler {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final MethodHandle THROW_UNSUPPORTED;
static {
try {
THROW_UNSUPPORTED = LOOKUP.findStatic(DefaultInvocationHandler.class,
"throwUnsupported",
MethodType.methodType(Object.class));
} catch (Exception e) {
throw new Error(e);
}
}
private static Object throwUnsupported() {
throw new UnsupportedOperationException();
}
@Override
public CallSite handleInvocation(
MethodHandles.Lookup proxyLookup,
String methodName,
MethodType methodType,
MethodHandle superMethod
) {
if (superMethod != null) {
return new ConstantCallSite(superMethod.asType(methodType));
}
return new ConstantCallSite(
MethodHandles.dropArguments(THROW_UNSUPPORTED, 0, methodType.parameterList()).asType(methodType)
);
}
}