Class ReflectionUtils
- java.lang.Object
-
- org.apache.maven.surefire.api.util.ReflectionUtils
-
public final class ReflectionUtils extends java.lang.Object
- Author:
- Kristian Rosenvold
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.reflect.Constructor<?>
getConstructor(java.lang.Class<?> clazz, java.lang.Class<?>... arguments)
static java.lang.reflect.Method
getMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameters)
static java.lang.reflect.Method
getMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Class<?>... parameters)
static <T> T
instantiate(java.lang.ClassLoader classLoader, java.lang.String classname, java.lang.Class<T> returnType)
static <T> T
instantiateObject(java.lang.String className, java.lang.Class<?>[] types, java.lang.Object[] params, java.lang.ClassLoader cl)
static <T> T
instantiateOneArg(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.Class<?> param1Class, java.lang.Object param1)
static <T> T
invokeGetter(java.lang.Class<?> instanceType, java.lang.Object instance, java.lang.String methodName)
static <T> T
invokeGetter(java.lang.Object instance, java.lang.String methodName)
static <T> T
invokeMethodChain(java.lang.Class<?>[] classesChain, java.lang.String[] noArgMethodNames, java.lang.Object fallback)
Method chain invoker.static <T> T
invokeMethodWithArray(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object... args)
static <T> T
invokeMethodWithArray2(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object... args)
static <T> T
invokeSetter(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object value)
static void
invokeSetter(java.lang.Object o, java.lang.String name, java.lang.Class<?> value1clazz, java.lang.Object value)
static <T> T
invokeStaticMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameters)
Invoker of public static no-argument method.static java.lang.Class<?>
loadClass(java.lang.ClassLoader classLoader, java.lang.String className)
static <T> T
newInstance(java.lang.reflect.Constructor<?> constructor, java.lang.Object... params)
static java.lang.Class<?>
reloadClass(java.lang.ClassLoader classLoader, java.lang.Object source)
static <T> java.lang.reflect.Constructor<T>
tryGetConstructor(java.lang.Class<T> clazz, java.lang.Class<?>... arguments)
static java.lang.reflect.Method
tryGetMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameters)
static java.lang.Class<?>
tryLoadClass(java.lang.ClassLoader classLoader, java.lang.String className)
-
-
-
Method Detail
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.Object instance, java.lang.String methodName, java.lang.Class<?>... parameters)
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameters)
-
tryGetMethod
public static java.lang.reflect.Method tryGetMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... parameters)
-
invokeGetter
public static <T> T invokeGetter(java.lang.Object instance, java.lang.String methodName)
-
invokeGetter
public static <T> T invokeGetter(java.lang.Class<?> instanceType, java.lang.Object instance, java.lang.String methodName)
-
getConstructor
public static java.lang.reflect.Constructor<?> getConstructor(java.lang.Class<?> clazz, java.lang.Class<?>... arguments)
-
tryGetConstructor
public static <T> java.lang.reflect.Constructor<T> tryGetConstructor(java.lang.Class<T> clazz, java.lang.Class<?>... arguments)
-
newInstance
public static <T> T newInstance(java.lang.reflect.Constructor<?> constructor, java.lang.Object... params)
-
instantiate
public static <T> T instantiate(java.lang.ClassLoader classLoader, java.lang.String classname, java.lang.Class<T> returnType)
-
instantiateOneArg
public static <T> T instantiateOneArg(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.Class<?> param1Class, java.lang.Object param1)
-
invokeSetter
public static void invokeSetter(java.lang.Object o, java.lang.String name, java.lang.Class<?> value1clazz, java.lang.Object value)
-
invokeSetter
public static <T> T invokeSetter(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object value)
-
invokeMethodWithArray
public static <T> T invokeMethodWithArray(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object... args)
-
invokeMethodWithArray2
public static <T> T invokeMethodWithArray2(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object... args) throws java.lang.reflect.InvocationTargetException
- Throws:
java.lang.reflect.InvocationTargetException
-
instantiateObject
public static <T> T instantiateObject(java.lang.String className, java.lang.Class<?>[] types, java.lang.Object[] params, java.lang.ClassLoader cl)
-
tryLoadClass
public static java.lang.Class<?> tryLoadClass(java.lang.ClassLoader classLoader, java.lang.String className)
-
loadClass
public static java.lang.Class<?> loadClass(java.lang.ClassLoader classLoader, java.lang.String className)
-
reloadClass
public static java.lang.Class<?> reloadClass(java.lang.ClassLoader classLoader, java.lang.Object source) throws java.lang.ReflectiveOperationException
- Throws:
java.lang.ReflectiveOperationException
-
invokeStaticMethod
public static <T> T invokeStaticMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.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:
java.lang.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 <T> T invokeMethodChain(java.lang.Class<?>[] classesChain, java.lang.String[] noArgMethodNames, java.lang.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:
java.lang.IllegalArgumentException
- ifclasses
andnoArgMethodNames
have different array length
-
-