Class AbstractSourceGenerationContext<A extends AbstractSourceGenerationContext<A,B>,B extends Enum<B>>

java.lang.Object
io.inverno.core.compiler.spi.support.AbstractSourceGenerationContext<A,B>

public abstract class AbstractSourceGenerationContext<A extends AbstractSourceGenerationContext<A,B>,B extends Enum<B>> extends Object

Represents a source class generation context which provides utilities aimed to simplify the generation of Java source classes.

Author:
Jeremy Kuhn
  • Field Details

    • parentGeneration

      protected A extends AbstractSourceGenerationContext<A,B> parentGeneration
      The parent generation context.
    • typeUtils

      protected Types typeUtils
      The types utility.
    • elementUtils

      protected Elements elementUtils
      The elements utility.
    • mode

      protected B extends Enum<B> mode
      The generation mode.
    • imports

      protected Map<String,String> imports
      The map of imports.
    • indentDepth

      protected int indentDepth
      The indent depth.
    • DEFAULT_INDENT

      protected static final String DEFAULT_INDENT
      The default indent.
      See Also:
    • indent

      protected String indent
      The indent used during generation.
    • moduleQualifiedName

      protected ModuleQualifiedName moduleQualifiedName
      The qualified name of the module being generated.
    • fieldNames

      protected Map<QualifiedName,String> fieldNames
      The map of field names used to avoid duplicates.
  • Constructor Details

    • AbstractSourceGenerationContext

      public AbstractSourceGenerationContext(Types typeUtils, Elements elementUtils, B mode)

      Creates a source generation context.

      Parameters:
      typeUtils - the types utility
      elementUtils - the elements utility
      mode - the generation mode
    • AbstractSourceGenerationContext

      public AbstractSourceGenerationContext(Types typeUtils, Elements elementUtils, B mode, String indent)

      Creates a source generation context.

      Parameters:
      typeUtils - the types utility
      elementUtils - the elements utility
      mode - the generation mode
      indent - the indent
    • AbstractSourceGenerationContext

      protected AbstractSourceGenerationContext(A parentGeneration)

      Creates a source generation context from a parent generation context.

      Parameters:
      parentGeneration - the parent generation context
  • Method Details

    • setIndent

      public void setIndent(String indent)

      Sets the generation indent.

      Parameters:
      indent - an indent
    • indent

      public String indent(int depth)

      Returns an indent of the specified depth from the current generation indent depth.

      Parameters:
      depth - the relative indent depth
      Returns:
      an indent
    • withMode

      public abstract A withMode(B mode)

      Returns a new generation context created from this context with the specified mode.

      This generation context remains untouched.

      Parameters:
      mode - a generation mode
      Returns:
      a new generation context
    • withIndentDepthAdd

      public A withIndentDepthAdd(int delta)

      Returns a new generation context created from this context with an indent depth increased by the specified delta.

      This generation context remains untouched.

      Parameters:
      delta - the indent depth delta
      Returns:
      a new generation context
    • withIndentDepth

      public abstract A withIndentDepth(int indentDepth)

      Returns a new generation context created from this context with the specified indent depth.

      This generation context remains untouched.

      Parameters:
      indentDepth - the indent depth
      Returns:
      a new generation context
    • withModule

      public abstract A withModule(ModuleQualifiedName moduleQualifiedName)

      Returns a new generation context created from this context for the specified module.

      This generation context remains untouched.

      Parameters:
      moduleQualifiedName - a module qualified name
      Returns:
      a new generation context
    • getMode

      public B getMode()

      Returns the generation mode.

      Returns:
      the generation mode
    • getIndentDepth

      public int getIndentDepth()

      Returns the indent depth.

      Returns:
      the indent depth
    • getModule

      public ModuleQualifiedName getModule()

      Returns the generated module.

      Returns:
      the generated module qualified name
    • getTypeUtils

      public Types getTypeUtils()

      Returns the types utility.

      Returns:
      the types utility
    • getElementUtils

      public Elements getElementUtils()

      Returns the elements utility.

      Returns:
      the elements utility
    • addImport

      public void addImport(String className, String canonicalName)

      Adds the specified import to the context.

      Parameters:
      className - the simple name of the imported type
      canonicalName - the canonical name of the imported type
    • removeImport

      public void removeImport(String className)

      Removes the import for the specified class.

      Parameters:
      className - a simple class name
    • getImports

      public Set<String> getImports()

      Returns the list of imports.

      Returns:
      a set of imports
    • getTypeName

      public String getTypeName(String canonicalName)

      Adds the specified canonical name to the list of imports if not done yet and returns the simple type name.

      Parameters:
      canonicalName - a canonical name
      Returns:
      the simple type name
    • getTypeName

      public String getTypeName(TypeMirror type)

      Adds the specified type to the list of imports if not done yet and returns the simple type name.

      Parameters:
      type - a type
      Returns:
      the simple type name
    • getFieldName

      public String getFieldName(QualifiedName qName)

      Returns a unique field name corresponding to the specified qualified name.

      Parameters:
      qName - a qualified name
      Returns:
      a unique field name
    • joining

      public Collector<CharSequence,?,StringBuilder> joining()

      Returns a Collector that concatenates the input elements into a StringBuilder, in encounter order.

      Returns:
      a Collector that concatenates the input elements into a StringBuilder, in encounter order
    • joining

      public Collector<CharSequence,?,StringBuilder> joining(CharSequence delimiter)

      Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

      Parameters:
      delimiter - the delimiter to be used between each element
      Returns:
      A Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter order