private abstract static class CodePrinter.MappedCodePrinter extends CodeConsumer
Modifier and Type | Class and Description |
---|---|
private static class |
CodePrinter.MappedCodePrinter.Mapping
Maintains a mapping from a given node to the position
in the source code at which its generated form was
placed.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<CodePrinter.MappedCodePrinter.Mapping> |
allMappings |
protected java.lang.StringBuilder |
code |
private boolean |
createSrcMap |
protected int |
lineIndex |
protected int |
lineLength |
protected int |
lineLengthThreshold |
private java.util.Deque<CodePrinter.MappedCodePrinter.Mapping> |
mappings |
private SourceMap.DetailLevel |
sourceMapDetailLevel |
sawFunction, statementNeedsEnded, statementStarted
Constructor and Description |
---|
MappedCodePrinter(int lineLengthThreshold,
boolean createSrcMap,
SourceMap.DetailLevel sourceMapDetailLevel) |
Modifier and Type | Method and Description |
---|---|
private static FilePosition |
convertPosition(FilePosition position,
int lineIndex,
int characterPosition,
boolean insertion)
Converts the given position by normalizing it against the insertion
or removal of a newline at the given line and character position.
|
(package private) void |
endSourceMapping(Node node)
Finishes the source mapping for the given
node at the current position.
|
(package private) void |
generateSourceMap(SourceMap map)
Generates the source map from the given code consumer,
appending the information it saved to the SourceMap
object given.
|
java.lang.String |
getCode() |
protected int |
getCurrentCharIndex() |
protected int |
getCurrentLineIndex() |
(package private) char |
getLastChar()
Retrieve the last character of the last string sent to append.
|
(package private) void |
reportLineCut(int lineIndex,
int charIndex,
boolean insertion)
Reports to the code consumer that the given line has been cut at the
given position, i.e.
|
(package private) void |
startSourceMapping(Node node)
Starts the source mapping for the given
node at the current position.
|
add, addConstant, addIdentifier, addNumber, addOp, append, appendBlockEnd, appendBlockStart, appendOp, beginBlock, beginCaseBody, breakAfterBlockFor, continueProcessing, endBlock, endBlock, endCaseBody, endClass, endFile, endFunction, endLine, endStatement, endStatement, isNegativeZero, isWordChar, listSeparator, maybeCutLine, maybeEndStatement, maybeInsertSpace, maybeLineBreak, notePreferredLineBreak, shouldPreserveExtraBlocks, startNewLine
private final java.util.Deque<CodePrinter.MappedCodePrinter.Mapping> mappings
private final java.util.List<CodePrinter.MappedCodePrinter.Mapping> allMappings
private final boolean createSrcMap
private final SourceMap.DetailLevel sourceMapDetailLevel
protected final java.lang.StringBuilder code
protected final int lineLengthThreshold
protected int lineLength
protected int lineIndex
MappedCodePrinter(int lineLengthThreshold, boolean createSrcMap, SourceMap.DetailLevel sourceMapDetailLevel)
void startSourceMapping(Node node)
startSourceMapping
in class CodeConsumer
void endSourceMapping(Node node)
endSourceMapping
in class CodeConsumer
void generateSourceMap(SourceMap map)
void reportLineCut(int lineIndex, int charIndex, boolean insertion)
private static FilePosition convertPosition(FilePosition position, int lineIndex, int characterPosition, boolean insertion)
position
- The existing position before the newline was inserted.lineIndex
- The index of the line at which the newline was inserted.characterPosition
- The position on the line at which the newline
was inserted.insertion
- True if a newline was inserted, false if a newline was
removed.java.lang.IllegalStateException
- if an attempt to reverse a line cut is
made on a previous line rather than the current line.public java.lang.String getCode()
char getLastChar()
CodeConsumer
getLastChar
in class CodeConsumer
protected final int getCurrentCharIndex()
protected final int getCurrentLineIndex()