static class CodePrinter.PrettyCodePrinter extends CodePrinter.MappedCodePrinter
Modifier and Type | Field and Description |
---|---|
private int |
indent |
(package private) static java.lang.String |
INDENT |
code, lineIndex, lineLength, lineLengthThreshold
sawFunction, statementNeedsEnded, statementStarted
Modifier | Constructor and Description |
---|---|
private |
PrettyCodePrinter(int lineLengthThreshold,
boolean createSourceMap,
SourceMap.DetailLevel sourceMapDetailLevel) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
append(java.lang.String str)
Appends a string to the code, keeping track of the current line length.
|
(package private) void |
appendBlockEnd() |
(package private) void |
appendBlockStart() |
(package private) void |
appendOp(java.lang.String op,
boolean binOp) |
(package private) void |
beginCaseBody() |
(package private) boolean |
breakAfterBlockFor(Node n,
boolean isStatementContext) |
(package private) void |
endCaseBody() |
(package private) void |
endFile()
Called when we're at the end of a file.
|
(package private) void |
endFunction(boolean statementContext) |
(package private) void |
endLine() |
private static Node |
getTryForCatch(Node n) |
(package private) void |
listSeparator() |
(package private) void |
maybeCutLine()
This may start a new line if the current line is longer than the line
length threshold.
|
(package private) void |
maybeInsertSpace()
Allows a consumer to insert spaces in locations where it is unnecessary
but may improve the readability of the code.
|
(package private) void |
maybeLineBreak() |
(package private) boolean |
shouldPreserveExtraBlocks()
If the body of a for loop or the then clause of an if statement has
a single statement, should it be wrapped in a block?
If the body of a for loop or the then clause of an if statement has
a single statement, should it be wrapped in a block? Doing so can
help when pretty-printing the code, and permits putting a debugging
breakpoint on the statement inside the condition.
|
(package private) void |
startNewLine()
Adds a newline to the code, resetting the line length and handling
indenting for pretty printing.
|
endSourceMapping, generateSourceMap, getCode, getCurrentCharIndex, getCurrentLineIndex, getLastChar, reportLineCut, startSourceMapping
add, addConstant, addIdentifier, addNumber, addOp, beginBlock, continueProcessing, endBlock, endBlock, endClass, endStatement, endStatement, isNegativeZero, isWordChar, maybeEndStatement, notePreferredLineBreak
static final java.lang.String INDENT
private int indent
private PrettyCodePrinter(int lineLengthThreshold, boolean createSourceMap, SourceMap.DetailLevel sourceMapDetailLevel)
lineLengthThreshold
- The length of a line after which we force
a newline when possible.createSourceMap
- Whether to generate source map data.sourceMapDetailLevel
- A filter to control which nodes get mapped
into the source map.void append(java.lang.String str)
append
in class CodeConsumer
void startNewLine()
startNewLine
in class CodeConsumer
void maybeLineBreak()
maybeLineBreak
in class CodeConsumer
void maybeCutLine()
maybeCutLine
in class CodeConsumer
void endLine()
endLine
in class CodeConsumer
void appendBlockStart()
appendBlockStart
in class CodeConsumer
void appendBlockEnd()
appendBlockEnd
in class CodeConsumer
void listSeparator()
listSeparator
in class CodeConsumer
void endFunction(boolean statementContext)
endFunction
in class CodeConsumer
void beginCaseBody()
beginCaseBody
in class CodeConsumer
void endCaseBody()
endCaseBody
in class CodeConsumer
void appendOp(java.lang.String op, boolean binOp)
appendOp
in class CodeConsumer
boolean shouldPreserveExtraBlocks()
shouldPreserveExtraBlocks
in class CodeConsumer
void maybeInsertSpace()
CodeConsumer
maybeInsertSpace
in class CodeConsumer
private static Node getTryForCatch(Node n)
boolean breakAfterBlockFor(Node n, boolean isStatementContext)
breakAfterBlockFor
in class CodeConsumer
void endFile()
CodeConsumer
endFile
in class CodeConsumer