Class PythonAnnotationProcessor

All Implemented Interfaces:
AutoCloseable, Processor

@SupportedAnnotationTypes("io.micronaut.context.python.annotation.PythonApplication") @SupportedOptions({"micronaut.python.source.root","micronaut.python.exclude","micronaut.introspection.allowReflection","micronaut.python.reflection.warnings","micronaut.python.pool.ignoreDependencies"}) public class PythonAnnotationProcessor extends AbstractInjectAnnotationProcessor implements AutoCloseable
Annotation processor for io.micronaut.context.python.annotation.PythonApplication that enables Python AST processing during Java compilation.

The SupportedOptions declaration is what makes those options configurable by a build tool rather than only by a hand-written -A flag: a tool that reads an option out of an application's own configuration has to know which options exist, and it discovers them by asking each registered processor. The options below are declared by this processor's TypeElementVisitors, which a tool enumerating processors never sees; TypeElementVisitorProcessor aggregates its visitors' options for the same reason, and this processor loads its visitors too late in a round to do that dynamically.

Since:
5.2.0
Author:
Micronaut
  • Field Details

    • APPLICATION_PATH

      public static final String APPLICATION_PATH
      See Also:
    • APPLICATION_SRC_PATH

      public static final String APPLICATION_SRC_PATH
      See Also:
    • SOURCE_ROOT_OPTION

      public static final String SOURCE_ROOT_OPTION
      The compiler option naming the directory that relative @PythonApplication(src = ...) directories are resolved against. Without it they resolve against the working directory.
      See Also:
    • APPLICATION_LAUNCHER_PATH

      public static final String APPLICATION_LAUNCHER_PATH
      See Also:
    • PACKAGE_MEMBERS_MODULE_PREFIX

      public static final String PACKAGE_MEMBERS_MODULE_PREFIX
      The prefix of the modules through which a compilation contributes members to a package (or, at the root of the sources, to the launcher). The main and the test sources of a project, or an application and a library, are compiled separately into virtual file system roots that share one namespace at run time, where a file present in several roots is served from one of them. A package initialiser therefore carries no members itself: every compilation writes them to a module named after a hash of its content, and the initialiser, identical in every root, merges the modules it finds.
      See Also:
    • JAVA_IMPORTS_MANIFEST_PREFIX

      public static final String JAVA_IMPORTS_MANIFEST_PREFIX
      The prefix of the manifests naming the Java packages, types and annotations a compilation's Python sources import, which the runtime serves as modules without generated files.
      See Also:
  • Constructor Details

    • PythonAnnotationProcessor

      public PythonAnnotationProcessor()
  • Method Details

    • setClassElementCallback

      public void setClassElementCallback(Consumer<ClassElement> callback)
      Set the callback to be invoked for each class element created during processing. This is primarily used for testing purposes.
      Parameters:
      callback - The callback function
    • setPythonSourceVisitors

      public void setPythonSourceVisitors(List<PythonSourceVisitor> pythonSourceVisitors)
      Sets visitors for Python source metadata in this compilation.
      Parameters:
      pythonSourceVisitors - the visitors
    • setCompilePythonBytecode

      public void setCompilePythonBytecode(boolean compilePythonBytecode)
      Set whether generated Python VFS resources should include optional GraalPy bytecode caches. Application sources that require runtime compatibility transformations may include a cache regardless of this setting so that the original source remains available for debugging.
      Parameters:
      compilePythonBytecode - Whether optional bytecode caches should be emitted
      Since:
      5.2.0
    • setIncrementalSources

      @Internal public void setIncrementalSources(Set<String> incrementalSources)
      Restricts isolating visitors and bean generation to affected Python sources.
      Parameters:
      incrementalSources - The affected absolute source paths, or null for all sources
    • setProcessAggregatingVisitors

      @Internal public void setProcessAggregatingVisitors(boolean processAggregatingVisitors)
      Sets whether aggregating Python type visitors should run.
      Parameters:
      processAggregatingVisitors - Whether aggregating visitors should run
    • setOutputDirectory

      @Internal public void setOutputDirectory(Path outputDirectory)
      Sets the class output directory used to reuse unchanged generated Python resources.
      Parameters:
      outputDirectory - The class output directory, or null for in-memory compilation
    • setProfiler

      @Internal public void setProfiler(@Nullable CompilationProfiler profiler)
      Sets the profiler of the compilation, or null when it is not profiled.
      Parameters:
      profiler - The profiler
    • setProcessingSession

      @Internal public void setProcessingSession(PythonProcessingSession processingSession)
      Sets a session that owns the GraalPy context across compiler invocations.
      Parameters:
      processingSession - The reusable processing session
    • init

      public void init(ProcessingEnvironment processingEnv)
      Specified by:
      init in interface Processor
      Overrides:
      init in class AbstractInjectAnnotationProcessor
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • process

      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
      Specified by:
      process in interface Processor
      Specified by:
      process in class AbstractProcessor
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
      Sets the class loader used for in-memory compiler execution.
      Parameters:
      classLoader - The class loader