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(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.static booleancanBeAssigned(Class<?> type, Object value) Checks if the value can be assigned to the given type.getAllFields(Class<?> clazz) Returns all fields of a class including private and inherited fields.getAllFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Returns all fields of the given class (or a subclass) that are annotated with the given annotation.getAllMethods(Class<?> clazz, boolean includeObjectMethods) Returns all methods of a class including private and inherited methods.getAllMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Returns all methods of the given class (or a subclass) that are annotated with the given annotation.getFieldsOfType(Class<?> clazz, Class<?> type) Returns all fields of the given class that are of the given type.getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Returns all fields of the given class that are annotated with the given annotation.getMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Returns all methods of the given class that are annotated with the given annotation.static Class<?>getWrapperType(Class<?> type) static <T> Class<T>static <T> Class<T>
-
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 fromannotation- The annotation to filter the fields by- Returns:
- A list of fields that are annotated with the given annotation
-
getAllFieldsWithAnnotation
public static Stream<Field> getAllFieldsWithAnnotation(Class<?> clazz, Class<? extends 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 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 onfields- The fields to call the methods formethod- The method to call
-
getFieldsOfType
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 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 fromannotation- The annotation to filter the methods by- Returns:
- A list of methods that are annotated with the given annotation
-
getAllMethodsWithAnnotation
public static Stream<Method> getAllMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Returns all methods of the given class (or a subclass) 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 list of methods that are annotated with the given annotation
-
canBeAssigned
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
-
wrap
-
unwrap
-
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
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
-