Class AnnotationHelper
java.lang.Object
com.blackbuild.klum.ast.runtime.internal.AnnotationHelper
Helper class for annotations. Provides various functions concerning the discovery and handling of annotations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Annotation>
Optional<T>getAnnotation(Field field, Class<T> annotationType) static Stream<Annotation>getMetaAnnotated(AnnotatedElement target, Class<? extends Annotation> metaAnnotation) Returns all annotations which are themselves annotated with a meta annotation on the given target.static <T extends Annotation>
Optional<T>getMostSpecificAnnotation(AnnotatedElement target, Class<T> annotationType) Tries to retrieve the given Annotation from the given target.static <T extends Annotation>
Optional<T>getMostSpecificAnnotation(AnnotatedElement target, Class<T> annotationType, Predicate<T> filter) Tries to retrieve the given Annotation from the given target.static <T extends Annotation>
TgetNestedAnnotation(AnnotatedElement target, Class<T> annotationType) Returns the annotation of the given type that is directly present on the given target.getNonDefaultMembers(Annotation annotation) static booleanisMetaAnnotation(Class<? extends Annotation> type) Returns true if the given annotation is a meta annotation, i.e.
-
Method Details
-
getMostSpecificAnnotation
public static <T extends Annotation> Optional<T> getMostSpecificAnnotation(AnnotatedElement target, Class<T> annotationType) Tries to retrieve the given Annotation from the given target. Checks in the following order:- On the target itself
- If the target is a member on the owning class of the target
- for each DSL class in hierarchy, check the class and the classes package
The first found instance of the annotation is returned. If no annotation is found, null is returned.
- Parameters:
target- the target to retrieve the annotation fromannotationType- the annotation type to retrieve- Returns:
- the annotation or
Optional.empty()if no annotation is found
-
getMostSpecificAnnotation
public static <T extends Annotation> Optional<T> getMostSpecificAnnotation(AnnotatedElement target, Class<T> annotationType, Predicate<T> filter) Tries to retrieve the given Annotation from the given target. Checks in the following order:- On the target itself
- If the target is a member on the owning class of the target
- for each DSL class in hierarchy, check the class and the classes package
- Type Parameters:
T- the annotation type- Parameters:
target- the target to retrieve the annotation fromannotationType- the annotation type to retrievefilter- the filter to apply to the annotation- Returns:
- the annotation or
Optional.empty()if no annotation is found
-
getNestedAnnotation
public static <T extends Annotation> T getNestedAnnotation(AnnotatedElement target, Class<T> annotationType) Returns the annotation of the given type that is directly present on the given target. If the annotation is not present, check all annotations of the target that are in turn annotated with the given annotation type.- Type Parameters:
T- the annotation type- Parameters:
target- the target to retrieve the annotation fromannotationType- the annotation type to retrieve- Returns:
- the found annotation or null
-
getMetaAnnotated
public static Stream<Annotation> getMetaAnnotated(AnnotatedElement target, Class<? extends Annotation> metaAnnotation) Returns all annotations which are themselves annotated with a meta annotation on the given target.- Parameters:
target- the target to retrieve the annotation frommetaAnnotation- the meta annotation that must be present on the result annotations- Returns:
- the found annotation or null
-
getNonDefaultMembers
-
isMetaAnnotation
Returns true if the given annotation is a meta annotation, i.e. it's targets includeElementType.ANNOTATION_TYPEor are not set at all.- Parameters:
type- the annotation type to check- Returns:
- true if the annotation is a meta annotation
-
getAnnotation
public static <T extends Annotation> Optional<T> getAnnotation(Field field, Class<T> annotationType)
-