Class ReflectionHelper

java.lang.Object
org.apache.camel.tooling.util.ReflectionHelper

public final class ReflectionHelper extends Object
Helper for working with reflection on classes.

This code is a copy of org.apache.camel.util.ReflectionHelper to avoid cyclic dependencies between artifacts and camel maven plugins. This code is based on org.apache.camel.spring.util.ReflectionUtils class.

  • Method Details

    • doWithClasses

      public static void doWithClasses(Class<?> clazz, ReflectionHelper.ClassCallback cc) throws IllegalArgumentException
      Perform the given callback operation on the nested (inner) classes.
      Parameters:
      clazz - class to start looking at
      cc - the callback to invoke for each inner class (excluding the class itself)
      Throws:
      IllegalArgumentException
    • doWithFields

      public static void doWithFields(Class<?> clazz, ReflectionHelper.FieldCallback fc) throws IllegalArgumentException
      Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.
      Parameters:
      clazz - the target class to analyze
      fc - the callback to invoke for each field
      Throws:
      IllegalArgumentException
    • doWithMethods

      public static void doWithMethods(Class<?> clazz, ReflectionHelper.MethodCallback mc) throws IllegalArgumentException
      Perform the given callback operation on all matching methods of the given class and superclasses (or given interface and super-interfaces).

      Important: This method does not take the bridge methods into account.

      Parameters:
      clazz - class to start looking at
      mc - the callback to invoke for each method
      Throws:
      IllegalArgumentException
    • findMethod

      public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes)
      Attempt to find a Method on the supplied class with the supplied name and parameter types. Searches all superclasses up to Object.

      Returns null if no Method can be found.

      Parameters:
      clazz - the class to introspect
      name - the name of the method
      paramTypes - the parameter types of the method (maybe null to indicate any signature)
      Returns:
      the Method object, or null if none found
    • findField

      public static Field findField(Class<?> clazz, String name)
      Attempt to find a Field on the supplied class with the supplied name. Searches all superclasses up to Object.

      Returns null if no Method can be found.

      Parameters:
      clazz - the class to introspect
      name - the name of the field
      Returns:
      the field object, or null if none found
    • setField

      public static void setField(Field f, Object instance, Object value)
    • getField

      public static Object getField(Field f, Object instance)