Class AbstractSourceGenerationContext<A extends AbstractSourceGenerationContext<A,B>,B extends Enum<B>>
Represents a source class generation context which provides utilities aimed to simplify the generation of Java source classes.
- Author:
- Jeremy Kuhn
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static StringThe default indent.protected ElementsThe elements utility.protected Map<QualifiedName,String>The map of field names used to avoid duplicates.The map of imports.protected StringThe indent used during generation.protected intThe indent depth.protected BThe generation mode.protected ModuleQualifiedNameThe qualified name of the module being generated.protected AThe parent generation context.protected TypesThe types utility. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSourceGenerationContext(A parentGeneration)Creates a source generation context from a parent generation context.AbstractSourceGenerationContext(Types typeUtils, Elements elementUtils, B mode)Creates a source generation context.AbstractSourceGenerationContext(Types typeUtils, Elements elementUtils, B mode, String indent)Creates a source generation context. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified import to the context.Returns the elements utility.getFieldName(QualifiedName qName)Returns a unique field name corresponding to the specified qualified name.Returns the list of imports.intReturns the indent depth.getMode()Returns the generation mode.Returns the generated module.getTypeName(String canonicalName)Adds the specified canonical name to the list of imports if not done yet and returns the simple type name.getTypeName(TypeMirror type)Adds the specified type to the list of imports if not done yet and returns the simple type name.Returns the types utility.indent(int depth)Returns an indent of the specified depth from the current generation indent depth.joining()Returns a Collector that concatenates the input elements into a StringBuilder, in encounter order.joining(CharSequence delimiter)Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.voidremoveImport(String className)Removes the import for the specified class.voidSets the generation indent.abstract AwithIndentDepth(int indentDepth)Returns a new generation context created from this context with the specified indent depth.withIndentDepthAdd(int delta)Returns a new generation context created from this context with an indent depth increased by the specified delta.abstract AReturns a new generation context created from this context with the specified mode.abstract AwithModule(ModuleQualifiedName moduleQualifiedName)Returns a new generation context created from this context for the specified module.
-
Field Details
-
parentGeneration
The parent generation context. -
typeUtils
The types utility. -
elementUtils
The elements utility. -
mode
The generation mode. -
imports
The map of imports. -
indentDepth
protected int indentDepthThe indent depth. -
DEFAULT_INDENT
The default indent.- See Also:
- Constant Field Values
-
indent
The indent used during generation. -
moduleQualifiedName
The qualified name of the module being generated. -
fieldNames
The map of field names used to avoid duplicates.
-
-
Constructor Details
-
AbstractSourceGenerationContext
Creates a source generation context.
- Parameters:
typeUtils- the types utilityelementUtils- the elements utilitymode- the generation mode
-
AbstractSourceGenerationContext
public AbstractSourceGenerationContext(Types typeUtils, Elements elementUtils, B mode, String indent)Creates a source generation context.
- Parameters:
typeUtils- the types utilityelementUtils- the elements utilitymode- the generation modeindent- the indent
-
AbstractSourceGenerationContext
Creates a source generation context from a parent generation context.
- Parameters:
parentGeneration- the parent generation context
-
-
Method Details
-
setIndent
Sets the generation indent.
- Parameters:
indent- an indent
-
indent
Returns an indent of the specified depth from the current generation indent depth.
- Parameters:
depth- the relative indent depth- Returns:
- an indent
-
withMode
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
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
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
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
Returns the generation mode.
- Returns:
- the generation mode
-
getIndentDepth
public int getIndentDepth()Returns the indent depth.
- Returns:
- the indent depth
-
getModule
Returns the generated module.
- Returns:
- the generated module qualified name
-
getTypeUtils
Returns the types utility.
- Returns:
- the types utility
-
getElementUtils
Returns the elements utility.
- Returns:
- the elements utility
-
addImport
Adds the specified import to the context.
- Parameters:
className- the simple name of the imported typecanonicalName- the canonical name of the imported type
-
removeImport
Removes the import for the specified class.
- Parameters:
className- a simple class name
-
getImports
Returns the list of imports.
- Returns:
- a set of imports
-
getTypeName
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
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
Returns a unique field name corresponding to the specified qualified name.
- Parameters:
qName- a qualified name- Returns:
- a unique field name
-
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
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
-