Package com.vaadin.flow.internal
Class AnnotationReader
java.lang.Object
com.vaadin.flow.internal.AnnotationReader
Helper class for reading annotation data.
For internal use only. May be renamed or removed in a future release.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Annotation>
Optional<T>getAnnotationFor
(Class<?> clazz, Class<T> annotationType) Helper to get an annotation for a class.static <T extends Annotation>
Optional<T>getAnnotationFor
(Field field, Class<T> annotationType) Helper to get an annotation for a field.static <T extends Annotation>
List<T>getAnnotationsFor
(Class<?> clazz, Class<T> annotationType) Helper to get annotations for a class by searching recursively the class and all its super classes and implemented interfaces and their parent interfaces.static <A extends Annotation,
T>
Optional<T>getAnnotationValueFor
(Class<?> clazz, Class<A> annotationType, Function<A, T> valueExtractor) Gets a value from an annotation for a class.static <A extends Annotation,
T>
Stream<T>getAnnotationValuesFor
(Class<?> clazz, Class<A> annotationType, Function<A, T> valueExtractor) Gets values from annotations for a class by searching recursively the class and all its super classes and implemented interfaces and their parent interfaces.getCssImportAnnotations
(Class<? extends Component> componentClass) static List<JavaScript>
getJavaScriptAnnotations
(Class<? extends Component> componentClass) Finds allJavaScript
annotations on the givenComponent
class, its super classes and implemented interfaces.getJsModuleAnnotations
(Class<? extends Component> componentClass) static List<StyleSheet>
getStyleSheetAnnotations
(Class<? extends Component> componentClass) Finds allStyleSheet
annotations on the givenComponent
class, its super classes and implemented interfaces.
-
Method Details
-
getStyleSheetAnnotations
Finds allStyleSheet
annotations on the givenComponent
class, its super classes and implemented interfaces.- Parameters:
componentClass
- the component class to search for the annotation- Returns:
- a list the style sheet annotations found
- See Also:
-
getCssImportAnnotations
Finds allCssImport
annotations on the givenComponent
class, its super classes and implemented interfaces.- Parameters:
componentClass
- the component class to search for the annotation- Returns:
- a list the CssImport annotations found
- See Also:
-
getJavaScriptAnnotations
Finds allJavaScript
annotations on the givenComponent
class, its super classes and implemented interfaces.- Parameters:
componentClass
- the component class to search for the annotation- Returns:
- a list the JavaScript annotations found
- See Also:
-
getJsModuleAnnotations
Finds allJsModule
annotation on the givenComponent
class, its super classes and implenented interfaces.- Parameters:
componentClass
- the component class to search for the annotation- Returns:
- a list the JavaScript annotations found
-
getAnnotationFor
public static <T extends Annotation> Optional<T> getAnnotationFor(Field field, Class<T> annotationType) Helper to get an annotation for a field.- Type Parameters:
T
- the annotation type- Parameters:
field
- the field to checkannotationType
- the annotation type to look for- Returns:
- an
Optional
annotation of the given type, or an empty Optional if the field does not have the given annotation
-
getAnnotationFor
public static <T extends Annotation> Optional<T> getAnnotationFor(Class<?> clazz, Class<T> annotationType) Helper to get an annotation for a class. If the annotation is not present on the target class, its super classes and implemented interfaces are also searched for the annotation.- Type Parameters:
T
- the annotation type- Parameters:
clazz
- the class from which the annotation should be foundannotationType
- the annotation type to look for- Returns:
- an
Optional
annotation of the given type
-
getAnnotationValueFor
public static <A extends Annotation,T> Optional<T> getAnnotationValueFor(Class<?> clazz, Class<A> annotationType, Function<A, T> valueExtractor) Gets a value from an annotation for a class. If the annotation is not present on the target class, its super classes and implemented interfaces are also searched for the annotation.- Type Parameters:
A
- the annotation typeT
- the annotation value type- Parameters:
clazz
- the class from which the annotation should be foundannotationType
- the annotation type to look forvalueExtractor
- the function for extracting the value from the annotation if an annotation is present- Returns:
- an
Optional
annotation value
-
getAnnotationsFor
public static <T extends Annotation> List<T> getAnnotationsFor(Class<?> clazz, Class<T> annotationType) Helper to get annotations for a class by searching recursively the class and all its super classes and implemented interfaces and their parent interfaces.The annotations in the list are ordered top-down according to the class hierarchy. For each hierarchy level, the annotations from interfaces implemented at that level are on the list before the annotations of the class itself.
NOTE: the list may contain annotations with the same values.
- Type Parameters:
T
- the annotation type- Parameters:
clazz
- the class from which the annotation should be foundannotationType
- the annotation type to look for- Returns:
- a list containing all the annotations found
-
getAnnotationValuesFor
public static <A extends Annotation,T> Stream<T> getAnnotationValuesFor(Class<?> clazz, Class<A> annotationType, Function<A, T> valueExtractor) Gets values from annotations for a class by searching recursively the class and all its super classes and implemented interfaces and their parent interfaces.The values in the stream are ordered top-down according to the class hierarchy. For each hierarchy level, the values from annotations of interfaces implemented at that level are on the list before the values from annotations of the class itself.
NOTE: the stream may contain duplicates
- Type Parameters:
A
- the annotation typeT
- the annotation value type- Parameters:
clazz
- the class from which the annotation should be foundannotationType
- the annotation type to look forvalueExtractor
- the function for extracting the value from any found annotation- Returns:
- a list containing all the annotations found
-