Class MutableAnnotationMetadata

java.lang.Object
io.micronaut.inject.annotation.DefaultAnnotationMetadata
io.micronaut.inject.annotation.MutableAnnotationMetadata
All Implemented Interfaces:
AnnotationMetadata, AnnotationSource, Cloneable

public class MutableAnnotationMetadata extends DefaultAnnotationMetadata
A mutable various of DefaultAnnotationMetadata that is used only at build time.
Since:
2.4.0
Author:
graemerocher
  • Constructor Details

    • MutableAnnotationMetadata

      public MutableAnnotationMetadata()
      Default constructor.
  • Method Details

    • of

      public static MutableAnnotationMetadata of(AnnotationMetadata annotationMetadata)
    • hasPropertyExpressions

      public boolean hasPropertyExpressions()
      Description copied from interface: AnnotationMetadata
      Does the metadata contain any property expressions like ${foo.bar}. Note this by default returns true as previous versions of Micronaut must assume metadata is present. The compilation time this is computed in order to decide whether to instrument annotation metadata with environment specific logic.
      Specified by:
      hasPropertyExpressions in interface AnnotationMetadata
      Overrides:
      hasPropertyExpressions in class DefaultAnnotationMetadata
      Returns:
      True if property expressions are present
    • hasEvaluatedExpressions

      public boolean hasEvaluatedExpressions()
      Description copied from interface: AnnotationMetadata
      Does the metadata contain any evaluated expressions like #{ T(java.lang.Math).random() }.
      Specified by:
      hasEvaluatedExpressions in interface AnnotationMetadata
      Overrides:
      hasEvaluatedExpressions in class DefaultAnnotationMetadata
      Returns:
      True if evaluated expressions are present
    • clone

      public MutableAnnotationMetadata clone()
      Overrides:
      clone in class DefaultAnnotationMetadata
    • getDefaultValues

      @NonNull public @NonNull Map<CharSequence,Object> getDefaultValues(@NonNull @NonNull String annotation)
      Description copied from interface: AnnotationMetadata
      Return the default values for the given annotation name.
      Specified by:
      getDefaultValues in interface AnnotationMetadata
      Overrides:
      getDefaultValues in class DefaultAnnotationMetadata
      Parameters:
      annotation - The annotation name
      Returns:
      The default values
    • addAnnotation

      public void addAnnotation(String annotation, Map<CharSequence,Object> values)
      Adds an annotation and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      annotation - The annotation
      values - The values
    • addAnnotation

      public void addAnnotation(String annotation, Map<CharSequence,Object> values, RetentionPolicy retentionPolicy)
      Adds an annotation and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      annotation - The annotation
      values - The values
      retentionPolicy - The retention policy
    • addDefaultAnnotationValues

      public final void addDefaultAnnotationValues(String annotation, Map<CharSequence,Object> values)
      Adds an annotation directly declared on the element and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      annotation - The annotation
      values - The values
    • addDefaultAnnotationValues

      public final void addDefaultAnnotationValues(String annotation, Map<CharSequence,Object> values, RetentionPolicy retentionPolicy)
      Adds an annotation directly declared on the element and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      annotation - The annotation
      values - The values
      retentionPolicy - The retention policy
    • addRepeatable

      public void addRepeatable(String annotationName, AnnotationValue<?> annotationValue)
      Adds a repeatable annotation value. If a value already exists will be added
      Parameters:
      annotationName - The annotation name
      annotationValue - The annotation value
    • addRepeatable

      public void addRepeatable(String annotationName, AnnotationValue<?> annotationValue, RetentionPolicy retentionPolicy)
      Adds a repeatable annotation value. If a value already exists will be added
      Parameters:
      annotationName - The annotation name
      annotationValue - The annotation value
      retentionPolicy - The retention policy
    • addRepeatableStereotype

      public void addRepeatableStereotype(List<String> parents, String stereotype, AnnotationValue<?> annotationValue)
      Adds a repeatable stereotype value. If a value already exists will be added
      Parameters:
      parents - The parent annotations
      stereotype - The annotation name
      annotationValue - The annotation value
    • addDeclaredRepeatableStereotype

      public void addDeclaredRepeatableStereotype(List<String> parents, String stereotype, AnnotationValue<?> annotationValue)
      Adds a repeatable declared stereotype value. If a value already exists will be added
      Parameters:
      parents - The parent annotations
      stereotype - The annotation name
      annotationValue - The annotation value
    • addDeclaredRepeatable

      public void addDeclaredRepeatable(String annotationName, AnnotationValue<?> annotationValue)
      Adds a repeatable annotation value. If a value already exists will be added
      Parameters:
      annotationName - The annotation name
      annotationValue - The annotation value
    • addDeclaredRepeatable

      public void addDeclaredRepeatable(String annotationName, AnnotationValue<?> annotationValue, RetentionPolicy retentionPolicy)
      Adds a repeatable annotation value. If a value already exists will be added
      Parameters:
      annotationName - The annotation name
      annotationValue - The annotation value
      retentionPolicy - The retention policy
    • addStereotype

      public final void addStereotype(List<String> parentAnnotations, String stereotype, Map<CharSequence,Object> values)
      Adds a stereotype and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      parentAnnotations - The parent annotations
      stereotype - The annotation
      values - The values
    • addStereotype

      public final void addStereotype(List<String> parentAnnotations, String stereotype, Map<CharSequence,Object> values, RetentionPolicy retentionPolicy)
      Adds a stereotype and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      parentAnnotations - The parent annotations
      stereotype - The annotation
      values - The values
      retentionPolicy - The retention policy
    • addDeclaredStereotype

      public void addDeclaredStereotype(List<String> parentAnnotations, String stereotype, Map<CharSequence,Object> values)
      Adds a stereotype and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      parentAnnotations - The parent annotations
      stereotype - The annotation
      values - The values
    • addDeclaredStereotype

      public void addDeclaredStereotype(List<String> parentAnnotations, String stereotype, Map<CharSequence,Object> values, RetentionPolicy retentionPolicy)
      Adds a stereotype and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      parentAnnotations - The parent annotations
      stereotype - The annotation
      values - The values
      retentionPolicy - The retention policy
    • addDeclaredAnnotation

      public void addDeclaredAnnotation(String annotation, Map<CharSequence,Object> values)
      Adds an annotation directly declared on the element and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      annotation - The annotation
      values - The values
    • addDeclaredAnnotation

      public void addDeclaredAnnotation(String annotation, Map<CharSequence,Object> values, RetentionPolicy retentionPolicy)
      Adds an annotation directly declared on the element and its member values, if the annotation already exists the data will be merged with existing values replaced.
      Parameters:
      annotation - The annotation
      values - The values
      retentionPolicy - The retention policy
    • mutateMember

      @Internal public static MutableAnnotationMetadata mutateMember(MutableAnnotationMetadata annotationMetadata, String annotationName, String member, Object value)

      Sets a member of the given AnnotationMetadata return a new annotation metadata instance without mutating the existing.

      WARNING: for internal use only be the framework

      Parameters:
      annotationMetadata - The metadata
      annotationName - The annotation name
      member - The member
      value - The value
      Returns:
      The metadata
    • newAnnotationValue

      protected <T extends Annotation> AnnotationValue<T> newAnnotationValue(String annotationType, Map<CharSequence,Object> values)
      Overrides:
      newAnnotationValue in class DefaultAnnotationMetadata
    • addAnnotationMetadata

      @Internal public void addAnnotationMetadata(DefaultAnnotationMetadata annotationMetadata)
      Include the annotation metadata from the other instance of DefaultAnnotationMetadata.
      Parameters:
      annotationMetadata - The annotation metadata
      Since:
      4.0.0
    • addAnnotationMetadata

      @Internal public void addAnnotationMetadata(MutableAnnotationMetadata annotationMetadata)
      Include the annotation metadata from the other instance of DefaultAnnotationMetadata.
      Parameters:
      annotationMetadata - The annotation metadata
      Since:
      4.0.0
    • contributeDefaults

      @Internal public static void contributeDefaults(AnnotationMetadata target, AnnotationMetadata source)
      Contributes defaults to the given target.

      WARNING: for internal use only be the framework

      Parameters:
      target - The target
      source - The source
    • contributeDefaults

      @Internal public static void contributeDefaults(AnnotationMetadata target, AnnotationMetadataHierarchy source)
      Contributes defaults to the given target.

      WARNING: for internal use only be the framework

      Parameters:
      target - The target
      source - The source
      Since:
      4.0.0
    • contributeRepeatable

      @Internal public static void contributeRepeatable(AnnotationMetadata target, AnnotationMetadata source)
      Contributes repeatable annotation metadata to the given target.

      WARNING: for internal use only be the framework

      Parameters:
      target - The target
      source - The source
    • mutateMember

      @Internal public static MutableAnnotationMetadata mutateMember(MutableAnnotationMetadata annotationMetadata, String annotationName, Map<CharSequence,Object> members)

      Sets a member of the given AnnotationMetadata return a new annotation metadata instance without mutating the existing.

      WARNING: for internal use only be the framework

      Parameters:
      annotationMetadata - The metadata
      annotationName - The annotation name
      members - The key/value set of members and values
      Returns:
      The metadata
    • removeAnnotationIf

      public <A extends Annotation> void removeAnnotationIf(@NonNull @NonNull Predicate<AnnotationValue<A>> predicate)
      Removes an annotation for the given predicate.
      Type Parameters:
      A - The annotation
      Parameters:
      predicate - The predicate
    • removeAnnotation

      public void removeAnnotation(String annotationType)
      Removes an annotation for the given annotation type.
      Parameters:
      annotationType - The annotation type
      Since:
      3.0.0
    • removeStereotype

      public void removeStereotype(String annotationType)
      Removes a stereotype annotation for the given annotation type.
      Parameters:
      annotationType - The annotation type
      Since:
      3.0.0
    • findRepeatableAnnotationContainerInternal

      protected String findRepeatableAnnotationContainerInternal(String annotation)
      Description copied from class: DefaultAnnotationMetadata
      Find annotation's repeatable container.
      Overrides:
      findRepeatableAnnotationContainerInternal in class DefaultAnnotationMetadata
      Parameters:
      annotation - The annotation
      Returns:
      the repeatable container or null
    • synthesize

      @Nullable public <T extends Annotation> T synthesize(@NonNull @NonNull Class<T> annotationClass)
      Description copied from interface: AnnotationSource
      Synthesizes a new annotation from the metadata for the given annotation type. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.
      Specified by:
      synthesize in interface AnnotationSource
      Type Parameters:
      T - The annotation generic type
      Parameters:
      annotationClass - The annotation class
      Returns:
      The annotation or null if it doesn't exist
    • synthesize

      @Nullable public <T extends Annotation> T synthesize(@NonNull @NonNull Class<T> annotationClass, @NonNull @NonNull String sourceAnnotation)
      Description copied from interface: AnnotationSource
      Synthesizes a new annotation for the given annotation type using the member values of the given source annotation.

      This method allows supporting synthesizing annotations that have been renamed, for example a jakarta.inject.Named annotation an be synthesized from the metadata of the a jakarta.inject.Named annotation.

      Specified by:
      synthesize in interface AnnotationSource
      Type Parameters:
      T - The annotation generic type
      Parameters:
      annotationClass - The annotation class
      sourceAnnotation - The source annotation that provides the member values
      Returns:
      The annotation or null if it doesn't exist
    • synthesizeDeclared

      @Nullable public <T extends Annotation> T synthesizeDeclared(@NonNull @NonNull Class<T> annotationClass, @NonNull @NonNull String sourceAnnotation)
      Description copied from interface: AnnotationSource
      Synthesizes a new annotation declared for the given annotation type using the member values of the given source annotation.

      This method allows supporting synthesizing annotations that have been renamed, for example a jakarta.inject.Named annotation an be synthesized from the metadata of the a jakarta.inject.Named annotation.

      Specified by:
      synthesizeDeclared in interface AnnotationSource
      Type Parameters:
      T - The annotation generic type
      Parameters:
      annotationClass - The annotation class
      sourceAnnotation - The source annotation that provides the member values
      Returns:
      The annotation or null if it doesn't exist
    • synthesizeDeclared

      @Nullable public <T extends Annotation> T synthesizeDeclared(@NonNull @NonNull Class<T> annotationClass)
      Description copied from interface: AnnotationSource
      Synthesizes a new annotation from the metadata for the given annotation type. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.

      This method ignores inherited annotations. (Returns null if no annotations are directly present on this element.)

      Specified by:
      synthesizeDeclared in interface AnnotationSource
      Type Parameters:
      T - The annotation generic type
      Parameters:
      annotationClass - The annotation class
      Returns:
      The annotation or null if it doesn't exist
    • synthesizeAll

      @NonNull public @NonNull Annotation[] synthesizeAll()
      Description copied from interface: AnnotationSource
      Synthesizes a new annotations from the metadata. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.
      Specified by:
      synthesizeAll in interface AnnotationSource
      Returns:
      All the annotations
    • synthesizeDeclared

      @NonNull public @NonNull Annotation[] synthesizeDeclared()
      Description copied from interface: AnnotationSource
      Synthesizes a new annotations from the metadata. This method works by creating a runtime proxy of the annotation interface and should be avoided in favour of direct use of the annotation metadata and only used for unique cases that require integrating third party libraries.
      Specified by:
      synthesizeDeclared in interface AnnotationSource
      Returns:
      All declared annotations