r01f.reflection.fluent
Class MethodInvoker<T>
java.lang.Object
r01f.reflection.fluent.MethodInvoker<T>
- Type Parameters:
T - the return type of the method invocation.
Usage example:
// Equivalent to call 'person.setName("Luke")'
Reflection.method("setName").withParameterTypes(String.class).in(person).invoke("Luke");
// Equivalent to call 'person.concentrate()'
Reflection.method("concentrate").in(person).invoke();
// Equivalent to call 'person.getName()'
String name = Reflection.method("getName").withReturnType(String.class).in(person).invoke();
public final class MethodInvoker<T>
- extends java.lang.Object
Method invocation using reflection
|
Field Summary |
private java.lang.reflect.Method |
_method
|
private java.lang.Object |
_targetObj
|
|
Constructor Summary |
private |
MethodInvoker(java.lang.Object target,
java.lang.reflect.Method method)
|
|
Method Summary |
private ReflectionException |
_cannotInvokeMethod(java.lang.Throwable cause,
java.lang.Object... args)
|
private static
|
_createInvoker(java.lang.String methodName,
java.lang.Object target,
java.lang.Class<?>... parameterTypes)
|
private static java.lang.reflect.Method |
_findMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes)
|
private static java.lang.reflect.Method |
_lookupInClassHierarchy(java.lang.String methodName,
java.lang.Class<?> targetType,
java.lang.Class<?>[] parameterTypes)
|
java.lang.reflect.Method |
getMethod()
Returns the "real" method managed by this class. |
T |
invoke(java.lang.Object... args)
Invokes the method managed by this class using the given arguments. |
(package private) static
|
newInvoker(java.lang.String methodName,
java.lang.Object target,
java.lang.Class<?>... parameterTypes)
|
private static java.lang.Class<?> |
typeOf(java.lang.Object target)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_targetObj
private final java.lang.Object _targetObj
_method
private final java.lang.reflect.Method _method
MethodInvoker
private MethodInvoker(java.lang.Object target,
java.lang.reflect.Method method)
newInvoker
static <T> MethodInvoker<T> newInvoker(java.lang.String methodName,
java.lang.Object target,
java.lang.Class<?>... parameterTypes)
invoke
public T invoke(java.lang.Object... args)
- Invokes the method managed by this class using the given arguments.
- Parameters:
args - the arguments to use to call the method managed by this class.
- Returns:
- the result of the method call.
- Throws:
ReflectionError - if the method cannot be invoked.
getMethod
public java.lang.reflect.Method getMethod()
- Returns the "real" method managed by this class.
- Returns:
- the "real" method managed by this class.
_createInvoker
private static <T> MethodInvoker<T> _createInvoker(java.lang.String methodName,
java.lang.Object target,
java.lang.Class<?>... parameterTypes)
typeOf
private static java.lang.Class<?> typeOf(java.lang.Object target)
_lookupInClassHierarchy
private static java.lang.reflect.Method _lookupInClassHierarchy(java.lang.String methodName,
java.lang.Class<?> targetType,
java.lang.Class<?>[] parameterTypes)
_findMethod
private static java.lang.reflect.Method _findMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes)
_cannotInvokeMethod
private ReflectionException _cannotInvokeMethod(java.lang.Throwable cause,
java.lang.Object... args)