Package org.citrusframework.util
Class ReflectionHelper
java.lang.Object
org.citrusframework.util.ReflectionHelper
Helper for working with reflection on classes.
This code is based on org.apache.camel.util.ReflectionHelper class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAction to take on each class.static interfaceCallback interface invoked on each field in the hierarchy.static interfaceAction to take on each method. -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddoWithClasses(Class<?> clazz, ReflectionHelper.ClassCallback cc) Perform the given callback operation on the nested (inner) classes.static voiddoWithFields(Class<?> clazz, ReflectionHelper.FieldCallback fc) Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.static voiddoWithMethods(Class<?> clazz, ReflectionHelper.MethodCallback mc) Perform the given callback operation on all matching methods of the given class and superclasses (or given interface and super-interfaces).static Fieldstatic MethodfindMethod(Class<?> clazz, String name, Class<?>... paramTypes) Attempt to find aMethodon the supplied class with the supplied name and parameter types.static Objectstatic ObjectinvokeMethod(Method method, Object target, Object... args) Invoke the specifiedMethodagainst the supplied target object with the supplied arguments.static void
-
Method Details
-
doWithClasses
public static void doWithClasses(Class<?> clazz, ReflectionHelper.ClassCallback cc) throws IllegalArgumentException Perform the given callback operation on the nested (inner) classes.- Parameters:
clazz- class to start looking atcc- the callback to invoke for each inner class (excluding the class itself)- Throws:
IllegalArgumentException
-
doWithFields
public static void doWithFields(Class<?> clazz, ReflectionHelper.FieldCallback fc) throws IllegalArgumentException Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.- Parameters:
clazz- the target class to analyzefc- the callback to invoke for each field- Throws:
IllegalArgumentException
-
doWithMethods
public static void doWithMethods(Class<?> clazz, ReflectionHelper.MethodCallback mc) throws IllegalArgumentException Perform the given callback operation on all matching methods of the given class and superclasses (or given interface and super-interfaces). Important: This method does not take thebridge methodsinto account.- Parameters:
clazz- class to start looking atmc- the callback to invoke for each method- Throws:
IllegalArgumentException
-
findField
Attempt to find afieldon the suppliedClasswith the suppliednameand/ortype. Searches all superclasses up toObject.- Parameters:
clazz- the class to introspectname- the name of the field (may benullif type is specified)- Returns:
- the corresponding Field object, or
nullif not found
-
findMethod
Attempt to find aMethodon the supplied class with the supplied name and parameter types. Searches all superclasses up toObject.Returns
nullif noMethodcan be found.- Parameters:
clazz- the class to introspectname- the name of the methodparamTypes- the parameter types of the method (may benullto indicate any signature)- Returns:
- the Method object, or
nullif none found
-
invokeMethod
Invoke the specifiedMethodagainst the supplied target object with the supplied arguments. The target object can benullwhen invoking a staticMethod.- Parameters:
method- the method to invoketarget- the target object to invoke the method onargs- the invocation arguments (maybenull)- Returns:
- the invocation result, if any
-
setField
-
getField
-