public final class CodeLines
extends java.lang.Object
This class serves as the JS code storage as well as provides the convenience methods for adding the code.
The writable representation of the output may be obtained through the toString()
method.
Constructor and Description |
---|
CodeLines()
Creates an instance of the
JsOutput with the default indentation. |
CodeLines(io.spine.code.gen.Indent indentation)
Creates an instance of the
JsOutput with the custom indentation. |
Modifier and Type | Method and Description |
---|---|
void |
append(CodeLine line)
Appends the code line and indents it to the current indent level.
|
void |
append(CodeLines appended)
Appends another code lines to this code.
|
void |
append(Snippet snippet)
Appends the lines of the snippet.
|
void |
append(java.lang.String codeLine)
Appends the line of code on the current indent level.
|
static CodeLines |
commaSeparated(java.util.List<CodeLine> lines)
Merges lines by addition of a comma to each line except the last one.
|
void |
decreaseDepth()
Manually decreases the current indent level.
|
void |
enterBlock(java.lang.String blockHeader)
Enters block with the custom header.
|
void |
enterElseBlock()
Closes the current
if block and enters the else block. |
void |
enterIfBlock(java.lang.String condition)
Enters the
if block body. |
void |
enterMethod(java.lang.String methodName,
java.lang.String... methodArgs)
Declares JS method and enters its body.
|
boolean |
equals(java.lang.Object o) |
void |
exitBlock()
Exits the
if , else or custom block. |
void |
exitMethod()
Exits method declaration.
|
int |
hashCode() |
void |
ifNotNull(java.lang.String value)
Enters the
if block checking that the given value is not null . |
void |
ifNotNullOrUndefined(java.lang.String value)
Enters the
if block checking that given value is not null or
undefined . |
void |
ifNotUndefined(java.lang.String value)
Enters the
if block checking that the given value is not undefined . |
void |
ifNull(java.lang.String value)
Enters the
if block checking that the given value is null . |
void |
increaseDepth()
Manually increases the current indent level.
|
java.lang.String |
toString()
Concatenates all the code lines with the correct indentation and line separator.
|
public CodeLines()
JsOutput
with the default indentation.public CodeLines(io.spine.code.gen.Indent indentation)
JsOutput
with the custom indentation.indentation
- the indentation to usepublic void append(CodeLines appended)
If the appended lines have different indent level, then the level of appended lines is adjusted to match the level of the current lines.
The indent level is adjusted by the difference of the levels.
appended
- the code to appendpublic void append(Snippet snippet)
public void append(java.lang.String codeLine)
codeLine
- the code to addpublic void append(CodeLine line)
line
- the line to appendpublic void enterMethod(java.lang.String methodName, java.lang.String... methodArgs)
methodName
- the full method name including type namemethodArgs
- the args to pass to the methodpublic void exitMethod()
public void enterIfBlock(java.lang.String condition)
if
block body.condition
- the if
clausepublic void enterElseBlock()
if
block and enters the else
block.public void enterBlock(java.lang.String blockHeader)
For example, the custom header may be for (let value in list)
.
blockHeader
- the block headerpublic void exitBlock()
if
, else
or custom block.public void ifNull(java.lang.String value)
if
block checking that the given value is null
.value
- the expression to check for null
public void ifNotNull(java.lang.String value)
if
block checking that the given value is not null
.value
- the expression to check for not being null
public void ifNotUndefined(java.lang.String value)
if
block checking that the given value is not undefined
.value
- the expression to check for not being undefined
public void ifNotNullOrUndefined(java.lang.String value)
if
block checking that given value is not null
or
undefined
.value
- the expression to check for not being null
or undefined
public void increaseDepth()
public void decreaseDepth()
public static CodeLines commaSeparated(java.util.List<CodeLine> lines)
public java.lang.String toString()
toString
in class java.lang.Object
String
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object