Interface AnnotationOverlay
-
- All Known Subinterfaces:
MutableAnnotationOverlay
- All Known Implementing Classes:
AnnotationOverlayImpl,MutableAnnotationOverlayImpl
public interface AnnotationOverlayAnnotation overlay allows overriding annotation information from an index. This is useful when Jandex is used as a language model and annotations are directly used as framework metadata. Transforming metadata is a frequent requirement in such situations, but core Jandex is immutable. This interface is layered on top of core Jandex and provides the necessary indirection between the user and the core Jandex that is required to apply the transformations.- Since:
- 3.2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAnnotationOverlay.BuilderThe builder for an annotation overlay.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default AnnotationInstanceannotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)Returns the annotation instance of givenclazzdeclared on givendeclaration.AnnotationInstanceannotation(Declaration declaration, DotName name)Returns the annotation instance with givennamedeclared on givendeclaration.java.util.Collection<AnnotationInstance>annotations(Declaration declaration)Returns the annotation instances declared on givendeclaration.default java.util.Collection<AnnotationInstance>annotationsWithRepeatable(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)Returns the annotation instances of given type (clazz) declared on givendeclaration.java.util.Collection<AnnotationInstance>annotationsWithRepeatable(Declaration declaration, DotName name)Returns the annotation instances with givennamedeclared on givendeclaration.static AnnotationOverlay.Builderbuilder(IndexView index, java.util.Collection<AnnotationTransformation> annotationTransformations)Returns a new builder for an annotation overlay for givenindexand a given collection oftransformations.default booleanhasAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)Returns whether an annotation instance of givenclazzis declared on givendeclaration.booleanhasAnnotation(Declaration declaration, DotName name)Returns whether an annotation instance with givennameis declared on givendeclaration.default booleanhasAnyAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation>... classes)Returns whether any annotation instance of one of givenclassesis declared on givendeclaration.booleanhasAnyAnnotation(Declaration declaration, java.util.Set<DotName> names)Returns whether any annotation instance with one of givennamesis declared on givendeclaration.IndexViewindex()Returns the index whose annotation information is being overlaid.
-
-
-
Method Detail
-
builder
static AnnotationOverlay.Builder builder(IndexView index, java.util.Collection<AnnotationTransformation> annotationTransformations)
Returns a new builder for an annotation overlay for givenindexand a given collection oftransformations.Thread safety
The object returned by the builder is immutable and can be shared between threads without safe publication.
- Parameters:
index- the Jandex index, must not benullannotationTransformations- the collection of annotation transformations- Returns:
- the annotation overlay builder, never
null
-
index
IndexView index()
Returns the index whose annotation information is being overlaid.- Returns:
- the index underlying this annotation overlay, never
null
-
hasAnnotation
boolean hasAnnotation(Declaration declaration, DotName name)
Returns whether an annotation instance with givennameis declared on givendeclaration.Like
AnnotationTarget.hasDeclaredAnnotation(DotName), and unlikeAnnotationTarget.hasAnnotation(DotName), this method ignores annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods.- Parameters:
declaration- the declaration to inspect, must not benullname- name of the annotation type to look for, must not benull- Returns:
trueif the annotation is present,falseotherwise
-
hasAnnotation
default boolean hasAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns whether an annotation instance of givenclazzis declared on givendeclaration.Like
AnnotationTarget.hasDeclaredAnnotation(Class), and unlikeAnnotationTarget.hasAnnotation(Class), this method ignores annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods.- Parameters:
declaration- the declaration to inspect, must not benullclazz- the annotation type to look for, must not benull- Returns:
trueif the annotation is present,falseotherwise- See Also:
hasAnnotation(Declaration, DotName)
-
hasAnyAnnotation
boolean hasAnyAnnotation(Declaration declaration, java.util.Set<DotName> names)
Returns whether any annotation instance with one of givennamesis declared on givendeclaration.This method ignores annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods.
- Parameters:
declaration- the declaration to inspect, must not benullnames- names of the annotation types to look for, must not benull- Returns:
trueif any of the annotations is present,falseotherwise
-
hasAnyAnnotation
default boolean hasAnyAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation>... classes)
Returns whether any annotation instance of one of givenclassesis declared on givendeclaration.This method ignores annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods.
- Parameters:
declaration- the declaration to inspect, must not benullclasses- annotation types to look for, must not benull- Returns:
trueif any of the annotations is present,falseotherwise
-
annotation
AnnotationInstance annotation(Declaration declaration, DotName name)
Returns the annotation instance with givennamedeclared on givendeclaration.Like
AnnotationTarget.declaredAnnotation(DotName), and unlikeAnnotationTarget.annotation(DotName), this method doesn't return annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods. In such case, if more than one annotation of givennameis present, an unspecified instance is returned.- Parameters:
declaration- the declaration to inspect, must not benullname- name of the annotation type to look for, must not benull- Returns:
- the annotation instance, or
nullif not found
-
annotation
default AnnotationInstance annotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instance of givenclazzdeclared on givendeclaration.Like
AnnotationTarget.declaredAnnotation(Class), and unlikeAnnotationTarget.annotation(Class), this method doesn't return annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods. In such case, if more than one annotation of givenclazzis present, an unspecified instance is returned.- Parameters:
declaration- the declaration to inspect, must not benullclazz- the annotation type to look for, must not benull- Returns:
- the annotation instance, or
nullif not found - See Also:
annotation(Declaration, DotName)
-
annotationsWithRepeatable
java.util.Collection<AnnotationInstance> annotationsWithRepeatable(Declaration declaration, DotName name)
Returns the annotation instances with givennamedeclared on givendeclaration. If the specified annotation is repeatable, the result also contains all values from the container annotation instance.The annotation class must be present in the index underlying this annotation overlay.
Like
AnnotationTarget.declaredAnnotationsWithRepeatable(DotName, IndexView), and unlikeAnnotationTarget.annotationsWithRepeatable(DotName, IndexView), this method doesn't return annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods.- Parameters:
declaration- the declaration to inspect, must not benullname- name of the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null
-
annotationsWithRepeatable
default java.util.Collection<AnnotationInstance> annotationsWithRepeatable(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instances of given type (clazz) declared on givendeclaration. If the specified annotation is repeatable, the result also contains all values from the container annotation instance.The annotation class must be present in the index underlying this annotation overlay.
Like
AnnotationTarget.declaredAnnotationsWithRepeatable(Class, IndexView), and unlikeAnnotationTarget.annotationsWithRepeatable(Class, IndexView), this method doesn't return annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods.- Parameters:
declaration- the declaration to inspect, must not benullclazz- the annotation type, must not benull- Returns:
- immutable collection of annotation instances, never
null - See Also:
annotationsWithRepeatable(Declaration, DotName)
-
annotations
java.util.Collection<AnnotationInstance> annotations(Declaration declaration)
Returns the annotation instances declared on givendeclaration.Like
AnnotationTarget.declaredAnnotations(), and unlikeAnnotationTarget.annotations(), this method doesn't return annotations declared on nested annotation targets. This doesn't hold in case of methods in the compatible mode, where method parameters are considered part of methods.- Parameters:
declaration- the declaration to inspect, must not benull- Returns:
- immutable collection of annotation instances, never
null
-
-