Class Reflection

java.lang.Object
org.fulib.fx.util.reflection.Reflection

public class Reflection extends Object
Utility class containing different helper methods for reflection.
  • Method Details

    • getFieldsWithAnnotation

      public static Stream<Field> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)
      Returns all fields of the given class that are annotated with the given annotation.
      Parameters:
      clazz - The class to get the fields from
      annotation - The annotation to filter the fields by
      Returns:
      A list of fields that are annotated with the given annotation
    • callMethodsForFieldInstances

      public static void callMethodsForFieldInstances(Object instance, Collection<Field> fields, Consumer<Object> method)
      Calls the given method for all fields of the given class that are annotated with the given annotation.
      Parameters:
      instance - The instance to call the methods on
      fields - The fields to call the methods for
      method - The method to call
    • getFieldsOfType

      public static Stream<Field> getFieldsOfType(Class<?> clazz, Class<?> type)
      Returns all fields of the given class that are of the given type.
      Parameters:
      clazz - The class to get the fields from
      type - The type to filter the fields by
      Returns:
      A list of fields that are of the given type
    • getMethodsWithAnnotation

      public static Stream<Method> getMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation)
      Returns all methods of the given class that are annotated with the given annotation.
      Parameters:
      clazz - The class to get the methods from
      annotation - The annotation to filter the methods by
      Returns:
      A list of methods that are annotated with the given annotation
    • canBeAssigned

      public static boolean canBeAssigned(Class<?> type, Object value)
      Checks if the value can be assigned to the given type.
      Parameters:
      type - The type to check
      value - The value to check
      Returns:
      True if the value can be assigned to the type, false otherwise
    • getAllFields

      @NotNull public static @NotNull Set<Field> getAllFields(@NotNull @NotNull Class<?> clazz)
      Returns all fields of the given class and its superclasses.
      Parameters:
      clazz - The class to get the fields from
      Returns:
      A set of all fields of the given class and its superclasses
    • getWrapperType

      public static Class<?> getWrapperType(Class<?> type)
    • wrap

      public static <T> Class<T> wrap(Class<T> unwrapped)
    • unwrap

      public static <T> Class<T> unwrap(Class<T> wrapped)