Class ReflectionUtil

java.lang.Object
org.zeroturnaround.javarebel.integration.util.ReflectionUtil

public class ReflectionUtil extends Object
  • 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

      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
    • invokeByArgs

      public static Object invokeByArgs(Object target, String methodName, Object... args)
    • 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
    • getFieldValue

      public static <T> T getFieldValue(Object o, String field)
    • getFieldValue

      public static <T> T getFieldValue(Class<?> orig, String field)
    • setFieldValue

      public static void setFieldValue(Object instance, String field, Object value)
    • 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 instance
      klass - 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 instead
      field - the field name
      value - the new value of the field
      Throws:
      Exception - if field not set
    • setAccessible

      public static void setAccessible(AccessibleObject m)
    • getDeclaredField

      public static Field getDeclaredField(Class<?> klass, String name)
    • 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)
    • copyDeclaredFields

      public static void copyDeclaredFields(Class<?> klass, Object src, Object dest)