panda.lang.reflect.MethodInjector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.lang.reflect;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import panda.lang.Exceptions;
import panda.lang.Injector;
import panda.lang.Objects;
public class MethodInjector implements Injector {
private Method method;
/**
* @param method the method
*/
public MethodInjector(Method method) {
this.method = method;
if (!method.isAccessible()) {
method.setAccessible(true);
}
}
@Override
public Type type(Object obj) {
return Methods.getParameterType(method, 0);
}
@Override
public void inject(Object obj, Object value) {
try {
method.invoke(obj, value);
}
catch (Exception e) {
throw Exceptions.wrapThrow(e);
}
}
@Override
public String toString() {
return Objects.toStringBuilder()
.append("method", method)
.toString();
}
}