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(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull Class<? extends @NotNull 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 stream of fields that are annotated with the given annotation
    • getAllFieldsWithAnnotation

      public static Stream<Field> getAllFieldsWithAnnotation(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull Class<? extends @NotNull Annotation> annotation)
      Returns all fields of the given class (or a subclass) 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 stream of fields that are annotated with the given annotation
    • callMethodsForFieldInstances

      public static void callMethodsForFieldInstances(@NotNull @NotNull Object instance, @NotNull @NotNull Collection<@NotNull Field> fields, @NotNull @NotNull Consumer<@NotNull 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(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull 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 stream of fields that are of the given type
    • getAllFieldsOfType

      public static Stream<Field> getAllFieldsOfType(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull Class<?> type)
      Returns all fields of the given class (or a super 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 stream of fields that are of the given type
    • getMethodsWithAnnotation

      public static Stream<Method> getMethodsWithAnnotation(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull Class<? extends @NotNull 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 stream of methods that are annotated with the given annotation
    • getAllMethodsWithAnnotation

      public static Stream<Method> getAllMethodsWithAnnotation(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull Class<? extends @NotNull Annotation> annotation)
      Returns all methods of the given class (or a super 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 stream of methods that are annotated with the given annotation
    • canBeAssigned

      public static boolean canBeAssigned(@NotNull @NotNull Class<?> type, @Nullable @Nullable 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
    • getWrapperType

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

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

      public static <T> Class<T> unwrap(@NotNull @NotNull Class<T> wrapped)
    • getAllFields

      public static List<Field> getAllFields(@NotNull @NotNull Class<?> clazz)
      Returns all fields of a class including private and inherited fields.
      Parameters:
      clazz - The class to get the fields from
      Returns:
      A list of all fields of the given class
    • getAllMethods

      public static List<Method> getAllMethods(@NotNull @NotNull Class<?> clazz, boolean includeObjectMethods)
      Returns all methods of a class including private and inherited methods.
      Parameters:
      clazz - The class to get the methods from
      Returns:
      A list of all methods of the given class