com.mercateo.reflection.Call Maven / Gradle / Ivy
package com.mercateo.reflection;
import com.mercateo.reflection.proxy.ProxyFactory;
import java.lang.reflect.Method;
import java.util.function.Consumer;
public class Call {
private final Class clazz;
private final Method method;
private final Object[] args;
public Call(Class clazz, Method method, Object[] args) {
this.clazz = clazz;
this.method = method;
this.args = args;
}
public static Call of(Class clazz, Consumer invocation) {
final T proxy = ProxyFactory.createProxy(clazz, new CallInterceptor<>(clazz),
CallInterceptor.InvocationRecorder.class);
invocation.accept((T) proxy);
// noinspection unchecked
return ((CallInterceptor.InvocationRecorder) proxy).getInvocationRecordingResult();
}
public static Method methodOf(Class clazz, Consumer invocation) {
return of(clazz, invocation).method();
}
public Class declaringClass() {
return clazz;
}
public Method method() {
return method;
}
public Object[] args() {
return args;
}
}