Package org.fulib.fx.util.reflection
Class Reflection
java.lang.Object
org.fulib.fx.util.reflection.Reflection
Utility class containing different helper methods for reflection.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcallMethodsForFieldInstances(@NotNull Object instance, @NotNull Collection<@NotNull Field> fields, @NotNull Consumer<@NotNull Object> method) Calls the given method for all fields of the given class that are annotated with the given annotation.static booleancanBeAssigned(@NotNull Class<?> type, @Nullable Object value) Checks if the value can be assigned to the given type.getAllFields(@NotNull Class<?> clazz) Returns all fields of a class including private and inherited fields.getAllFieldsOfType(@NotNull Class<?> clazz, @NotNull Class<?> type) Returns all fields of the given class (or a super class) that are of the given type.getAllFieldsWithAnnotation(@NotNull Class<?> clazz, @NotNull Class<? extends @NotNull Annotation> annotation) Returns all fields of the given class (or a subclass) that are annotated with the given annotation.getAllMethods(@NotNull Class<?> clazz, boolean includeObjectMethods) Returns all methods of a class including private and inherited methods.getAllMethodsWithAnnotation(@NotNull Class<?> clazz, @NotNull Class<? extends @NotNull Annotation> annotation) Returns all methods of the given class (or a super class) that are annotated with the given annotation.getFieldsOfType(@NotNull Class<?> clazz, @NotNull Class<?> type) Returns all fields of the given class that are of the given type.getFieldsWithAnnotation(@NotNull Class<?> clazz, @NotNull Class<? extends @NotNull Annotation> annotation) Returns all fields of the given class that are annotated with the given annotation.getMethodsWithAnnotation(@NotNull Class<?> clazz, @NotNull Class<? extends @NotNull Annotation> annotation) Returns all methods of the given class that are annotated with the given annotation.static Class<?>getWrapperType(@NotNull Class<?> type) Returns the wrapped type of the given type.static <T> Class<T>Unwraps a wrapped type.static <T> Class<T>Wraps an unwrapped type.
-
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 fromannotation- 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 fromannotation- 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 onfields- The fields to call the methods formethod- 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 fromtype- 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 fromtype- 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 fromannotation- 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 fromannotation- 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 checkvalue- The value to check- Returns:
- True if the value can be assigned to the type, false otherwise
-
getWrapperType
Returns the wrapped type of the given type.- Parameters:
type- The type to be wrapped- Returns:
- the wrapped type or the given type if not a primitive type
-
wrap
Wraps an unwrapped type.- Type Parameters:
T- The unwrapped type- Parameters:
unwrapped- The unwrapped type- Returns:
- The wrapped type
-
unwrap
Unwraps a wrapped type.- Type Parameters:
T- The wrapped type- Parameters:
wrapped- The wrapped type- Returns:
- The unwrapped type
-
getAllFields
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
-