Class ReflectionUtil
java.lang.Object
org.zeroturnaround.javarebel.integration.util.ReflectionUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 a declared method with no parametersstatic <T> TInvoke a declared method with one parameter.static <T> TInvoke a declared method with two parameters.static <T> TInvoke a declared method with three parameters.static ObjectinvokeByArgs(Object target, String methodName, Object... args) static ObjectinvokeStaticByArgs(Class<?> klass, String methodName, Object... args) static voidstatic 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)
-
Constructor Details
-
ReflectionUtil
public ReflectionUtil()
-
-
Method Details
-
invoke
public static <T> T invoke(Object target, String methodName, Object param1, Object param2, Object param3) Invoke a declared method with three parameters. -
invoke
Invoke a declared method with two parameters. -
invoke
Invoke a declared method with one parameter. -
invoke
Invoke a declared method with no parameters -
invokeByArgs
-
invokeStaticByArgs
-
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
-
getFieldValue
-
getFieldValue
-
setFieldValue
-
setFieldValueOrFail
public static void setFieldValueOrFail(Object instance, String field, Object value) throws Exception - Throws:
Exception
-
setFieldValue
-
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
-
getDeclaredField
-
getDeclaredMethod
-
getDeclaredConstructor
-
getClassForAnyName
-
copyDeclaredFields
-