Package org.ametys.runtime.util
Class Annotations
- java.lang.Object
-
- org.ametys.runtime.util.Annotations
-
public final class Annotations extends Object
Helper forAnnotation
s.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Logger
__LOGGER
-
Constructor Summary
Constructors Modifier Constructor Description private
Annotations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static Stream<Class<?>>
_getAncestorInterfaces(Class<?> classToTest)
private static Stream<Class<?>>
_getAncestorInterfacesAndSelf(Class<?> classToTest)
private static Stream<Class<?>>
_getInterfaces(Class<?> classToTest)
private static Stream<Class<?>>
_getSuperclassesAndSelf(Class<?> classToTest)
private static boolean
_isAnnotationPresent(Class<?> classToTest, Class<? extends Annotation> annotationClass)
private static boolean
_isAnnotationPresentOnInterfaces(Class<?> classToTest, Class<? extends Annotation> annotationClass)
private static boolean
_isAnnotationPresentOnInterfacesOfSuperclasses(Class<?> classToTest, Class<? extends Annotation> annotationClass)
private static <A extends Annotation,T>
T_logAndGet(BiFunction<A,Class<?>,T> annotationAttributeGetter, Class<?> annotated, A annotation)
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.
-
-
-
Field Detail
-
__LOGGER
private static final org.slf4j.Logger __LOGGER
-
-
Constructor Detail
-
Annotations
private Annotations()
-
-
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.
-
_isAnnotationPresent
private static boolean _isAnnotationPresent(Class<?> classToTest, Class<? extends Annotation> annotationClass)
-
_isAnnotationPresentOnInterfacesOfSuperclasses
private static boolean _isAnnotationPresentOnInterfacesOfSuperclasses(Class<?> classToTest, Class<? extends Annotation> annotationClass)
-
_getSuperclassesAndSelf
private static Stream<Class<?>> _getSuperclassesAndSelf(Class<?> classToTest)
-
_isAnnotationPresentOnInterfaces
private static boolean _isAnnotationPresentOnInterfaces(Class<?> classToTest, Class<? extends Annotation> annotationClass)
-
_getAncestorInterfacesAndSelf
private static Stream<Class<?>> _getAncestorInterfacesAndSelf(Class<?> classToTest)
-
_getAncestorInterfaces
private static Stream<Class<?>> _getAncestorInterfaces(Class<?> classToTest)
-
_getInterfaces
private static Stream<Class<?>> _getInterfaces(Class<?> classToTest)
-
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.
-
_logAndGet
private static <A extends Annotation,T> T _logAndGet(BiFunction<A,Class<?>,T> annotationAttributeGetter, Class<?> annotated, A annotation)
-
-