Interface RoundContext


public interface RoundContext
Context of a single round of code generation. For example the first round may generate types, that require additional code generation.
  • Method Details

    • availableAnnotations

      Collection<TypeName> availableAnnotations()
      Annotations available in this round, the collection contains only annotations valid for the extension being invoked.
      Returns:
      available annotations
    • types

      All types that are processed in this round. Only contains types that are valid for processing by this extension.
      Returns:
      matching types
    • annotatedTypes

      Collection<TypeInfo> annotatedTypes(TypeName annotationType)
      All types annotated with a specific annotation (including types that inherit such annotation from super types or through interfaces).
      Parameters:
      annotationType - annotation to check
      Returns:
      types that contain the annotation
    • annotatedElements

      Collection<TypedElementInfo> annotatedElements(TypeName annotationType)
      All elements annotated with a specific annotation.
      Parameters:
      annotationType - annotation to check
      Returns:
      elements that contain the annotation
    • addGeneratedType

      void addGeneratedType(TypeName type, ClassModel.Builder newClass, TypeName mainTrigger, Object... originatingElements)
      Add a new class to be code generated.

      Actual code generation will be done once, at the end of this round. Note that you can always force immediate generation through CodegenContext.filer(). In such a case do not add the type through this method. If you call this method with a type that was already registered, you will replace that instance.

      Parameters:
      type - type of the new class
      newClass - builder of the new class
      mainTrigger - a type that caused this, may be the processor itself, if not bound to any type
      originatingElements - possible originating elements (such as Element in APT, or ClassInfo in classpath scanning)
    • generatedType

      Optional<ClassModel.Builder> generatedType(TypeName type)
      Class model builder for a type that is to be code generated. This method provides access to all types that are to be generated, even from other extensions that do not match annotations. Whether another extension was already called depends on its CodegenExtensionProvider weight.
      Parameters:
      type - type of the generated type
      Returns:
      class model of the new type if any