Package org.ametys.runtime.util
Class Annotations
java.lang.Object
org.ametys.runtime.util.Annotations
Helper for
Annotations.-
Method Summary
Modifier and TypeMethodDescriptionstatic <A extends Annotation,T>
Stream<T>getAnnotationAttributeValues(Class<?> classToTest, Class<A> annotationClass, BiFunction<A, Class<?>, T> annotationAttributeGetter) Gets theAnnotations on any of the superclasses or on any of the implemented interfaces from the given class to test, and then apply abifunctionon it (generally to obtain attributes from theAnnotationinstance).static booleanisAnnotationPresent(Class<?> classToTest, Class<? extends Annotation> annotationClass) Tests if givenAnnotationis present on any of the superclasses or on any of the implemented interfaces.
-
Method Details
-
isAnnotationPresent
public static boolean isAnnotationPresent(Class<?> classToTest, Class<? extends Annotation> annotationClass) Tests if givenAnnotationis present on any of the superclasses or on any of the implemented interfaces.
UnlikeClass.isAnnotationPresent(java.lang.Class<? extends java.lang.annotation.Annotation>), it also checks into all the implemented interfaces.
Thus, the meta-annotationInheritedhas no effect because whether or not it is present, the whole hierarchy is traversed here anyway.- Parameters:
classToTest- The class to testannotationClass- TheAnnotationclass- Returns:
trueif 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 theAnnotations on any of the superclasses or on any of the implemented interfaces from the given class to test, and then apply abifunctionon it (generally to obtain attributes from theAnnotationinstance).
UnlikeClass.getAnnotation(java.lang.Class<A>), it also checks into all the implemented interfaces.
Whereas the whole hierarchy is traversed, the meta-annotationInheritedcan have some effects depending on the operations you process on the resultStream, as the same annotation instance will be provided to theBiFunctionwith different classes (which are related, one being the superclass of all the others).- Type Parameters:
A- The runtime type of theAnnotationT- The type of results to get- Parameters:
classToTest- The class to testannotationClass- TheAnnotationclassannotationAttributeGetter- Thetwo-args functionto apply to get the final results. The two arguments represent theAnnotationinstance and the class which is annotated (be careful if theAnnotationclass has the meta-annotationInherited).- Returns:
- a
Streamof T elements returned by thebifunctionapplied onAnnotations instances on any of the superclasses or on any of the implemented interfaces or on the provided class itself.
-