Class ReflectionUtil
- java.lang.Object
-
- org.zeroturnaround.javarebel.integration.util.ReflectionUtil
-
public class ReflectionUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyDeclaredFields(Class<?> klass, Object src, Object dest)static MethodfindDeclaredMethod(Class<?> klass, String methodName, Object... args)Find the single declared method in the class hierarchy that matches the name and parameters.static Class<?>getClassForAnyName(ClassLoader loader, String... names)static Constructor<?>getDeclaredConstructor(Class<?> klass, Class<?>... paramTypes)static FieldgetDeclaredField(Class<?> klass, String name)static MethodgetDeclaredMethod(Class<?> klass, String method, Class<?>... paramTypes)static <T> TgetFieldValue(Class<?> orig, String field)static <T> TgetFieldValue(Object o, String field)static <T> Tinvoke(Object target, String methodName)Invoke a declared method with no parametersstatic <T> Tinvoke(Object target, String methodName, Object param1)Invoke a declared method with one parameter.static <T> Tinvoke(Object target, String methodName, Object param1, Object param2)Invoke a declared method with two parameters.static <T> Tinvoke(Object target, String methodName, Object param1, Object param2, Object param3)Invoke a declared method with three parameters.static ObjectinvokeByArgs(Object target, String methodName, Object... args)static ObjectinvokeStaticByArgs(Class<?> klass, String methodName, Object... args)static voidsetAccessible(AccessibleObject m)static voidsetFieldValue(Object instance, Class<?> klass, String field, Object value)static voidsetFieldValue(Object instance, String field, Object value)static voidsetFieldValueOrFail(Object instance, Class<?> klass, String field, Object value)static voidsetFieldValueOrFail(Object instance, String field, Object value)
-
-
-
Method Detail
-
invoke
public static <T> T invoke(Object target, String methodName, Object param1, Object param2, Object param3)
Invoke a declared method with three parameters.
-
invoke
public static <T> T invoke(Object target, String methodName, Object param1, Object param2)
Invoke a declared method with two parameters.
-
invoke
public static <T> T invoke(Object target, String methodName, Object param1)
Invoke a declared method with one parameter.
-
invoke
public static <T> T invoke(Object target, String methodName)
Invoke a declared method with no parameters
-
invokeStaticByArgs
public static Object invokeStaticByArgs(Class<?> klass, String methodName, Object... args)
-
findDeclaredMethod
public static Method findDeclaredMethod(Class<?> klass, String methodName, Object... args) throws NoSuchMethodException
Find the single declared method in the class hierarchy that matches the name and parameters.- Throws:
NoSuchMethodException
-
setFieldValueOrFail
public static void setFieldValueOrFail(Object instance, String field, Object value) throws Exception
- Throws:
Exception
-
setFieldValue
public static void setFieldValue(Object instance, Class<?> klass, String field, Object value)
-
setFieldValueOrFail
public static void setFieldValueOrFail(Object instance, Class<?> klass, String field, Object value) throws Exception
- Parameters:
instance- the instanceklass- lowest class in hierarchy to look into, restriction is needed when otherwise you might detect the same field name from unknown subclasses and change this insteadfield- the field namevalue- the new value of the field- Throws:
Exception- if field not set
-
setAccessible
public static void setAccessible(AccessibleObject m)
-
getDeclaredMethod
public static Method getDeclaredMethod(Class<?> klass, String method, Class<?>... paramTypes)
-
getDeclaredConstructor
public static Constructor<?> getDeclaredConstructor(Class<?> klass, Class<?>... paramTypes)
-
getClassForAnyName
public static Class<?> getClassForAnyName(ClassLoader loader, String... names)
-
-