Package pi.util

Class ReflectionUtil

java.lang.Object
pi.util.ReflectionUtil

public final class ReflectionUtil extends Object
  • Method Details

    • getField

      public static <T> Field getField(Class<T> cls, String fieldName)
    • getField

      public static <T> Field getField(Class<T> cls, String fieldName, boolean recursive)
    • getStaticValue

      public static <V> V getStaticValue(Class<?> cls, String fieldName)
    • getAllFields

      public static List<Field> getAllFields(List<Field> fields, Class<?> type)
      Recursively gets all fields of the specified type, respecting parent classes.
      Parameters:
      fields - The list containing all fields.
      type - The type to retrieve the fields from.
      Returns:
      All fields of the specified type, including the fields of the parent classes.
    • getMethod

      public static Method getMethod(String name, Class<?> type, Class<?>... parameterTypes)
      Recursively gets a method by the specified name respecting the parent classes and the parameters of the declaration.
      Parameters:
      name - The name of the method.
      type - The type on which to search for the method.
      parameterTypes - The types of the parameters defined by the method declaration.
      Returns:
      The found method or null if no such method exists.
    • setValue

      public static <T, C> boolean setValue(Class<C> cls, Object instance, String fieldName, T value)
    • setEnumPropertyValue

      public static <T> boolean setEnumPropertyValue(Class<T> cls, Object instance, Field field, String propertyName, String value)
    • getSetter

      public static <T> Method getSetter(Class<T> cls, String fieldName)
    • getSetters

      public static <T> Collection<Method> getSetters(Class<T> cls)
    • isWrapperType

      public static <T, C> boolean isWrapperType(Class<T> primitive, Class<C> potentialWrapper)
    • setFieldValue

      public static <T> boolean setFieldValue(Class<T> cls, Object instance, String fieldName, String value)
    • getMethodsAnnotatedWith

      public static List<Method> getMethodsAnnotatedWith(Class<?> type, Class<? extends Annotation> annotation)
    • getEvents

      public static Collection<Method> getEvents(Class<?> type)
      Gets the events for the specified type.

      This will search for all methods that have a parameter of type EventListener and match the LITIENGINE's naming conventions for event subscription (i.e. the method name starts with one of the prefixes "add" or "on".

      Parameters:
      type - The type to inspect the events on.
      Returns:
      All methods on the specified type that are considered to be events.
      See Also:
    • getDefaultValue

      public static <T> T getDefaultValue(Class<T> clazz)