Package io.micronaut.aot.core
Interface AOTContext
- All Known Implementing Classes:
DefaultSourceGenerationContext
,DelegatingSourceGenerationContext
public interface AOTContext
The source generation context is used by source generators
to get configuration details. It is also used as the communication
medium between source generators when one depends on the other.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDiagnostics
(String category, String message) Adds a diagnostic message, which is going to be written in a log file.<T> @NonNull Optional<T>
Reads an entry from the context.@NonNull ApplicationContextAnalyzer
Returns the application context analyzer.@NonNull Configuration
Returns the source generators configuration.Returns the diagnostics map.@NonNull String
The package which should be used for generated classes.@NonNull Runtime
Returns the target runtime environment.@NonNull com.squareup.javapoet.JavaFile
javaFile
(com.squareup.javapoet.TypeSpec typeSpec) Generates a java file spec.<T> void
Stores an entry in the context.void
registerClassNeededAtCompileTime
(@NonNull Class<?> clazz) Registers a class as needed at compile time (where compile time is the compile time of generated classes).void
registerExcludedResource
(@NonNull String path) Registers a resource path as excluded.void
registerGeneratedResource
(@NonNull String path, Consumer<? super File> consumer) Registers a new generated resource.void
registerGeneratedSourceFile
(@NonNull com.squareup.javapoet.JavaFile javaFile) Registers a generated source file.void
registerServiceImplementation
(Class<?> serviceType, String simpleServiceName) Registers a generated service type.void
registerStaticInitializer
(com.squareup.javapoet.MethodSpec staticInitializer) Registers a code block to be executed statically when the optimized binary is loaded.<T> void
registerStaticOptimization
(String className, Class<T> optimizationKind, Consumer<? super com.squareup.javapoet.CodeBlock.Builder> bodyBuilder) Registers a static optimization method.
-
Method Details
-
getPackageName
The package which should be used for generated classes.- Returns:
- the package name
-
getConfiguration
Returns the source generators configuration.- Returns:
- the configuration
-
getAnalyzer
Returns the application context analyzer.- Returns:
- the application context analyzer
-
registerGeneratedSourceFile
void registerGeneratedSourceFile(@NonNull @NonNull com.squareup.javapoet.JavaFile javaFile) Registers a generated source file.- Parameters:
javaFile
- the file to be added.
-
registerStaticInitializer
void registerStaticInitializer(com.squareup.javapoet.MethodSpec staticInitializer) Registers a code block to be executed statically when the optimized binary is loaded.- Parameters:
staticInitializer
- the static initializer method
-
registerStaticOptimization
<T> void registerStaticOptimization(String className, Class<T> optimizationKind, Consumer<? super com.squareup.javapoet.CodeBlock.Builder> bodyBuilder) Registers a static optimization method. This will automatically create a class which implements theStaticOptimizations
service type. The consumer should create a body which returns an instance of the optimization type.- Type Parameters:
T
- the type class of the optimization- Parameters:
className
- the name of the class to generateoptimizationKind
- the type of the optimizationbodyBuilder
- the builder of the body of the load() method
-
registerServiceImplementation
Registers a generated service type.- Parameters:
serviceType
- the type of the servicesimpleServiceName
- the simple name of the generated type
-
registerGeneratedResource
Registers a new generated resource.- Parameters:
path
- the relative path to the resource (including file name)consumer
- the consumer to be called when the resource is generated.
-
registerExcludedResource
Registers a resource path as excluded. Excluded resources should be removed, as much as possible, from the final binary/deliverable since they are either not used or substituted with code.- Parameters:
path
- the path of the resource to exclude
-
registerClassNeededAtCompileTime
Registers a class as needed at compile time (where compile time is the compile time of generated classes). This will typically be used when source generators need classes which are not on the application classpath.- Parameters:
clazz
- a class
-
javaFile
@NonNull @NonNull com.squareup.javapoet.JavaFile javaFile(com.squareup.javapoet.TypeSpec typeSpec) Generates a java file spec.- Parameters:
typeSpec
- the type spec of the main class- Returns:
- a java file
-
addDiagnostics
Adds a diagnostic message, which is going to be written in a log file.- Parameters:
category
- a category for the message, typically corresponding to the source generator typemessage
- a message to log
-
put
Stores an entry in the context. The entry may be read by other processors, as long as they are executed in the proper order.- Type Parameters:
T
- the type of the value- Parameters:
type
- the class of the value to storevalue
- the value to store
-
get
Reads an entry from the context.- Type Parameters:
T
- the type of the entry- Parameters:
type
- the class of the entry- Returns:
- an empty value if absent
-
getDiagnostics
Returns the diagnostics map.- Returns:
- the diagnostics
-
getRuntime
Returns the target runtime environment.- Returns:
- target runtime
-