Interface VisitorContext

  • All Superinterfaces:
    ClassWriterOutputVisitor, io.micronaut.core.convert.value.ConvertibleValues<java.lang.Object>, java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.Object>>, io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object>, io.micronaut.core.value.ValueResolver<java.lang.CharSequence>
    All Known Subinterfaces:
    BeanElementVisitorContext

    public interface VisitorContext
    extends io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object>, ClassWriterOutputVisitor
    Provides a way for TypeElementVisitor classes to log messages during compilation and fail compilation.
    Since:
    1.0
    • Field Detail

      • MICRONAUT_BASE_OPTION_NAME

        static final java.lang.String MICRONAUT_BASE_OPTION_NAME
        See Also:
        Constant Field Values
      • MICRONAUT_PROCESSING_PROJECT_DIR

        static final java.lang.String MICRONAUT_PROCESSING_PROJECT_DIR
        See Also:
        Constant Field Values
      • MICRONAUT_PROCESSING_GROUP

        static final java.lang.String MICRONAUT_PROCESSING_GROUP
        See Also:
        Constant Field Values
      • MICRONAUT_PROCESSING_MODULE

        static final java.lang.String MICRONAUT_PROCESSING_MODULE
        See Also:
        Constant Field Values
    • Method Detail

      • getElementFactory

        @NonNull
        ElementFactory<?,​?,​?,​?> getElementFactory()
        Gets the element factory for this visitor context.
        Returns:
        The element factory
        Since:
        2.3.0
      • info

        void info​(java.lang.String message,
                  @Nullable
                  Element element)
        Allows printing informational messages.
        Parameters:
        message - The message
        element - The element
      • info

        void info​(java.lang.String message)
        Allows printing informational messages.
        Parameters:
        message - The message
      • fail

        void fail​(java.lang.String message,
                  @Nullable
                  Element element)
        Allows failing compilation for a given element with the given message.
        Parameters:
        message - The message
        element - The element
      • warn

        void warn​(java.lang.String message,
                  @Nullable
                  Element element)
        Allows printing a warning for the given message and element.
        Parameters:
        message - The message
        element - The element
      • getConfiguration

        @NonNull
        default VisitorConfiguration getConfiguration()
        Returns:
        The visitor configuration
      • visitMetaInfFile

        @Deprecated
        default java.util.Optional<GeneratedFile> visitMetaInfFile​(java.lang.String path)
        Deprecated.
        Visiting a file should supply the originating elements. Use visitMetaInfFile(String, Element...) instead
        Visit a file within the META-INF directory.
        Specified by:
        visitMetaInfFile in interface ClassWriterOutputVisitor
        Parameters:
        path - The path to the file
        Returns:
        An optional file it was possible to create it
      • visitMetaInfFile

        java.util.Optional<GeneratedFile> visitMetaInfFile​(java.lang.String path,
                                                           Element... originatingElements)
        Visit a file within the META-INF directory.
        Specified by:
        visitMetaInfFile in interface ClassWriterOutputVisitor
        Parameters:
        path - The path to the file
        originatingElements - The originating elements
        Returns:
        An optional file it was possible to create it
      • visitGeneratedFile

        java.util.Optional<GeneratedFile> visitGeneratedFile​(java.lang.String path)
        Visit a file that will be located within the generated source directory.
        Specified by:
        visitGeneratedFile in interface ClassWriterOutputVisitor
        Parameters:
        path - The path to the file
        Returns:
        An optional file it was possible to create it
      • getClasspathResources

        @NonNull
        default java.lang.Iterable<java.net.URL> getClasspathResources​(@NonNull
                                                                       java.lang.String path)
        Obtain a set of resources from the user classpath.
        Parameters:
        path - The path
        Returns:
        An iterable of resources
      • getProjectDir

        default java.util.Optional<java.nio.file.Path> getProjectDir()
        Obtain the project directory.
        Returns:
        An optional wrapping the project directory
      • getClassesOutputPath

        default java.util.Optional<java.nio.file.Path> getClassesOutputPath()
        Provide the Path to the annotation processing classes output directory, i.e. the parent of META-INF.

        This might, for example, be used as a convenience for TypeElementVisitor classes to provide relative path strings to addGeneratedResource(String)

         Path resource = ... // absolute path to the resource
         visitorContext.getClassesOutputPath().ifPresent(path ->
             visitorContext.addGeneratedResource(path.relativize(resource).toString()));
         
        Returns:
        Path pointing to the classes output directory
      • getClassElement

        default java.util.Optional<ClassElement> getClassElement​(java.lang.String name)
        This method will lookup another class element by name. If it cannot be found an empty optional will be returned.
        Parameters:
        name - The name
        Returns:
        The class element
      • getClassElement

        default java.util.Optional<ClassElement> getClassElement​(java.lang.Class<?> type)
        This method will lookup another class element by name. If it cannot be found an empty optional will be returned.
        Parameters:
        type - The name
        Returns:
        The class element
      • getClassElements

        @NonNull
        default ClassElement[] getClassElements​(@NonNull
                                                java.lang.String aPackage,
                                                @NonNull
                                                java.lang.String... stereotypes)
        Find all the classes within the given package and having the given annotation.
        Parameters:
        aPackage - The package
        stereotypes - The stereotypes
        Returns:
        The class elements
      • getOptions

        default java.util.Map<java.lang.String,​java.lang.String> getOptions()
        The annotation processor environment custom options.

        All options names MUST start with MICRONAUT_BASE_OPTION_NAME

        Returns:
        A Map with annotation processor runtime options
        See Also:
        ProcessingEnvironment.getOptions()
      • getGeneratedResources

        default java.util.Collection<java.lang.String> getGeneratedResources()
        Provide a collection of generated classpath resources that other TypeElement visitors might want to consume. The generated resources are intended to be strings paths relative to the classpath root.
        Returns:
        a possibly empty collection of resource paths
      • addGeneratedResource

        default void addGeneratedResource​(java.lang.String resource)
        Some TypeElementVisitors generate classpath resources that other visitors might be interested in. The generated resources are intended to be strings paths relative to the classpath root
        Parameters:
        resource - the relative path to add