Class JavaAnnotationMetadataBuilder
java.lang.Object
io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder<Element,AnnotationMirror>
io.micronaut.annotation.processing.JavaAnnotationMetadataBuilder
public class JavaAnnotationMetadataBuilder
extends AbstractAnnotationMetadataBuilder<Element,AnnotationMirror>
A
AnnotationMetadata
for builder for Java to be used at compile time.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested classes/interfaces inherited from class io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder
AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata
-
Constructor Summary
ConstructorDescriptionJavaAnnotationMetadataBuilder
(Elements elements, Messager messager, AnnotationUtils annotationUtils, ModelUtils modelUtils) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds an error.protected void
addWarning
(@NonNull Element originatingElement, @NonNull String warning) Adds a warning.buildHierarchy
(Element element, boolean inheritTypeAnnotations, boolean declaredOnly) Build the type hierarchy for the given element.static void
Clears any caches from the last compilation round.protected VisitorContext
Creates the visitor context for this implementation.getAnnotationMember
(Element annotationElement, CharSequence member) Get the annotation member.protected String
getAnnotationMemberName
(Element member) Read the name of an annotation member.getAnnotationMirror
(String annotationName) Return a mirror for the given annotation.protected List<? extends AnnotationMirror>
getAnnotationsForType
(Element element) Obtain the annotations for the given type.protected String
getAnnotationTypeName
(AnnotationMirror annotationMirror) Get the given type of the annotation.protected <K extends Annotation>
Optional<AnnotationValue<K>>getAnnotationValues
(Element originatingElement, Element member, Class<K> annotationType) Resolve the annotations values from the given member for the given type.protected String
getElementName
(Element element) Get the name for the given element.protected @Nullable AnnotatedElementValidator
Obtains the element validator.protected String
getOriginatingClassName
(Element orginatingElement) getRepeatableName
(AnnotationMirror annotationMirror) Obtain the name of the repeatable annotation if the annotation is one.getRepeatableNameForType
(Element annotationType) Obtain the name of the repeatable annotation if the annotation is one.protected @NonNull RetentionPolicy
getRetentionPolicy
(@NonNull Element annotation) Gets the retention policy for the given annotation.protected Element
getTypeForAnnotation
(AnnotationMirror annotationMirror) Get the type of the given annotation.boolean
hasAnnotation
(Element element, Class<? extends Annotation> ann) Checks if a method has an annotation.boolean
hasAnnotation
(Element element, String ann) Checks if a method has an annotation.static boolean
hasAnnotation
(ExecutableElement method, Class<? extends Annotation> ann) Checks if a method has an annotation.protected boolean
hasAnnotations
(Element element) Checks whether any annotations are present on the given element.protected boolean
isExcludedAnnotation
(@NonNull Element element, @NonNull String annotationName) Is the given annotation excluded for the specified element.protected boolean
isValidationRequired
(Element member) Return whether the given member requires validation.readAnnotationDefaultValues
(String annotationTypeName, Element element) Read the raw default annotation values from the given annotation.readAnnotationRawValues
(AnnotationMirror annotationMirror) Read the raw annotation values from the given annotation.protected void
readAnnotationRawValues
(Element originatingElement, String annotationName, Element 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 void
readAnnotationRawValues
(Element originatingElement, String annotationName, Element 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 Object
readAnnotationValue
(Element originatingElement, Element 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.Methods inherited from class io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder
annotate, buildDeclared, buildEvaluatedExpressionReference, clearMutated, copyToRuntime, getAnnotationMappers, getAnnotationTransformers, getCachedAnnotationDefaults, getMappedAnnotationNames, getMappedAnnotationPackages, getRetentionPolicy, isEvaluatedExpression, lookupOrBuild, lookupOrBuildForField, lookupOrBuildForMethod, lookupOrBuildForParameter, lookupOrBuildForType, postProcess, readNestedAnnotationValue, readNestedAnnotationValue, removeAnnotation, removeAnnotationIf, removeStereotype, validateAnnotationValue
-
Constructor Details
-
JavaAnnotationMetadataBuilder
public JavaAnnotationMetadataBuilder(Elements elements, Messager messager, AnnotationUtils annotationUtils, ModelUtils modelUtils) Default constructor.- Parameters:
elements
- The elementUtilsmessager
- The messagerannotationUtils
- The annotation utilsmodelUtils
- The model utils
-
-
Method Details
-
getElementValidator
Description copied from class:AbstractAnnotationMetadataBuilder
Obtains the element validator.- Overrides:
getElementValidator
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Returns:
- The validator.
-
addError
protected void addError(@NonNull @NonNull Element originatingElement, @NonNull @NonNull String error) Description copied from class:AbstractAnnotationMetadataBuilder
Adds an error.- Specified by:
addError
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
originatingElement
- The originating elementerror
- The error
-
addWarning
protected void addWarning(@NonNull @NonNull Element originatingElement, @NonNull @NonNull String warning) Description copied from class:AbstractAnnotationMetadataBuilder
Adds a warning.- Specified by:
addWarning
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
originatingElement
- The originating elementwarning
- The warning
-
getAnnotationMemberName
Description copied from class:AbstractAnnotationMetadataBuilder
Read the name of an annotation member.- Specified by:
getAnnotationMemberName
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
member
- The member- Returns:
- The name
-
getRepeatableName
Description copied from class:AbstractAnnotationMetadataBuilder
Obtain the name of the repeatable annotation if the annotation is one.- Specified by:
getRepeatableName
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationMirror
- The annotation mirror- Returns:
- Return the name or null
-
getRepeatableNameForType
Description copied from class:AbstractAnnotationMetadataBuilder
Obtain the name of the repeatable annotation if the annotation is one.- Specified by:
getRepeatableNameForType
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationType
- The annotation mirror- Returns:
- Return the name or null
-
getAnnotationMirror
Description copied from class:AbstractAnnotationMetadataBuilder
Return a mirror for the given annotation.- Specified by:
getAnnotationMirror
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationName
- The annotation name- Returns:
- An optional mirror
-
createVisitorContext
Description copied from class:AbstractAnnotationMetadataBuilder
Creates the visitor context for this implementation.- Specified by:
createVisitorContext
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Returns:
- The visitor context
-
getRetentionPolicy
@NonNull protected @NonNull RetentionPolicy getRetentionPolicy(@NonNull @NonNull Element annotation) Description copied from class:AbstractAnnotationMetadataBuilder
Gets the retention policy for the given annotation.- Specified by:
getRetentionPolicy
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotation
- The annotation- Returns:
- The retention policy
-
getTypeForAnnotation
Description copied from class:AbstractAnnotationMetadataBuilder
Get the type of the given annotation.- Specified by:
getTypeForAnnotation
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationMirror
- The annotation- Returns:
- The type
-
getAnnotationsForType
Description copied from class:AbstractAnnotationMetadataBuilder
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.- Specified by:
getAnnotationsForType
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
element
- The type element- Returns:
- The annotations
-
isExcludedAnnotation
protected boolean isExcludedAnnotation(@NonNull @NonNull Element element, @NonNull @NonNull String annotationName) Description copied from class:AbstractAnnotationMetadataBuilder
Is the given annotation excluded for the specified element.- Overrides:
isExcludedAnnotation
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
element
- The elementannotationName
- The annotation name- Returns:
- True if it is excluded
-
buildHierarchy
protected List<Element> buildHierarchy(Element element, boolean inheritTypeAnnotations, boolean declaredOnly) Description copied from class:AbstractAnnotationMetadataBuilder
Build the type hierarchy for the given element.- Specified by:
buildHierarchy
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
element
- The elementinheritTypeAnnotations
- Whether to inherit type annotationsdeclaredOnly
- Whether to only include declared annotations- Returns:
- The type hierarchy
-
readAnnotationRawValues
Description copied from class:AbstractAnnotationMetadataBuilder
Read the raw annotation values from the given annotation.- Specified by:
readAnnotationRawValues
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationMirror
- The annotation- Returns:
- The values
-
getAnnotationMember
@Nullable protected @Nullable Element getAnnotationMember(Element annotationElement, CharSequence member) Description copied from class:AbstractAnnotationMetadataBuilder
Get the annotation member.- Specified by:
getAnnotationMember
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationElement
- The annotation elementmember
- The member- Returns:
- The annotation member element
-
getOriginatingClassName
- Specified by:
getOriginatingClassName
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror>
-
getAnnotationValues
protected <K extends Annotation> Optional<AnnotationValue<K>> getAnnotationValues(Element originatingElement, Element member, Class<K> annotationType) Description copied from class:AbstractAnnotationMetadataBuilder
Resolve the annotations values from the given member for the given type.- Specified by:
getAnnotationValues
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Type Parameters:
K
- The annotation type- Parameters:
originatingElement
- The originating elementmember
- The memberannotationType
- The type- Returns:
- The values
-
readAnnotationRawValues
protected void readAnnotationRawValues(Element originatingElement, String annotationName, Element member, String memberName, Object annotationValue, Map<CharSequence, Object> annotationValues) Description copied from class:AbstractAnnotationMetadataBuilder
Read the given member and value, applying conversions if necessary, and place the data in the given map.- Specified by:
readAnnotationRawValues
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - 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(Element originatingElement, String annotationName, Element member, String memberName, Object annotationValue, Map<CharSequence, Object> annotationValues, Map<String, Map<CharSequence, Object>> resolvedDefaults) Description copied from class:AbstractAnnotationMetadataBuilder
Read the given member and value, applying conversions if necessary, and place the data in the given map.- Overrides:
readAnnotationRawValues
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
originatingElement
- The originating elementannotationName
- The annotation namemember
- The member being read frommemberName
- The memberannotationValue
- The valueannotationValues
- The values to populateresolvedDefaults
- The resolved defaults
-
isValidationRequired
Description copied from class:AbstractAnnotationMetadataBuilder
Return whether the given member requires validation.- Specified by:
isValidationRequired
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
member
- The member- Returns:
- True if it is
-
readAnnotationValue
protected Object readAnnotationValue(Element originatingElement, Element member, String annotationName, String memberName, Object annotationValue) Description copied from class:AbstractAnnotationMetadataBuilder
Read the given member and value, applying conversions if necessary, and place the data in the given map.- Specified by:
readAnnotationValue
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
originatingElement
- The originating elementmember
- The memberannotationName
- The annotation namememberName
- The member nameannotationValue
- The value- Returns:
- The object
-
readAnnotationDefaultValues
protected Map<? extends Element,?> readAnnotationDefaultValues(String annotationTypeName, Element element) Description copied from class:AbstractAnnotationMetadataBuilder
Read the raw default annotation values from the given annotation.- Specified by:
readAnnotationDefaultValues
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationTypeName
- annotation nameelement
- the type- Returns:
- The values
-
getAnnotationTypeName
Description copied from class:AbstractAnnotationMetadataBuilder
Get the given type of the annotation.- Specified by:
getAnnotationTypeName
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
annotationMirror
- The annotation- Returns:
- The type
-
getElementName
Description copied from class:AbstractAnnotationMetadataBuilder
Get the name for the given element.- Specified by:
getElementName
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
element
- The element- Returns:
- The name
-
hasAnnotation
Checks if a method has an annotation.- Specified by:
hasAnnotation
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
element
- The methodann
- The annotation to look for- Returns:
- Whether if the method has the annotation
-
hasAnnotation
Checks if a method has an annotation.- Specified by:
hasAnnotation
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
element
- The methodann
- The annotation to look for- Returns:
- Whether if the method has the annotation
-
hasAnnotations
Description copied from class:AbstractAnnotationMetadataBuilder
Checks whether any annotations are present on the given element.- Specified by:
hasAnnotations
in classAbstractAnnotationMetadataBuilder<Element,
AnnotationMirror> - Parameters:
element
- The element- Returns:
- True if the annotation is present
-
clearCaches
public static void clearCaches()Clears any caches from the last compilation round. -
hasAnnotation
Checks if a method has an annotation.- Parameters:
method
- The methodann
- The annotation to look for- Returns:
- Whether if the method has the annotation
-