Class Annotations

java.lang.Object
org.ametys.runtime.util.Annotations

public final class Annotations extends Object
Helper for Annotations.
  • Method Details

    • isAnnotationPresent

      public static boolean isAnnotationPresent(Class<?> classToTest, Class<? extends Annotation> annotationClass)
      Tests if given Annotation is present on any of the superclasses or on any of the implemented interfaces.
      Unlike Class.isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation>), it also checks into all the implemented interfaces.
      Thus, the meta-annotation Inherited has no effect because whether or not it is present, the whole hierarchy is traversed here anyway.
      Parameters:
      classToTest - The class to test
      annotationClass - The Annotation class
      Returns:
      true if annotation is present on any of the superclasses or on any of the implemented interfaces.
    • getAnnotationAttributeValues

      public static <A extends Annotation, T> Stream<T> getAnnotationAttributeValues(Class<?> classToTest, Class<A> annotationClass, BiFunction<A,Class<?>,T> annotationAttributeGetter)
      Gets the Annotations on any of the superclasses or on any of the implemented interfaces from the given class to test, and then apply a bifunction on it (generally to obtain attributes from the Annotation instance).
      Unlike Class.getAnnotation(java.lang.Class<A>), it also checks into all the implemented interfaces.
      Whereas the whole hierarchy is traversed, the meta-annotation Inherited can have some effects depending on the operations you process on the result Stream, as the same annotation instance will be provided to the BiFunction with different classes (which are related, one being the superclass of all the others).
      Type Parameters:
      A - The runtime type of the Annotation
      T - The type of results to get
      Parameters:
      classToTest - The class to test
      annotationClass - The Annotation class
      annotationAttributeGetter - The two-args function to apply to get the final results. The two arguments represent the Annotation instance and the class which is annotated (be careful if the Annotation class has the meta-annotation Inherited).
      Returns:
      a Stream of T elements returned by the bifunction applied on Annotations instances on any of the superclasses or on any of the implemented interfaces or on the provided class itself.