com.vaadin.flow.internal.
Class 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) Finds all
CssImport
annotations on the givenComponent
class, its super classes and implemented interfaces.static List<JavaScript>
getJavaScriptAnnotations
(Class<? extends Component> componentClass) Finds all
JavaScript
annotations on the givenComponent
class, its super classes and implemented interfaces.getJsModuleAnnotations
(Class<? extends Component> componentClass) Finds all
JsModule
annotation on the givenComponent
class, its super classes and implenented interfaces.static List<StyleSheet>
getStyleSheetAnnotations
(Class<? extends Component> componentClass) Finds all
StyleSheet
annotations on the givenComponent
class, its super classes and implemented interfaces.
-
Method Details
-
getStyleSheetAnnotations
Finds all
StyleSheet
annotations on the givenComponent
class, its super classes and implemented interfaces.Parameters:
componentClass
- the component class to search for the annotationReturns:
a list the style sheet annotations found
See Also:
-
getCssImportAnnotations
Finds all
CssImport
annotations on the givenComponent
class, its super classes and implemented interfaces.Parameters:
componentClass
- the component class to search for the annotationReturns:
a list the CssImport annotations found
See Also:
-
getJavaScriptAnnotations
Finds all
JavaScript
annotations on the givenComponent
class, its super classes and implemented interfaces.Parameters:
componentClass
- the component class to search for the annotationReturns:
a list the JavaScript annotations found
See Also:
-
getJsModuleAnnotations
Finds all
JsModule
annotation on the givenComponent
class, its super classes and implenented interfaces.Parameters:
componentClass
- the component class to search for the annotationReturns:
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 typeParameters:
field
- the field to checkannotationType
- the annotation type to look forReturns:
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 typeParameters:
clazz
- the class from which the annotation should be foundannotationType
- the annotation type to look forReturns:
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 typeParameters:
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 presentReturns:
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 typeParameters:
clazz
- the class from which the annotation should be foundannotationType
- the annotation type to look forReturns:
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 typeParameters:
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 annotationReturns:
a list containing all the annotations found
-