net.lenni0451.lambdaevents.handler.methodhandle.VirtualMethodHandleHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of LambdaEvents Show documentation
Show all versions of LambdaEvents Show documentation
Fast and modular event library for Java
The newest version!
package net.lenni0451.lambdaevents.handler.methodhandle;
import lombok.SneakyThrows;
import net.lenni0451.lambdaevents.AHandler;
import net.lenni0451.lambdaevents.EventHandler;
import net.lenni0451.lambdaevents.utils.EventUtils;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
/**
* The {@link AHandler} implementation which calls the handler method using method handles.
* Only for use if the method has no parameters.
*/
public class VirtualMethodHandleHandler extends AHandler {
private final MethodHandle methodHandle;
/**
* @param owner The owner of the handler method
* @param instance The instance of the handler owner
* @param annotation The {@link EventHandler} annotation of the handler method
* @param methodHandle The handler method handle
*/
public VirtualMethodHandleHandler(Class> owner, @Nullable Object instance, EventHandler annotation, final MethodHandle methodHandle) {
super(owner, instance, annotation);
this.methodHandle = methodHandle;
}
@Override
@SneakyThrows
public void call(Object event) {
this.methodHandle.invokeExact();
}
@Override
public String toString() {
return "virtualMethodHandle: " + this.owner.getName() + " -> " + EventUtils.toString(this.methodHandle);
}
}