Package io.micronaut.aot.core.context
Class DefaultSourceGenerationContext
java.lang.Object
io.micronaut.aot.core.context.DefaultSourceGenerationContext
- All Implemented Interfaces:
- AOTContext
The source generation context.
 Typically provides access to the application classloader or the name of
 the package of classes which are going to be generated.
 In addition, the context can be used to register resources which will need
 to be excluded from the final binary (e.g if a configuration file is replaced
 with a class at build time, we need a way to explain that the resource file
 needs to be excluded from the binary).
 Last but not least, this context can be used to send diagnostic messages
 which are written to log files during code generation.
- 
Constructor SummaryConstructorsConstructorDescriptionDefaultSourceGenerationContext(String packageName, ApplicationContextAnalyzer analyzer, Configuration configuration, Path generatedResourcesDirectory) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddDiagnostics(String category, String message) Adds a diagnostic message, which is going to be written in a log file.voidfinish()Performs actions which have to be done as late as possible during source generation.<T> @NonNull Optional<T>Reads an entry from the context.@NonNull ApplicationContextAnalyzerReturns the application context analyzer.Returns the set of classes which require build time initialization@NonNull ConfigurationReturns the source generators configuration.Returns the diagnostics map.Returns the list of resources to be excluded from the binary.List<com.squareup.javapoet.JavaFile>List<com.squareup.javapoet.MethodSpec>@NonNull StringThe package which should be used for generated classes.@NonNull RuntimeReturns the target runtime environment.@NonNull com.squareup.javapoet.JavaFilejavaFile(com.squareup.javapoet.TypeSpec typeSpec) Generates a java file spec.<T> voidStores an entry in the context.voidregisterBuildTimeInit(String className) Registers a type as a requiring initialization at build time.voidregisterClassNeededAtCompileTime(@NonNull Class<?> clazz) Registers a class as needed at compile time (where compile time is the compile time of generated classes).voidregisterExcludedResource(@NonNull String path) Registers a resource path as excluded.voidregisterGeneratedResource(@NonNull String path, Consumer<? super File> consumer) Registers a new generated resource.voidregisterGeneratedSourceFile(@NonNull com.squareup.javapoet.JavaFile javaFile) Registers a generated source file.voidregisterServiceImplementation(Class<?> serviceType, String simpleServiceName) Registers a generated service type.voidregisterStaticInitializer(com.squareup.javapoet.MethodSpec staticInitializer) Registers a code block to be executed statically when the optimized binary is loaded.<T> voidregisterStaticOptimization(String className, Class<T> optimizationKind, Consumer<? super com.squareup.javapoet.CodeBlock.Builder> bodyBuilder) Registers a static optimization method.
- 
Constructor Details- 
DefaultSourceGenerationContextpublic DefaultSourceGenerationContext(String packageName, ApplicationContextAnalyzer analyzer, Configuration configuration, Path generatedResourcesDirectory) 
 
- 
- 
Method Details- 
getPackageNameDescription copied from interface:AOTContextThe package which should be used for generated classes.- Specified by:
- getPackageNamein interface- AOTContext
- Returns:
- the package name
 
- 
getRuntimeDescription copied from interface:AOTContextReturns the target runtime environment.- Specified by:
- getRuntimein interface- AOTContext
- Returns:
- target runtime
 
- 
getConfigurationDescription copied from interface:AOTContextReturns the source generators configuration.- Specified by:
- getConfigurationin interface- AOTContext
- Returns:
- the configuration
 
- 
getAnalyzerDescription copied from interface:AOTContextReturns the application context analyzer.- Specified by:
- getAnalyzerin interface- AOTContext
- Returns:
- the application context analyzer
 
- 
registerExcludedResourceDescription copied from interface:AOTContextRegisters 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.- Specified by:
- registerExcludedResourcein interface- AOTContext
- Parameters:
- path- the path of the resource to exclude
 
- 
registerClassNeededAtCompileTimeDescription copied from interface:AOTContextRegisters 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.- Specified by:
- registerClassNeededAtCompileTimein interface- AOTContext
- Parameters:
- clazz- a class
 
- 
registerGeneratedSourceFilepublic void registerGeneratedSourceFile(@NonNull @NonNull com.squareup.javapoet.JavaFile javaFile) Description copied from interface:AOTContextRegisters a generated source file.- Specified by:
- registerGeneratedSourceFilein interface- AOTContext
- Parameters:
- javaFile- the file to be added.
 
- 
getGeneratedJavaFiles
- 
registerStaticInitializerpublic void registerStaticInitializer(com.squareup.javapoet.MethodSpec staticInitializer) Description copied from interface:AOTContextRegisters a code block to be executed statically when the optimized binary is loaded.- Specified by:
- registerStaticInitializerin interface- AOTContext
- Parameters:
- staticInitializer- the static initializer method
 
- 
registerStaticOptimizationpublic <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 theStaticOptimizationsservice type. The consumer should create a body which returns an instance of the optimization type.- Specified by:
- registerStaticOptimizationin interface- AOTContext
- Type Parameters:
- T- the type class of the optimization
- Parameters:
- className- the name of the class to generate
- optimizationKind- the type of the optimization
- bodyBuilder- the builder of the body of the load() method
 
- 
registerServiceImplementationRegisters a generated service type.- Specified by:
- registerServiceImplementationin interface- AOTContext
- Parameters:
- serviceType- the type of the service
- simpleServiceName- the simple name of the generated type
 
- 
getGeneratedStaticInitializers
- 
registerGeneratedResourcepublic void registerGeneratedResource(@NonNull @NonNull String path, Consumer<? super File> consumer) Description copied from interface:AOTContextRegisters a new generated resource.- Specified by:
- registerGeneratedResourcein interface- AOTContext
- Parameters:
- path- the relative path to the resource (including file name)
- consumer- the consumer to be called when the resource is generated.
 
- 
getExtraClasspath
- 
registerBuildTimeInitDescription copied from interface:AOTContextRegisters a type as a requiring initialization at build time.- Specified by:
- registerBuildTimeInitin interface- AOTContext
- Parameters:
- className- the type
 
- 
getExcludedResourcesReturns the list of resources to be excluded from the binary.- Returns:
- the list of resources registered to be excluded.
- See Also:
 
- 
javaFile@NonNull public @NonNull com.squareup.javapoet.JavaFile javaFile(com.squareup.javapoet.TypeSpec typeSpec) Description copied from interface:AOTContextGenerates a java file spec.- Specified by:
- javaFilein interface- AOTContext
- Parameters:
- typeSpec- the type spec of the main class
- Returns:
- a java file
 
- 
addDiagnosticsDescription copied from interface:AOTContextAdds a diagnostic message, which is going to be written in a log file.- Specified by:
- addDiagnosticsin interface- AOTContext
- Parameters:
- category- a category for the message, typically corresponding to the source generator type
- message- a message to log
 
- 
putDescription copied from interface:AOTContextStores an entry in the context. The entry may be read by other processors, as long as they are executed in the proper order.- Specified by:
- putin interface- AOTContext
- Type Parameters:
- T- the type of the value
- Parameters:
- type- the class of the value to store
- value- the value to store
 
- 
getDescription copied from interface:AOTContextReads an entry from the context.- Specified by:
- getin interface- AOTContext
- Type Parameters:
- T- the type of the entry
- Parameters:
- type- the class of the entry
- Returns:
- an empty value if absent
 
- 
getDiagnosticsDescription copied from interface:AOTContextReturns the diagnostics map.- Specified by:
- getDiagnosticsin interface- AOTContext
- Returns:
- the diagnostics
 
- 
getBuildTimeInitClassesDescription copied from interface:AOTContextReturns the set of classes which require build time initialization- Specified by:
- getBuildTimeInitClassesin interface- AOTContext
- Returns:
- the set of classes needing build time init
 
- 
finishpublic void finish()Description copied from interface:AOTContextPerforms actions which have to be done as late as possible during source generation.- Specified by:
- finishin interface- AOTContext
 
 
-