com.mercateo.reflection.Call Maven / Gradle / Ivy
package com.mercateo.reflection;
import java.lang.reflect.Method;
import java.util.function.Consumer;
import com.mercateo.reflection.proxy.ProxyFactory;
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);
invocation.accept(proxy);
// noinspection unchecked
return ((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;
}
}