Interface AnnotationOverlay
-
- All Known Subinterfaces:
MutableAnnotationOverlay
- All Known Implementing Classes:
AnnotationOverlayImpl
,MutableAnnotationOverlayImpl
public interface AnnotationOverlay
Annotation 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 class
AnnotationOverlay.Builder
The builder for an annotation overlay.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default AnnotationInstance
annotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instance of givenclazz
declared on givendeclaration
.AnnotationInstance
annotation(Declaration declaration, DotName name)
Returns the annotation instance with givenname
declared 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 givenname
declared on givendeclaration
.static AnnotationOverlay.Builder
builder(IndexView index, java.util.Collection<AnnotationTransformation> annotationTransformations)
Returns a new builder for an annotation overlay for givenindex
and a given collection oftransformations
.default boolean
hasAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns whether an annotation instance of givenclazz
is declared on givendeclaration
.boolean
hasAnnotation(Declaration declaration, DotName name)
Returns whether an annotation instance with givenname
is declared on givendeclaration
.default boolean
hasAnyAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation>... classes)
Returns whether any annotation instance of one of givenclasses
is declared on givendeclaration
.boolean
hasAnyAnnotation(Declaration declaration, java.util.Set<DotName> names)
Returns whether any annotation instance with one of givennames
is declared on givendeclaration
.IndexView
index()
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 givenindex
and 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 benull
annotationTransformations
- 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 givenname
is 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 benull
name
- name of the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise
-
hasAnnotation
default boolean hasAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns whether an annotation instance of givenclazz
is 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 benull
clazz
- the annotation type to look for, must not benull
- Returns:
true
if the annotation is present,false
otherwise- See Also:
hasAnnotation(Declaration, DotName)
-
hasAnyAnnotation
boolean hasAnyAnnotation(Declaration declaration, java.util.Set<DotName> names)
Returns whether any annotation instance with one of givennames
is 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 benull
names
- names of the annotation types to look for, must not benull
- Returns:
true
if any of the annotations is present,false
otherwise
-
hasAnyAnnotation
default boolean hasAnyAnnotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation>... classes)
Returns whether any annotation instance of one of givenclasses
is 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 benull
classes
- annotation types to look for, must not benull
- Returns:
true
if any of the annotations is present,false
otherwise
-
annotation
AnnotationInstance annotation(Declaration declaration, DotName name)
Returns the annotation instance with givenname
declared 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 givenname
is present, an unspecified instance is returned.- Parameters:
declaration
- the declaration to inspect, must not benull
name
- name of the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found
-
annotation
default AnnotationInstance annotation(Declaration declaration, java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Returns the annotation instance of givenclazz
declared 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 givenclazz
is present, an unspecified instance is returned.- Parameters:
declaration
- the declaration to inspect, must not benull
clazz
- the annotation type to look for, must not benull
- Returns:
- the annotation instance, or
null
if not found - See Also:
annotation(Declaration, DotName)
-
annotationsWithRepeatable
java.util.Collection<AnnotationInstance> annotationsWithRepeatable(Declaration declaration, DotName name)
Returns the annotation instances with givenname
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(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 benull
name
- 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 benull
clazz
- 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
-
-