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 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.Get the excluded service implementations.@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(@NonNull 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.voidregisterExcludedServiceImpl(@NonNull String className, @NonNull String reason) Register an excluded service implementation that is based on another generator and not user input.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.
-
Method Details
-
getPackageName
@NonNull String getPackageName()The package which should be used for generated classes.- Returns:
- the package name
-
getConfiguration
@NonNull Configuration getConfiguration()Returns the source generators configuration.- Returns:
- the configuration
-
getAnalyzer
@NonNull ApplicationContextAnalyzer getAnalyzer()Returns the application context analyzer.- Returns:
- the application context analyzer
-
registerGeneratedSourceFile
void registerGeneratedSourceFile(@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 theStaticOptimizationsservice 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
-
registerGeneratedResource
-
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
-
registerExcludedServiceImpl
Register an excluded service implementation that is based on another generator and not user input. When static service loader is created, this implementation won't be added and therefore won't be loaded.- Parameters:
className- The service implementation classnamereason- The human-readable reason for exclusion
-
getExcludedServiceImplementations
-
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
-
registerBuildTimeInit
Registers a type as a requiring initialization at build time.- Parameters:
className- the type
-
javaFile
@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
-
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
-
getDiagnostics
-
getRuntime
-
getBuildTimeInitClasses
-
finish
void finish()Performs actions which have to be done as late as possible during source generation.
-