public abstract class CodeBuilder<E extends TargetExpr> extends Object
All implementations share indenting behavior and output variable behavior, while implementing their own idiosyncrasies for creating and modifying output variables.
| Constructor and Description |
|---|
CodeBuilder()
Constructs a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
addToOutputVar(List<? extends E> targetExprs)
Appends a line/statement with the concatenation of the given target expressions saved to the
current output variable.
|
CodeBuilder<E> |
append(String... codeFragments)
Appends one or more strings to the generated code.
|
CodeBuilder<E> |
appendLine(String... codeFragments)
Appends the current indent, then the given strings, then a newline.
|
CodeBuilder<E> |
appendLineEnd(String... codeFragments)
Appends the given strings, then a newline.
|
CodeBuilder<E> |
appendLineStart(String... codeFragments)
Appends the current indent, then the given strings.
|
CodeBuilder<E> |
appendOutputVarName()
Appends the name of the current output variable.
|
void |
decreaseIndent()
Decreases the current indent.
|
void |
decreaseIndentTwice()
Decreases the current indent twice.
|
String |
getCode() |
protected boolean |
getOutputVarIsInited()
Gets the current output variable initialization status.
|
String |
getOutputVarName()
Gets the current output variable name.
|
void |
increaseIndent()
Increases the current indent.
|
void |
increaseIndentTwice()
Increases the current indent twice.
|
abstract void |
initOutputVarIfNecessary()
Appends a full line/statement for initializing the current output variable.
|
void |
popOutputVar()
Pops off the current output variable.
|
void |
pushOutputVar(String outputVarName)
Pushes on a new current output variable.
|
void |
setOutputVarInited()
Tells this CodeBuilder that the current output variable has already been initialized.
|
public CodeBuilder()
public void increaseIndent()
public void increaseIndentTwice()
public void decreaseIndent()
public void decreaseIndentTwice()
public void pushOutputVar(String outputVarName)
outputVarName - The new output variable name.public void popOutputVar()
public void setOutputVarInited()
initOutputVarIfNecessary and addToOutputVar to not add initialization
code even on the first use of the variable.public String getOutputVarName()
public CodeBuilder<E> append(String... codeFragments)
codeFragments - The code string(s) to append.public CodeBuilder<E> appendLine(String... codeFragments)
codeFragments - The code string(s) to append.public CodeBuilder<E> appendLineStart(String... codeFragments)
codeFragments - The code string(s) to append.public CodeBuilder<E> appendLineEnd(String... codeFragments)
codeFragments - The code string(s) to append.public CodeBuilder<E> appendOutputVarName()
public String getCode()
public abstract void initOutputVarIfNecessary()
public abstract void addToOutputVar(List<? extends E> targetExprs)
targetExprs - One or more target expressions to compute output.protected boolean getOutputVarIsInited()