Package org.ametys.runtime.util
Class Annotations
- java.lang.Object
-
- org.ametys.runtime.util.Annotations
-
public final class Annotations extends Object
Helper forAnnotation
s.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <A extends Annotation,T>
Stream<T>getAnnotationAttributeValues(Class<?> classToTest, Class<A> annotationClass, BiFunction<A,Class<?>,T> annotationAttributeGetter)
Gets theAnnotation
s on any of the superclasses or on any of the implemented interfaces from the given class to test, and then apply abifunction
on it (generally to obtain attributes from theAnnotation
instance).static boolean
isAnnotationPresent(Class<?> classToTest, Class<? extends Annotation> annotationClass)
Tests if givenAnnotation
is present on any of the superclasses or on any of the implemented interfaces.
-
-
-
Method Detail
-
isAnnotationPresent
public static boolean isAnnotationPresent(Class<?> classToTest, Class<? extends Annotation> annotationClass)
Tests if givenAnnotation
is 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-annotationInherited
has no effect because whether or not it is present, the whole hierarchy is traversed here anyway.- Parameters:
classToTest
- The class to testannotationClass
- TheAnnotation
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 theAnnotation
s on any of the superclasses or on any of the implemented interfaces from the given class to test, and then apply abifunction
on it (generally to obtain attributes from theAnnotation
instance).
UnlikeClass.getAnnotation(java.lang.Class<A>)
, it also checks into all the implemented interfaces.
Whereas the whole hierarchy is traversed, the meta-annotationInherited
can have some effects depending on the operations you process on the resultStream
, as the same annotation instance will be provided to theBiFunction
with different classes (which are related, one being the superclass of all the others).- Type Parameters:
A
- The runtime type of theAnnotation
T
- The type of results to get- Parameters:
classToTest
- The class to testannotationClass
- TheAnnotation
classannotationAttributeGetter
- Thetwo-args function
to apply to get the final results. The two arguments represent theAnnotation
instance and the class which is annotated (be careful if theAnnotation
class has the meta-annotationInherited
).- Returns:
- a
Stream
of T elements returned by thebifunction
applied onAnnotation
s instances on any of the superclasses or on any of the implemented interfaces or on the provided class itself.
-
-