Class AbstractAnnotationMetadataBuilder<T,A>

java.lang.Object
io.micronaut.inject.annotation.AbstractAnnotationMetadataBuilder<T,A>
Type Parameters:
T - The element type
A - The annotation type
Direct Known Subclasses:
GroovyAnnotationMetadataBuilder, JavaAnnotationMetadataBuilder

@Internal public abstract class AbstractAnnotationMetadataBuilder<T,A> extends Object
An abstract implementation that builds AnnotationMetadata.
Since:
1.0
Author:
Graeme Rocher
  • Constructor Details

    • AbstractAnnotationMetadataBuilder

      protected AbstractAnnotationMetadataBuilder()
      Default constructor.
  • Method Details

    • buildDeclared

      public AnnotationMetadata buildDeclared(T element)
      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 type
      methodElement - The method element
      parameterElement - 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 owningType
      element - 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 owningType
      element - The element
      Returns:
      The AbstractAnnotationMetadataBuilder.CachedAnnotationMetadata
    • lookupOrBuild

      Lookup or build new annotation metadata.
      Parameters:
      key - The cache key
      element - The type element
      Returns:
      The annotation metadata
      Since:
      4.0.0
    • getTypeForAnnotation

      protected abstract T getTypeForAnnotation(A annotationMirror)
      Get the type of the given annotation.
      Parameters:
      annotationMirror - The annotation
      Returns:
      The type
    • hasAnnotation

      protected abstract boolean hasAnnotation(T element, Class<? extends Annotation> annotation)
      Checks whether an annotation is present.
      Parameters:
      element - The element
      annotation - The annotation type
      Returns:
      True if the annotation is present
    • hasAnnotation

      protected abstract boolean hasAnnotation(T element, String annotation)
      Checks whether an annotation is present.
      Parameters:
      element - The element
      annotation - The annotation type name
      Returns:
      True if the annotation is present
    • hasAnnotations

      protected abstract boolean hasAnnotations(T element)
      Checks whether any annotations are present on the given element.
      Parameters:
      element - The element
      Returns:
      True if the annotation is present
    • getAnnotationTypeName

      protected abstract String getAnnotationTypeName(A annotationMirror)
      Get the given type of the annotation.
      Parameters:
      annotationMirror - The annotation
      Returns:
      The type
    • getElementName

      protected abstract String getElementName(T element)
      Get the name for the given element.
      Parameters:
      element - The element
      Returns:
      The name
    • getAnnotationsForType

      protected abstract List<? extends A> getAnnotationsForType(T element)
      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 element
      inheritTypeAnnotations - Whether to inherit type annotations
      declaredOnly - 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 element
      annotationName - The annotation name
      member - The member being read from
      memberName - The member
      annotationValue - The value
      annotationValues - 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 element
      annotationName - The annotation name
      member - The member being read from
      memberName - The member
      annotationValue - The value
      annotationValues - The values to populate
      resolvedDefaults - 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 element
      annotationName - The annotation name
      member - The member
      memberName - The member name
      resolvedValue - The resolved value
    • isValidationRequired

      protected abstract boolean isValidationRequired(T member)
      Return whether the given member requires validation.
      Parameters:
      member - The member
      Returns:
      True if it is
    • getElementValidator

      @Nullable protected @Nullable AnnotatedElementValidator getElementValidator()
      Obtains the element validator.
      Returns:
      The validator.
    • addError

      protected abstract void addError(@NonNull T originatingElement, @NonNull @NonNull String error)
      Adds an error.
      Parameters:
      originatingElement - The originating element
      error - The error
    • addWarning

      protected abstract void addWarning(@NonNull T originatingElement, @NonNull @NonNull String warning)
      Adds a warning.
      Parameters:
      originatingElement - The originating element
      warning - The warning
    • 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 element
      member - The member
      annotationName - The annotation name
      memberName - The member name
      annotationValue - The value
      Returns:
      The object
    • readAnnotationDefaultValues

      protected abstract Map<? extends T,?> readAnnotationDefaultValues(String annotationName, T annotationType)
      Read the raw default annotation values from the given annotation.
      Parameters:
      annotationName - annotation name
      annotationType - the type
      Returns:
      The values
    • readAnnotationRawValues

      protected abstract Map<? extends T,?> readAnnotationRawValues(A annotationMirror)
      Read the raw annotation values from the given annotation.
      Parameters:
      annotationMirror - The annotation
      Returns:
      The values
    • 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 element
      member - The member
      annotationType - The type
      Returns:
      The values
    • getAnnotationMemberName

      protected abstract String getAnnotationMemberName(T member)
      Read the name of an annotation member.
      Parameters:
      member - The member
      Returns:
      The name
    • getRepeatableName

      @Nullable protected abstract @Nullable String getRepeatableName(A annotationMirror)
      Obtain the name of the repeatable annotation if the annotation is one.
      Parameters:
      annotationMirror - The annotation mirror
      Returns:
      Return the name or null
    • getRepeatableNameForType

      @Nullable protected abstract @Nullable String getRepeatableNameForType(T annotationType)
      Obtain the name of the repeatable annotation if the annotation is one.
      Parameters:
      annotationType - The annotation mirror
      Returns:
      Return the name or null
    • readNestedAnnotationValue

      protected AnnotationValue<?> readNestedAnnotationValue(T annotationElement, A annotationType)
      Parameters:
      annotationElement - The annotation element
      annotationType - The annotation type
      Returns:
      The annotation value
    • readNestedAnnotationValue

      protected AnnotationValue<?> readNestedAnnotationValue(T annotationElement, A annotationType, Map<String,Map<CharSequence,Object>> resolvedDefaults)
    • getAnnotationMirror

      protected abstract Optional<T> getAnnotationMirror(String annotationName)
      Return a mirror for the given annotation.
      Parameters:
      annotationName - The annotation name
      Returns:
      An optional mirror
    • isEvaluatedExpression

      protected boolean isEvaluatedExpression(@Nullable @Nullable Object value)
      Detect evaluated expression in annotation value.
      Parameters:
      value - - Annotation value
      Returns:
      if value contains evaluated expression
    • buildEvaluatedExpressionReference

      @NonNull protected @NonNull Object buildEvaluatedExpressionReference(@NonNull T originatingElement, @NonNull @NonNull String annotationName, @NonNull @NonNull String memberName, @NonNull @NonNull Object initialAnnotationValue)
      Wraps original annotation value to make it processable at later stages.
      Parameters:
      originatingElement - originating annotated element
      annotationName - annotation name
      memberName - annotation member name
      initialAnnotationValue - original annotation value
      Returns:
      expression reference
    • getOriginatingClassName

      @Nullable protected abstract @Nullable String getOriginatingClassName(@NonNull T orginatingElement)
    • getAnnotationMember

      @Nullable protected abstract T getAnnotationMember(T annotationElement, CharSequence member)
      Get the annotation member.
      Parameters:
      annotationElement - The annotation element
      member - The member
      Returns:
      The annotation member element
    • getAnnotationMappers

      @NonNull protected <K extends Annotation> @NonNull List<AnnotationMapper<K>> getAnnotationMappers(@NonNull @NonNull 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

      @NonNull protected <K extends Annotation> @NonNull List<AnnotationTransformer<K>> getAnnotationTransformers(@NonNull @NonNull 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
    • createVisitorContext

      protected abstract VisitorContext createVisitorContext()
      Creates the visitor context for this implementation.
      Returns:
      The visitor context
    • getRetentionPolicy

      @NonNull protected abstract @NonNull RetentionPolicy getRetentionPolicy(@NonNull T annotation)
      Gets the retention policy for the given annotation.
      Parameters:
      annotation - The annotation
      Returns:
      The retention policy
    • getRetentionPolicy

      @NonNull public @NonNull RetentionPolicy getRetentionPolicy(@NonNull @NonNull String annotation)
      Gets the retention policy for the given annotation.
      Parameters:
      annotation - The annotation
      Returns:
      The retention policy
    • postProcess

      protected void postProcess(MutableAnnotationMetadata mutableAnnotationMetadata, T element)
    • getCachedAnnotationDefaults

      @NonNull protected @NonNull Map<CharSequence,Object> getCachedAnnotationDefaults(String annotationName, T annotationType)
      Get the cached annotation defaults.
      Parameters:
      annotationName - The annotation name
      annotationType - The annotation type
      Returns:
      The defaults
    • isExcludedAnnotation

      protected boolean isExcludedAnnotation(@NonNull T element, @NonNull @NonNull String annotationName)
      Is the given annotation excluded for the specified element.
      Parameters:
      element - The element
      annotationName - The annotation name
      Returns:
      True if it is excluded
    • clearMutated

      @Internal public static void clearMutated()
      Used to clear mutated metadata at the end of a compilation cycle.
    • clearCaches

      @Internal public static void clearCaches()
      Used to clear caches at the end of a compilation cycle.
    • copyToRuntime

      @Internal public static void 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

      @Internal public static Set<String> getMappedAnnotationNames()
      Returns:
      Additional mapped annotation names
    • getMappedAnnotationPackages

      @Internal public static Set<String> getMappedAnnotationPackages()
      Returns:
      Additional mapped annotation names
    • annotate

      @NonNull public <A2 extends Annotation> @NonNull AnnotationMetadata annotate(@NonNull @NonNull AnnotationMetadata annotationMetadata, @NonNull @NonNull AnnotationValue<A2> annotationValue)
      Annotate an existing annotation metadata object.
      Type Parameters:
      A2 - The annotation type
      Parameters:
      annotationMetadata - The annotation metadata
      annotationValue - The annotation value
      Returns:
      The mutated metadata
    • removeAnnotation

      @NonNull public @NonNull AnnotationMetadata removeAnnotation(@NonNull @NonNull AnnotationMetadata annotationMetadata, @NonNull @NonNull String annotationType)
      Removes an annotation from the given annotation metadata.
      Parameters:
      annotationMetadata - The annotation metadata
      annotationType - The annotation type
      Returns:
      The updated metadata
      Since:
      3.0.0
    • removeStereotype

      @NonNull public @NonNull AnnotationMetadata removeStereotype(@NonNull @NonNull AnnotationMetadata annotationMetadata, @NonNull @NonNull String annotationType)
      Removes an annotation from the given annotation metadata.
      Parameters:
      annotationMetadata - The annotation metadata
      annotationType - The annotation type
      Returns:
      The updated metadata
      Since:
      3.0.0
    • removeAnnotationIf

      @NonNull public <T1 extends Annotation> @NonNull AnnotationMetadata removeAnnotationIf(@NonNull @NonNull AnnotationMetadata annotationMetadata, @NonNull @NonNull Predicate<AnnotationValue<T1>> predicate)
      Removes an annotation from the metadata for the given predicate.
      Type Parameters:
      T1 - The annotation type
      Parameters:
      annotationMetadata - The annotation metadata
      predicate - The predicate
      Returns:
      The potentially modified metadata