Class ReflectionUtils

java.lang.Object
panda.utilities.ReflectionUtils

public final class ReflectionUtils extends Object
  • Method Details

    • getByModifier

      public static <E extends Executable> Collection<E> getByModifier(E[] executables, int modifier)
      Get executables with the specified modifier
      Type Parameters:
      E - type of executable
      Parameters:
      executables - array of executables to search in
      modifier - the modifier to search for
      Returns:
      collection of matched executables
    • getMethod

      public static panda.std.Option<Method> getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
      Get method wrapped into optional instead of exception if method does not exist. Comparing to Class.getMethod(String, Class[]) it also checks non-public methods.
      Parameters:
      clazz - the class to search in
      methodName - name of method
      parameterTypes - parameter types of method
      Returns:
      the result method wrapped into optional
    • getMethods

      public static List<Method> getMethods(Class<?> clazz, String methodName)
      Collect all methods with the same name
      Parameters:
      clazz - class to search
      methodName - name to search for
      Returns:
      the list of the matching methods
    • getMethodsAnnotatedWith

      public static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation)
      Collect methods annotated with the specified annotation
      Parameters:
      clazz - class to search
      annotation - annotation to search for
      Returns:
      the set of annotated methods
    • getStaticFieldValues

      public static <T> Collection<T> getStaticFieldValues(Class<?> clazz, Class<T> type)
      Collect values of static fields with the specified type
      Type Parameters:
      T - value type
      Parameters:
      clazz - class to search in
      type - type of field
      Returns:
      collection of collected values
    • getFieldValues

      public static <R, T> Collection<R> getFieldValues(Class<T> clazz, Class<R> type, @Nullable T instance)
      Collect values of static fields with the specified type
      Type Parameters:
      R - type of values
      T - type of instance
      Parameters:
      clazz - class to search in
      type - type of fields
      instance - instance
      Returns:
      collection of collected values