Class AbstractAnnotationMetadataBuilder<T,A>
java.lang.Object
io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder<T,A>
- Type Parameters:
T- The element typeA- The annotation type
- Direct Known Subclasses:
GroovyAnnotationMetadataBuilder, JavaAnnotationMetadataBuilder
An abstract implementation that builds
AnnotationMetadata.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe caching entry. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final @Nullable AnnotatedElementValidatorNames of annotations that should produce deprecation warnings. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidAdds an error.protected abstract voidaddWarning(T originatingElement, String warning) Adds a warning.<A2 extends Annotation>
AnnotationMetadataannotate(AnnotationMetadata annotationMetadata, AnnotationValue<A2> annotationValue) Annotate an existing annotation metadata object.buildDeclared(T element) Build only metadata for declared annotations.protected ObjectbuildEvaluatedExpressionReference(T originatingElement, String annotationName, String memberName, Object initialAnnotationValue) Wraps original annotation value to make it processable at later stages.buildHierarchy(T element, boolean inheritTypeAnnotations, boolean declaredOnly) Build the type hierarchy for the given element.protected final AnnotationMetadatabuildInternal(T element) static voidUsed to clear caches at the end of a compilation cycle.static voidUsed to clear mutated metadata at the end of a compilation cycle.static voidclearMutated(Object key) Used to clear mutated metadata at the end of a compilation cycle.static voidThis is used for testing scenarios only where annotation metadata is created without bean creation.protected @Nullable StringfindRepeatableContainerNameForType(String annotationName) Find the repeatable container for given annotation type.protected <K extends Annotation>
@Nullable List<AnnotationMapper<K>> getAnnotationMappers(String annotationName) Obtain the annotation mappers for the given annotation name.protected abstract @Nullable TgetAnnotationMember(T annotationElement, CharSequence member) Get the annotation member.protected abstract StringgetAnnotationMemberName(T member) Read the name of an annotation member.getAnnotationMirror(String annotationName) Return a mirror for the given annotation.getAnnotationsForType(T element) Obtain the annotations for the given type.protected <K extends Annotation>
@Nullable List<AnnotationTransformer<K>> getAnnotationTransformers(String annotationName) Obtain the transformers mappers for the given annotation name.protected abstract StringgetAnnotationTypeName(A annotationMirror) Get the given type of the annotation.protected abstract <K extends Annotation>
Optional<AnnotationValue<K>> getAnnotationValues(T originatingElement, T member, Class<K> annotationType) Resolve the annotations values from the given member for the given type.protected Map<CharSequence, Object> getCachedAnnotationDefaults(String annotationName, T annotationType) Get the cached annotation defaults.protected abstract StringgetElementName(T element) Get the name for the given element.protected @Nullable AnnotatedElementValidatorObtains the element validator.protected abstract @Nullable StringgetOriginatingClassName(T orginatingElement) protected abstract @Nullable StringgetRepeatableContainerNameForType(T annotationType) Obtain the name of the repeatable annotation if the annotation is one.protected abstract @Nullable StringgetRepeatableName(A annotationMirror) Obtain the name of the repeatable annotation if the annotation is one.getRetentionPolicy(String annotation) Gets the retention policy for the given annotation.protected abstract RetentionPolicygetRetentionPolicy(T annotation) Gets the retention policy for the given annotation.protected abstract TgetTypeForAnnotation(A annotationMirror) Get the type of the given annotation.protected abstract VisitorContextReturns the visitor context for this implementation.protected abstract booleanhasAnnotation(T element, Class<? extends Annotation> annotation) Checks whether an annotation is present.protected abstract booleanhasAnnotation(T element, String annotation) Checks whether an annotation is present.protected abstract booleanhasAnnotations(T element) Checks whether any annotations are present on the given element.protected booleanisEvaluatedExpression(@Nullable Object value) Detect evaluated expression in annotation value.protected booleanisExcludedAnnotation(T element, String annotationName) Is the given annotation excluded for the specified element.protected booleanisRepeatableAnnotationContainer(AnnotationValue<?> annotationValue) protected abstract booleanisValidationRequired(T member) Return whether the given member requires validation.lookupOrBuild(Object key, T element) Lookup or build new annotation metadata.lookupOrBuildForField(T owningType, T element) Build the metadata for the given field element excluding any class metadata.lookupOrBuildForMethod(T owningType, T element) Build the metadata for the given method element excluding any class metadata.lookupOrBuildForParameter(T owningType, T methodElement, T parameterElement) Build the metadata for the given element.lookupOrBuildForType(T typeElement) Build the metadata for the given element.protected voidpostProcess(MutableAnnotationMetadata mutableAnnotationMetadata, T element) readAnnotationDefaultValues(String annotationName, T annotationType) Read the raw default annotation values from the given annotation.readAnnotationRawValues(A annotationMirror) Read the raw annotation values from the given annotation.protected abstract voidreadAnnotationRawValues(T originatingElement, String annotationName, T member, String memberName, Object annotationValue, Map<CharSequence, Object> annotationValues) Read the given member and value, applying conversions if necessary, and place the data in the given map.protected voidreadAnnotationRawValues(T originatingElement, String annotationName, T member, String memberName, Object annotationValue, Map<CharSequence, Object> annotationValues, Map<String, Map<CharSequence, Object>> resolvedDefaults) Read the given member and value, applying conversions if necessary, and place the data in the given map.protected abstract ObjectreadAnnotationValue(T originatingElement, T member, String annotationName, String memberName, Object annotationValue) Read the given member and value, applying conversions if necessary, and place the data in the given map.protected AnnotationValue<?> readNestedAnnotationValue(T annotationElement, A annotationType) protected AnnotationValue<?> readNestedAnnotationValue(T annotationElement, A annotationType, Map<String, Map<CharSequence, Object>> resolvedDefaults) removeAnnotation(AnnotationMetadata annotationMetadata, String annotationType) Removes an annotation from the given annotation metadata.<T1 extends Annotation>
AnnotationMetadataremoveAnnotationIf(AnnotationMetadata annotationMetadata, Predicate<AnnotationValue<T1>> predicate) Removes an annotation from the metadata for the given predicate.removeStereotype(AnnotationMetadata annotationMetadata, String annotationType) Removes an annotation from the given annotation metadata.protected voidvalidateAnnotationValue(T originatingElement, String annotationName, T member, String memberName, Object resolvedValue) Validates an annotation value.
-
Field Details
-
ELEMENT_VALIDATOR
Names of annotations that should produce deprecation warnings. The key in the map is the deprecated annotation the value the replacement.
-
-
Constructor Details
-
AbstractAnnotationMetadataBuilder
protected AbstractAnnotationMetadataBuilder()Default constructor.
-
-
Method Details
-
buildDeclared
Build only metadata for declared annotations.- Parameters:
element- The element- Returns:
- The
AnnotationMetadata
-
lookupOrBuildForParameter
public AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupOrBuildForParameter(T owningType, T methodElement, T parameterElement) Build the metadata for the given element. If the element is a method the class metadata will be included.- Parameters:
owningType- The owning typemethodElement- The method elementparameterElement- The parameter element- Returns:
- The
AnnotationMetadata
-
lookupOrBuildForType
public AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupOrBuildForType(T typeElement) Build the metadata for the given element.- Parameters:
typeElement- The element- Returns:
- The
AnnotationMetadata
-
lookupOrBuildForMethod
public AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupOrBuildForMethod(T owningType, T element) Build the metadata for the given method element excluding any class metadata.- Parameters:
owningType- The owningTypeelement- The element- Returns:
- The
AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata
-
lookupOrBuildForField
public AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupOrBuildForField(T owningType, T element) Build the metadata for the given field element excluding any class metadata.- Parameters:
owningType- The owningTypeelement- The element- Returns:
- The
AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata
-
lookupOrBuild
public AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata lookupOrBuild(Object key, T element) Lookup or build new annotation metadata.- Parameters:
key- The cache keyelement- The type element- Returns:
- The annotation metadata
- Since:
- 4.0.0
-
buildInternal
-
getTypeForAnnotation
-
hasAnnotation
Checks whether an annotation is present.- Parameters:
element- The elementannotation- The annotation type- Returns:
- True if the annotation is present
-
hasAnnotation
-
hasAnnotations
Checks whether any annotations are present on the given element.- Parameters:
element- The element- Returns:
- True if the annotation is present
-
getAnnotationTypeName
-
getElementName
-
getAnnotationsForType
Obtain the annotations for the given type. This method is also responsible for unwrapping repeatable annotations.For example,
@Parent(value = {@Child, @Child})should result in the two child annotations being returned from this method instead of the parent annotation.- Parameters:
element- The type element- Returns:
- The annotations
-
buildHierarchy
protected abstract List<T> buildHierarchy(T element, boolean inheritTypeAnnotations, boolean declaredOnly) Build the type hierarchy for the given element.- Parameters:
element- The elementinheritTypeAnnotations- Whether to inherit type annotationsdeclaredOnly- Whether to only include declared annotations- Returns:
- The type hierarchy
-
readAnnotationRawValues
protected abstract void readAnnotationRawValues(T originatingElement, String annotationName, T member, String memberName, Object annotationValue, Map<CharSequence, Object> annotationValues) Read the given member and value, applying conversions if necessary, and place the data in the given map.- Parameters:
originatingElement- The originating elementannotationName- The annotation namemember- The member being read frommemberName- The memberannotationValue- The valueannotationValues- The values to populate
-
readAnnotationRawValues
protected void readAnnotationRawValues(T originatingElement, String annotationName, T member, String memberName, Object annotationValue, Map<CharSequence, Object> annotationValues, Map<String, Map<CharSequence, Object>> resolvedDefaults) Read the given member and value, applying conversions if necessary, and place the data in the given map.- Parameters:
originatingElement- The originating elementannotationName- The annotation namemember- The member being read frommemberName- The memberannotationValue- The valueannotationValues- The values to populateresolvedDefaults- The resolved defaults- Since:
- 4.3.0
-
validateAnnotationValue
protected void validateAnnotationValue(T originatingElement, String annotationName, T member, String memberName, Object resolvedValue) Validates an annotation value.- Parameters:
originatingElement- The originating elementannotationName- The annotation namemember- The membermemberName- The member nameresolvedValue- The resolved value
-
isValidationRequired
Return whether the given member requires validation.- Parameters:
member- The member- Returns:
- True if it is
-
getElementValidator
Obtains the element validator.- Returns:
- The validator.
-
addError
-
addWarning
-
readAnnotationValue
protected abstract Object readAnnotationValue(T originatingElement, T member, String annotationName, String memberName, Object annotationValue) Read the given member and value, applying conversions if necessary, and place the data in the given map.- Parameters:
originatingElement- The originating elementmember- The memberannotationName- The annotation namememberName- The member nameannotationValue- The value- Returns:
- The object
-
readAnnotationDefaultValues
-
readAnnotationRawValues
-
getAnnotationValues
protected abstract <K extends Annotation> Optional<AnnotationValue<K>> getAnnotationValues(T originatingElement, T member, Class<K> annotationType) Resolve the annotations values from the given member for the given type.- Type Parameters:
K- The annotation type- Parameters:
originatingElement- The originating elementmember- The memberannotationType- The type- Returns:
- The values
-
getAnnotationMemberName
-
getRepeatableName
-
getRepeatableContainerNameForType
-
readNestedAnnotationValue
- Parameters:
annotationElement- The annotation elementannotationType- The annotation type- Returns:
- The annotation value
-
readNestedAnnotationValue
protected AnnotationValue<?> readNestedAnnotationValue(T annotationElement, A annotationType, Map<String, Map<CharSequence, Object>> resolvedDefaults) - Parameters:
annotationElement- The annotation elementannotationType- The annotation typeresolvedDefaults- resoldved defaults- Returns:
- The annotation value
-
getAnnotationMirror
-
isEvaluatedExpression
Detect evaluated expression in annotation value.- Parameters:
value- - Annotation value- Returns:
- if value contains evaluated expression
-
buildEvaluatedExpressionReference
protected Object buildEvaluatedExpressionReference(T originatingElement, String annotationName, String memberName, Object initialAnnotationValue) Wraps original annotation value to make it processable at later stages.- Parameters:
originatingElement- originating annotated elementannotationName- annotation namememberName- annotation member nameinitialAnnotationValue- original annotation value- Returns:
- expression reference
-
getOriginatingClassName
-
getAnnotationMember
Get the annotation member.- Parameters:
annotationElement- The annotation elementmember- The member- Returns:
- The annotation member element
-
getAnnotationMappers
protected <K extends Annotation> @Nullable List<AnnotationMapper<K>> getAnnotationMappers(String annotationName) Obtain the annotation mappers for the given annotation name.- Type Parameters:
K- The annotation type- Parameters:
annotationName- The annotation name- Returns:
- The mappers
-
getAnnotationTransformers
protected <K extends Annotation> @Nullable List<AnnotationTransformer<K>> getAnnotationTransformers(String annotationName) Obtain the transformers mappers for the given annotation name.- Type Parameters:
K- The annotation type- Parameters:
annotationName- The annotation name- Returns:
- The transformers
-
getVisitorContext
Returns the visitor context for this implementation.- Returns:
- The visitor context
-
getRetentionPolicy
Gets the retention policy for the given annotation.- Parameters:
annotation- The annotation- Returns:
- The retention policy
-
getRetentionPolicy
Gets the retention policy for the given annotation.- Parameters:
annotation- The annotation- Returns:
- The retention policy
-
postProcess
-
getCachedAnnotationDefaults
protected Map<CharSequence, Object> getCachedAnnotationDefaults(String annotationName, T annotationType) Get the cached annotation defaults.- Parameters:
annotationName- The annotation nameannotationType- The annotation type- Returns:
- The defaults
-
isRepeatableAnnotationContainer
- Parameters:
annotationValue- The annotation value- Returns:
- true if the annotation is a repeatable container
-
findRepeatableContainerNameForType
-
isExcludedAnnotation
-
clearMutated
Used to clear mutated metadata at the end of a compilation cycle. -
clearMutated
-
clearCaches
Used to clear caches at the end of a compilation cycle. -
copyToRuntime
This is used for testing scenarios only where annotation metadata is created without bean creation. It is needed because at compile time there are no defaults added via DefaultAnnotationMetadata. -
getMappedAnnotationNames
-
getMappedAnnotationPackages
-
annotate
public <A2 extends Annotation> AnnotationMetadata annotate(AnnotationMetadata annotationMetadata, AnnotationValue<A2> annotationValue) Annotate an existing annotation metadata object.- Type Parameters:
A2- The annotation type- Parameters:
annotationMetadata- The annotation metadataannotationValue- The annotation value- Returns:
- The mutated metadata
-
removeAnnotation
public AnnotationMetadata removeAnnotation(AnnotationMetadata annotationMetadata, String annotationType) Removes an annotation from the given annotation metadata.- Parameters:
annotationMetadata- The annotation metadataannotationType- The annotation type- Returns:
- The updated metadata
- Since:
- 3.0.0
-
removeStereotype
public AnnotationMetadata removeStereotype(AnnotationMetadata annotationMetadata, String annotationType) Removes an annotation from the given annotation metadata.- Parameters:
annotationMetadata- The annotation metadataannotationType- The annotation type- Returns:
- The updated metadata
- Since:
- 3.0.0
-
removeAnnotationIf
public <T1 extends Annotation> AnnotationMetadata removeAnnotationIf(AnnotationMetadata annotationMetadata, Predicate<AnnotationValue<T1>> predicate) Removes an annotation from the metadata for the given predicate.- Type Parameters:
T1- The annotation type- Parameters:
annotationMetadata- The annotation metadatapredicate- The predicate- Returns:
- The potentially modified metadata
-