Package org.apache.maven.surefire.util
Class ReflectionUtils
java.lang.Object
org.apache.maven.surefire.util.ReflectionUtils
- Author:
- Kristian Rosenvold
-
Method Summary
Modifier and TypeMethodDescriptionstatic Constructor
getConstructor
(Class<?> clazz, Class<?>... arguments) static Method
static Method
static <T> T
instantiate
(ClassLoader classLoader, String classname, Class<T> returnType) static Object
instantiateObject
(String className, Class[] types, Object[] params, ClassLoader classLoader) static Object
instantiateOneArg
(ClassLoader classLoader, String className, Class<?> param1Class, Object param1) static Object
instantiateTwoArgs
(ClassLoader classLoader, String className, Class<?> param1Class, Object param1, Class param2Class, Object param2) static Object
invokeGetter
(Class<?> instanceType, Object instance, String methodName) static Object
invokeGetter
(Object instance, String methodName) static Object
invokeMethodChain
(Class<?>[] classesChain, String[] noArgMethodNames, Object fallback) Method chain invoker.static Object
invokeMethodWithArray
(Object target, Method method, Object... args) static Object
invokeMethodWithArray2
(Object target, Method method, Object... args) static Object
invokeSetter
(Object target, Method method, Object value) static void
invokeSetter
(Object o, String name, Class<?> value1clazz, Object value) static Object
invokeStaticMethod
(Class<?> clazz, String methodName, Class<?>[] parameterTypes, Object[] parameters) Invoker of public static no-argument method.static Class
<?> loadClass
(ClassLoader classLoader, String className) static Object
newInstance
(Constructor constructor, Object... params) static Method
tryGetMethod
(Class<?> clazz, String methodName, Class<?>... parameters) static Class
<?> tryLoadClass
(ClassLoader classLoader, String className)
-
Method Details
-
getMethod
-
getMethod
-
tryGetMethod
-
invokeGetter
-
invokeGetter
-
getConstructor
-
newInstance
-
instantiate
-
instantiateOneArg
public static Object instantiateOneArg(ClassLoader classLoader, String className, Class<?> param1Class, Object param1) -
instantiateTwoArgs
-
invokeSetter
-
invokeSetter
-
invokeMethodWithArray
-
invokeMethodWithArray2
public static Object invokeMethodWithArray2(Object target, Method method, Object... args) throws InvocationTargetException - Throws:
InvocationTargetException
-
instantiateObject
public static Object instantiateObject(String className, Class[] types, Object[] params, ClassLoader classLoader) -
tryLoadClass
-
loadClass
-
invokeStaticMethod
public static Object invokeStaticMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes, Object[] parameters) Invoker of public static no-argument method.- Parameters:
clazz
- class on which public static no-argumentmethodName
is invokedmethodName
- public static no-argument method to be calledparameterTypes
- method parameter typesparameters
- method parameters- Returns:
- value returned by
methodName
- Throws:
RuntimeException
- if no such method foundSurefireReflectionException
- if the method could not be called or threw an exception. It has original cause Exception.
-
invokeMethodChain
public static Object invokeMethodChain(Class<?>[] classesChain, String[] noArgMethodNames, Object fallback) Method chain invoker.- Parameters:
classesChain
- classes to invoke on method chainnoArgMethodNames
- chain of public methods to callfallback
- returned value if a chain could not be invoked due to an error- Returns:
- successfully returned value from the last method call;
fallback
otherwise - Throws:
IllegalArgumentException
- ifclasses
andnoArgMethodNames
have different array length
-