Class PythonAnnotationProcessor
java.lang.Object
javax.annotation.processing.AbstractProcessor
io.micronaut.annotation.processing.AbstractInjectAnnotationProcessor
io.micronaut.python.processing.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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringThe 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.static final StringThe prefix of the modules through which a compilation contributes members to a package (or, at the root of the sources, to the launcher).static final StringThe compiler option naming the directory that relative@PythonApplication(src = ...)directories are resolved against.Fields inherited from class AbstractInjectAnnotationProcessor
classWriterOutputVisitor, elementUtils, filer, GRADLE_PROCESSING_AGGREGATING, GRADLE_PROCESSING_ISOLATING, javaVisitorContext, messager, MICRONAUT_PROCESSING_ANNOTATIONS, MICRONAUT_PROCESSING_INCREMENTAL, modelUtils, postponedTypes, typeUtils, visitorAttributesFields inherited from class AbstractProcessor
processingEnv -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidinit(ProcessingEnvironment processingEnv) booleanprocess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) voidsetClassElementCallback(Consumer<ClassElement> callback) Set the callback to be invoked for each class element created during processing.voidsetClassLoader(ClassLoader classLoader) Sets the class loader used for in-memory compiler execution.voidsetCompilePythonBytecode(boolean compilePythonBytecode) Set whether generated Python VFS resources should include optional GraalPy bytecode caches.voidsetIncrementalSources(Set<String> incrementalSources) Restricts isolating visitors and bean generation to affected Python sources.voidsetOutputDirectory(Path outputDirectory) Sets the class output directory used to reuse unchanged generated Python resources.voidsetProcessAggregatingVisitors(boolean processAggregatingVisitors) Sets whether aggregating Python type visitors should run.voidsetProcessingSession(PythonProcessingSession processingSession) Sets a session that owns the GraalPy context across compiler invocations.voidsetProfiler(@Nullable CompilationProfiler profiler) Sets the profiler of the compilation, or null when it is not profiled.voidsetPythonSourceVisitors(List<PythonSourceVisitor> pythonSourceVisitors) Sets visitors for Python source metadata in this compilation.Methods inherited from class AbstractInjectAnnotationProcessor
error, error, getIncrementalProcessorType, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, getVisitorKind, isIncremental, isProcessedAnnotation, newVisitorContext, note, note, processingGeneratedAnnotation, warning, warningMethods inherited from class AbstractProcessor
getCompletions, isInitialized
-
Field Details
-
APPLICATION_PATH
- See Also:
-
APPLICATION_SRC_PATH
- See Also:
-
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
- See Also:
-
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
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
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
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
-
setProcessAggregatingVisitors
Sets whether aggregating Python type visitors should run.- Parameters:
processAggregatingVisitors- Whether aggregating visitors should run
-
setOutputDirectory
-
setProfiler
Sets the profiler of the compilation, or null when it is not profiled.- Parameters:
profiler- The profiler
-
setProcessingSession
Sets a session that owns the GraalPy context across compiler invocations.- Parameters:
processingSession- The reusable processing session
-
init
- Specified by:
initin interfaceProcessor- Overrides:
initin classAbstractInjectAnnotationProcessor
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
process
- Specified by:
processin interfaceProcessor- Specified by:
processin classAbstractProcessor
-
setClassLoader
Sets the class loader used for in-memory compiler execution.- Parameters:
classLoader- The class loader
-