Class AnnotationReader


  • public class AnnotationReader
    extends Object
    Helper class for reading annotation data.

    For internal use only. May be renamed or removed in a future release.

    Since:
    1.0
    • Method Detail

      • getJsModuleAnnotations

        public static List<JsModule> getJsModuleAnnotations​(Class<? extends Component> componentClass)
        Finds all JsModule annotation on the given Component 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 AnnotationOptional<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 check
        annotationType - 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 AnnotationOptional<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 found
        annotationType - 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 type
        T - the annotation value type
        Parameters:
        clazz - the class from which the annotation should be found
        annotationType - the annotation type to look for
        valueExtractor - the function for extracting the value from the annotation if an annotation is present
        Returns:
        an Optional annotation value
      • getAnnotationsFor

        public static <T extends AnnotationList<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 found
        annotationType - 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 type
        T - the annotation value type
        Parameters:
        clazz - the class from which the annotation should be found
        annotationType - the annotation type to look for
        valueExtractor - the function for extracting the value from any found annotation
        Returns:
        a list containing all the annotations found