java.lang.Object
org.fuin.ddd4j.ddd.MethodExecutor
Lightweight utility class to execute a method using reflection.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal MethodfindDeclaredAnnotatedMethod(@NotNull Object obj, @NotNull Class<? extends Annotation> annotationType, Class<?>... expectedArgumentTypes) Finds a declared method on the instance or it's parents that has an annotation and optional parameters.getDeclaredMethodsIncludingSuperClasses(@NotNull Class<?> clasz, @NotNull Class<?>... stopParents) Returns a list of declared methods from classes and super classes.final <T> TInvokes a method with any number of arguments.final <T> TinvokeDeclaredAnnotatedMethod(@NotNull Object obj, @NotNull Class<? extends Annotation> annotationType, Class<?>[] argumentTypes, Object[] arguments) Finds a declared method that has an annotation and optional parameters.final booleanVerifies if both arrays have the same length and types.
-
Constructor Details
-
MethodExecutor
public MethodExecutor()
-
-
Method Details
-
invokeDeclaredAnnotatedMethod
public final <T> T invokeDeclaredAnnotatedMethod(@NotNull @NotNull Object obj, @NotNull @NotNull Class<? extends Annotation> annotationType, Class<?>[] argumentTypes, Object[] arguments) Finds a declared method that has an annotation and optional parameters.- Type Parameters:
T- Type of the return value.- Parameters:
obj- Object to inspect.annotationType- Expected annotation type.argumentTypes- Expected argument types, empty array ornull.arguments- Arguments, empty array ornull. Must be the same size as 'argumentTypes'.- Returns:
- Value returned by the method or
null.
-
findDeclaredAnnotatedMethod
public final Method findDeclaredAnnotatedMethod(@NotNull @NotNull Object obj, @NotNull @NotNull Class<? extends Annotation> annotationType, Class<?>... expectedArgumentTypes) Finds a declared method on the instance or it's parents that has an annotation and optional parameters. The class- Parameters:
obj- Object to inspect.annotationType- Expected annotation type.expectedArgumentTypes- Expected argument types, empty array ornull.- Returns:
- Method or
nullif any of the expected parameters does not match.
-
getDeclaredMethodsIncludingSuperClasses
public final List<Method> getDeclaredMethodsIncludingSuperClasses(@NotNull @NotNull Class<?> clasz, @NotNull @NotNull Class<?>... stopParents) Returns a list of declared methods from classes and super classes. The given stop classes will not be inspected.- Parameters:
clasz- Class to inspect.stopParents- Parent classes to stop inspection or null to stop atObject.- Returns:
- List of methods.
-
invoke
public final <T> T invoke(@NotNull @NotNull Method method, @NotNull @NotNull Object target, Object... args) Invokes a method with any number of arguments.- Type Parameters:
T- Type of the return value.- Parameters:
method- Method to call.target- Object that contains the method.args- Arguments, empty array ornull.- Returns:
- Value returned by the method or
null.
-
same
Verifies if both arrays have the same length and types.- Parameters:
expected- Expected types, empty array ornull.actual- Actual types, empty array ornull.- Returns:
- TRUE if both arguments match.
-