Interface VisitorContext

All Superinterfaces:
ClassWriterOutputVisitor, ConversionServiceProvider, ConvertibleValues<Object>, Iterable<Map.Entry<String,Object>>, MutableConvertibleValues<Object>, ValueResolver<CharSequence>
All Known Subinterfaces:
BeanElementVisitorContext
All Known Implementing Classes:
GroovyVisitorContext, JavaVisitorContext

public interface VisitorContext extends MutableConvertibleValues<Object>, ClassWriterOutputVisitor
Provides a way for TypeElementVisitor classes to log messages during compilation and fail compilation.
Since:
1.0
Author:
James Kleeh, Graeme Rocher
  • Field Details

  • Method Details

    • getLanguage

      Returns:
      The visitor context's language.
      Since:
      4.2.0
    • getElementFactory

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

      @NonNull @NonNull ElementAnnotationMetadataFactory getElementAnnotationMetadataFactory()
      Gets the element annotation metadata factory.
      Returns:
      The element annotation metadata factory
      Since:
      4.0.0
    • getExpressionCompilationContextFactory

      @NonNull @NonNull ExpressionCompilationContextFactory getExpressionCompilationContextFactory()
      Returns:
      The expression compilation context factory.
      Since:
      4.0.0
    • getAnnotationMetadataBuilder

      @Internal @NonNull @NonNull AbstractAnnotationMetadataBuilder<?,?> getAnnotationMetadataBuilder()
      Gets the annotation metadata builder.
      Returns:
      The annotation metadata builder
      Since:
      4.0.0
    • info

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

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

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

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

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

      Optional<GeneratedFile> visitMetaInfFile(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

      Optional<GeneratedFile> visitGeneratedFile(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 @NonNull Iterable<URL> getClasspathResources(@NonNull @NonNull String path)
      Obtain a set of resources from the user classpath.
      Parameters:
      path - The path
      Returns:
      An iterable of resources
    • getProjectDir

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

      default Optional<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 Optional<ClassElement> getClassElement(String name)
      This method will look up 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 Optional<ClassElement> getClassElement(String name, ElementAnnotationMetadataFactory annotationMetadataFactory)
      This method will look up another class element by name. If it cannot be found an empty optional will be returned.
      Parameters:
      name - The name
      annotationMetadataFactory - The element annotation metadata factory
      Returns:
      The class element
      Since:
      4.0.0
    • getRequiredClassElement

      default ClassElement getRequiredClassElement(String name, ElementAnnotationMetadataFactory annotationMetadataFactory)
      This method will look up another class element by name. If it cannot be found an exception thrown.
      Parameters:
      name - The name
      annotationMetadataFactory - The element annotation metadata factory
      Returns:
      The class element
      Since:
      4.0.0
    • getClassElement

      default Optional<ClassElement> getClassElement(Class<?> type)
      This method will look up 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 @NonNull ClassElement[] getClassElements(@NonNull @NonNull String aPackage, @NonNull @NonNull 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 Map<String,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:
    • getGeneratedResources

      default Collection<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(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