Package org.apache.maven.surefire.util
Class ReflectionUtils
java.lang.Object
org.apache.maven.surefire.util.ReflectionUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ConstructorgetConstructor(Class<?> clazz, Class<?>... arguments) static Methodstatic Methodstatic <T> Tinstantiate(ClassLoader classLoader, String classname, Class<T> returnType) static ObjectinstantiateObject(String className, Class[] types, Object[] params, ClassLoader classLoader) static ObjectinstantiateOneArg(ClassLoader classLoader, String className, Class<?> param1Class, Object param1) static ObjectinstantiateTwoArgs(ClassLoader classLoader, String className, Class<?> param1Class, Object param1, Class param2Class, Object param2) static ObjectinvokeGetter(Class<?> instanceType, Object instance, String methodName) static ObjectinvokeGetter(Object instance, String methodName) static ObjectinvokeMethodChain(Class<?>[] classesChain, String[] noArgMethodNames, Object fallback) Method chain invoker.static ObjectinvokeMethodWithArray(Object target, Method method, Object... args) static ObjectinvokeMethodWithArray2(Object target, Method method, Object... args) static ObjectinvokeSetter(Object target, Method method, Object value) static voidinvokeSetter(Object o, String name, Class<?> value1clazz, Object value) static ObjectinvokeStaticMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes, Object[] parameters) Invoker of public static no-argument method.static Class<?>loadClass(ClassLoader classLoader, String className) static ObjectnewInstance(Constructor constructor, Object... params) static Class<?>reloadClass(ClassLoader classLoader, Object source) static MethodtryGetMethod(Class<?> clazz, String methodName, Class<?>... parameters) static Class<?>tryLoadClass(ClassLoader classLoader, String className)
-
Field Details
-
EMPTY_CLASS_ARRAY
-
EMPTY_OBJECT_ARRAY
-
-
Constructor Details
-
ReflectionUtils
private ReflectionUtils()
-
-
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
-
reloadClass
public static Class<?> reloadClass(ClassLoader classLoader, Object source) throws ReflectiveOperationException - Throws:
ReflectiveOperationException
-
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-argumentmethodNameis 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;
fallbackotherwise - Throws:
IllegalArgumentException- ifclassesandnoArgMethodNameshave different array length
-