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 Details

    • getPackageName

      @NonNull @NonNull String getPackageName()
      The package which should be used for generated classes.
      Returns:
      the package name
    • getConfiguration

      @NonNull @NonNull Configuration getConfiguration()
      Returns the source generators configuration.
      Returns:
      the configuration
    • getAnalyzer

      @NonNull @NonNull ApplicationContextAnalyzer 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 the StaticOptimizations 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 generate
      optimizationKind - the type of the optimization
      bodyBuilder - the builder of the body of the load() method
    • registerServiceImplementation

      void registerServiceImplementation(Class<?> serviceType, String simpleServiceName)
      Registers a generated service type.
      Parameters:
      serviceType - the type of the service
      simpleServiceName - the simple name of the generated type
    • registerGeneratedResource

      void registerGeneratedResource(@NonNull @NonNull String path, Consumer<? super File> consumer)
      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

      void registerExcludedResource(@NonNull @NonNull String path)
      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

      void registerClassNeededAtCompileTime(@NonNull @NonNull Class<?> clazz)
      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

      void registerBuildTimeInit(@NonNull @NonNull String className)
      Registers a type as a requiring initialization at build time.
      Parameters:
      className - the type
    • 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

      @NonNull void addDiagnostics(String category, String message)
      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 type
      message - a message to log
    • put

      <T> void put(@NonNull @NonNull Class<T> type, @NonNull T value)
      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 store
      value - the value to store
    • get

      @NonNull <T> @NonNull Optional<T> get(@NonNull @NonNull Class<T> type)
      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

      @NonNull @NonNull Map<String,List<String>> getDiagnostics()
      Returns the diagnostics map.
      Returns:
      the diagnostics
    • getRuntime

      @NonNull @NonNull Runtime getRuntime()
      Returns the target runtime environment.
      Returns:
      target runtime
    • getBuildTimeInitClasses

      Set<String> getBuildTimeInitClasses()
      Returns the set of classes which require build time initialization.
      Returns:
      the set of classes needing build time init
    • finish

      void finish()
      Performs actions which have to be done as late as possible during source generation.