Class AnnotationUtils


  • @Internal
    public class AnnotationUtils
    extends java.lang.Object
    Utility methods for annotations.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AnnotationUtils​(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.util.Elements elementUtils, javax.annotation.processing.Messager messager, javax.lang.model.util.Types types, ModelUtils modelUtils, GenericUtils genericUtils, javax.annotation.processing.Filer filer)
      Default constructor.
      protected AnnotationUtils​(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.util.Elements elementUtils, javax.annotation.processing.Messager messager, javax.lang.model.util.Types types, ModelUtils modelUtils, GenericUtils genericUtils, javax.annotation.processing.Filer filer, io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object> visitorAttributes)
      Default constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata​(java.util.List<javax.lang.model.element.Element> parents, javax.lang.model.element.Element element)
      Get the annotation metadata for the given element and the given parents.
      io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata​(javax.lang.model.element.Element element)
      Get the annotation metadata for the given element.
      io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata​(javax.lang.model.element.Element parent, javax.lang.model.element.Element element)
      Get the annotation metadata for the given element and the given parent.
      io.micronaut.core.annotation.AnnotationMetadata getDeclaredAnnotationMetadata​(javax.lang.model.element.Element element)
      Get the declared annotation metadata for the given element.
      io.micronaut.inject.annotation.AnnotatedElementValidator getElementValidator()
      The AnnotatedElementValidator instance.
      protected boolean hasStereotype​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> stereotype)
      Return whether the given element is annotated with the given annotation stereotype.
      protected boolean hasStereotype​(javax.lang.model.element.Element element, java.lang.String... stereotypes)
      Return whether the given element is annotated with the given annotation stereotypes.
      protected boolean hasStereotype​(javax.lang.model.element.Element element, java.util.List<java.lang.String> stereotypes)
      Return whether the given element is annotated with any of the given annotation stereotypes.
      static void invalidateMetadata​(javax.lang.model.element.Element element)
      Invalidates any cached metadata.
      boolean isAnnotated​(java.lang.String declaringType, javax.lang.model.element.ExecutableElement method)
      Check whether the method is annotated.
      JavaAnnotationMetadataBuilder newAnnotationBuilder()
      Creates a new annotation builder.
      JavaVisitorContext newVisitorContext()
      Creates a new JavaVisitorContext.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AnnotationUtils

        protected AnnotationUtils​(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                  javax.lang.model.util.Elements elementUtils,
                                  javax.annotation.processing.Messager messager,
                                  javax.lang.model.util.Types types,
                                  ModelUtils modelUtils,
                                  GenericUtils genericUtils,
                                  javax.annotation.processing.Filer filer,
                                  io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object> visitorAttributes)
        Default constructor.
        Parameters:
        processingEnv - The processing env
        elementUtils - The elements
        messager - The messager
        types - The types
        modelUtils - The model utils
        genericUtils - The generic utils
        filer - The filer
        visitorAttributes - The visitor attributes
      • AnnotationUtils

        protected AnnotationUtils​(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                  javax.lang.model.util.Elements elementUtils,
                                  javax.annotation.processing.Messager messager,
                                  javax.lang.model.util.Types types,
                                  ModelUtils modelUtils,
                                  GenericUtils genericUtils,
                                  javax.annotation.processing.Filer filer)
        Default constructor.
        Parameters:
        processingEnv - The processing env
        elementUtils - The elements
        messager - The messager
        types - The types
        modelUtils - The model utils
        genericUtils - The generic utils
        filer - The filer
    • Method Detail

      • getElementValidator

        @Nullable
        public io.micronaut.inject.annotation.AnnotatedElementValidator getElementValidator()
        The AnnotatedElementValidator instance. Can be null.
        Returns:
        The validator instance
      • hasStereotype

        protected boolean hasStereotype​(javax.lang.model.element.Element element,
                                        java.lang.Class<? extends java.lang.annotation.Annotation> stereotype)
        Return whether the given element is annotated with the given annotation stereotype.
        Parameters:
        element - The element
        stereotype - The stereotype
        Returns:
        True if it is
      • hasStereotype

        protected boolean hasStereotype​(javax.lang.model.element.Element element,
                                        java.lang.String... stereotypes)
        Return whether the given element is annotated with the given annotation stereotypes.
        Parameters:
        element - The element
        stereotypes - The stereotypes
        Returns:
        True if it is
      • hasStereotype

        protected boolean hasStereotype​(javax.lang.model.element.Element element,
                                        java.util.List<java.lang.String> stereotypes)
        Return whether the given element is annotated with any of the given annotation stereotypes.
        Parameters:
        element - The element
        stereotypes - The stereotypes
        Returns:
        True if it is
      • getAnnotationMetadata

        public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata​(javax.lang.model.element.Element element)
        Get the annotation metadata for the given element.
        Parameters:
        element - The element
        Returns:
        The AnnotationMetadata
      • getDeclaredAnnotationMetadata

        public io.micronaut.core.annotation.AnnotationMetadata getDeclaredAnnotationMetadata​(javax.lang.model.element.Element element)
        Get the declared annotation metadata for the given element.
        Parameters:
        element - The element
        Returns:
        The AnnotationMetadata
      • getAnnotationMetadata

        public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata​(javax.lang.model.element.Element parent,
                                                                                     javax.lang.model.element.Element element)
        Get the annotation metadata for the given element and the given parent. This method is used for cases when you need to combine annotation metadata for two elements, for example a JavaBean property where the field and the method metadata need to be combined.
        Parameters:
        parent - The parent
        element - The element
        Returns:
        The AnnotationMetadata
      • getAnnotationMetadata

        public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata​(java.util.List<javax.lang.model.element.Element> parents,
                                                                                     javax.lang.model.element.Element element)
        Get the annotation metadata for the given element and the given parents. This method is used for cases when you need to combine annotation metadata for two elements, for example a JavaBean property where the field and the method metadata need to be combined.
        Parameters:
        parents - The parents
        element - The element
        Returns:
        The AnnotationMetadata
      • isAnnotated

        public boolean isAnnotated​(java.lang.String declaringType,
                                   javax.lang.model.element.ExecutableElement method)
        Check whether the method is annotated.
        Parameters:
        declaringType - The declaring type
        method - The method
        Returns:
        True if it is annotated with non internal annotations
      • invalidateMetadata

        @Internal
        public static void invalidateMetadata​(javax.lang.model.element.Element element)
        Invalidates any cached metadata.
        Parameters:
        element - The element