public final class DefaultSourceGenerationContext extends java.lang.Object implements AOTContext
| Constructor and Description |
|---|
DefaultSourceGenerationContext(java.lang.String packageName,
ApplicationContextAnalyzer analyzer,
Configuration configuration,
java.nio.file.Path generatedResourcesDirectory) |
| Modifier and Type | Method and Description |
|---|---|
void |
addDiagnostics(java.lang.String category,
java.lang.String message)
Adds a diagnostic message, which is going to be written
in a log file.
|
<T> java.util.Optional<T> |
get(java.lang.Class<T> type)
Reads an entry from the context.
|
ApplicationContextAnalyzer |
getAnalyzer()
Returns the application context analyzer.
|
Configuration |
getConfiguration()
Returns the source generators configuration.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getDiagnostics()
Returns the diagnostics map.
|
java.util.Set<java.lang.String> |
getExcludedResources()
Returns the list of resources to be excluded from
the binary.
|
java.util.List<java.io.File> |
getExtraClasspath() |
java.util.List<com.squareup.javapoet.JavaFile> |
getGeneratedJavaFiles() |
java.util.List<com.squareup.javapoet.MethodSpec> |
getGeneratedStaticInitializers() |
java.lang.String |
getPackageName()
The package which should be used for generated classes.
|
Runtime |
getRuntime()
Returns the target runtime environment.
|
com.squareup.javapoet.JavaFile |
javaFile(com.squareup.javapoet.TypeSpec typeSpec)
Generates a java file spec.
|
<T> void |
put(java.lang.Class<T> type,
T value)
Stores an entry in the context.
|
void |
registerClassNeededAtCompileTime(java.lang.Class<?> clazz)
Registers a class as needed at compile time (where compile time
is the compile time of generated classes).
|
void |
registerExcludedResource(java.lang.String path)
Registers a resource path as excluded.
|
void |
registerGeneratedResource(java.lang.String path,
java.util.function.Consumer<? super java.io.File> consumer)
Registers a new generated resource.
|
void |
registerGeneratedSourceFile(com.squareup.javapoet.JavaFile javaFile)
Registers a generated source file.
|
void |
registerServiceImplementation(java.lang.Class<?> serviceType,
java.lang.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(java.lang.String className,
java.lang.Class<T> optimizationKind,
java.util.function.Consumer<? super com.squareup.javapoet.CodeBlock.Builder> bodyBuilder)
Registers a static optimization method.
|
public DefaultSourceGenerationContext(java.lang.String packageName,
ApplicationContextAnalyzer analyzer,
Configuration configuration,
java.nio.file.Path generatedResourcesDirectory)
@NonNull public java.lang.String getPackageName()
AOTContextgetPackageName in interface AOTContext@NonNull public Runtime getRuntime()
AOTContextgetRuntime in interface AOTContext@NonNull public Configuration getConfiguration()
AOTContextgetConfiguration in interface AOTContext@NonNull public ApplicationContextAnalyzer getAnalyzer()
AOTContextgetAnalyzer in interface AOTContextpublic void registerExcludedResource(@NonNull
java.lang.String path)
AOTContextregisterExcludedResource in interface AOTContextpath - the path of the resource to excludepublic void registerClassNeededAtCompileTime(@NonNull
java.lang.Class<?> clazz)
AOTContextregisterClassNeededAtCompileTime in interface AOTContextclazz - a classpublic void registerGeneratedSourceFile(@NonNull
com.squareup.javapoet.JavaFile javaFile)
AOTContextregisterGeneratedSourceFile in interface AOTContextjavaFile - the file to be added.public java.util.List<com.squareup.javapoet.JavaFile> getGeneratedJavaFiles()
public void registerStaticInitializer(com.squareup.javapoet.MethodSpec staticInitializer)
AOTContextregisterStaticInitializer in interface AOTContextstaticInitializer - the static initializer methodpublic <T> void registerStaticOptimization(java.lang.String className,
java.lang.Class<T> optimizationKind,
java.util.function.Consumer<? super com.squareup.javapoet.CodeBlock.Builder> bodyBuilder)
StaticOptimizations
service type. The consumer should create a body which returns
an instance of the optimization type.registerStaticOptimization in interface AOTContextT - the type class of the optimizationclassName - the name of the class to generateoptimizationKind - the type of the optimizationbodyBuilder - the builder of the body of the load() methodpublic void registerServiceImplementation(java.lang.Class<?> serviceType,
java.lang.String simpleServiceName)
registerServiceImplementation in interface AOTContextserviceType - the type of the servicesimpleServiceName - the simple name of the generated typepublic java.util.List<com.squareup.javapoet.MethodSpec> getGeneratedStaticInitializers()
public void registerGeneratedResource(@NonNull
java.lang.String path,
java.util.function.Consumer<? super java.io.File> consumer)
AOTContextregisterGeneratedResource in interface AOTContextpath - the relative path to the resource (including file name)consumer - the consumer to be called when the resource is generated.@NonNull public java.util.List<java.io.File> getExtraClasspath()
@NonNull public java.util.Set<java.lang.String> getExcludedResources()
AOTContext.registerExcludedResource(java.lang.String)@NonNull public com.squareup.javapoet.JavaFile javaFile(com.squareup.javapoet.TypeSpec typeSpec)
AOTContextjavaFile in interface AOTContexttypeSpec - the type spec of the main classpublic void addDiagnostics(java.lang.String category,
java.lang.String message)
AOTContextaddDiagnostics in interface AOTContextcategory - a category for the message, typically corresponding
to the source generator typemessage - a message to logpublic <T> void put(@NonNull
java.lang.Class<T> type,
@NonNull
T value)
AOTContextput in interface AOTContextT - the type of the valuetype - the class of the value to storevalue - the value to store@NonNull
public <T> java.util.Optional<T> get(@NonNull
java.lang.Class<T> type)
AOTContextget in interface AOTContextT - the type of the entrytype - the class of the entry@NonNull public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getDiagnostics()
AOTContextgetDiagnostics in interface AOTContext