public final class OpsBuilder extends Object
Modifier and Type | Class and Description |
---|---|
static class |
OpsBuilder.BlankLineWanted
A request to add or remove a blank line in the output.
|
Constructor and Description |
---|
OpsBuilder(Input input,
Output output)
The
OpsBuilder constructor. |
Modifier and Type | Method and Description |
---|---|
int |
actualSize(int position,
int length) |
Integer |
actualStartColumn(int position) |
void |
addAll(List<Op> ops)
Add a list of
Op s. |
void |
blankLineWanted(OpsBuilder.BlankLineWanted wanted)
Force or suppress a blank line here in the output.
|
void |
breakOp()
Emit a
Doc.Break . |
void |
breakOp(Doc.FillMode fillMode,
String flat,
Indent plusIndent)
Emit a generic
Doc.Break . |
void |
breakOp(Doc.FillMode fillMode,
String flat,
Indent plusIndent,
Optional<Output.BreakTag> optionalTag)
Emit a generic
Doc.Break . |
void |
breakOp(Indent plusIndent)
Emit a
Doc.Break . |
void |
breakOp(String flat)
|
void |
breakToFill()
Emit a filled
Doc.Break . |
void |
breakToFill(String flat)
|
ImmutableList<Op> |
build()
Build a list of
Op s from the OpsBuilder . |
void |
checkClosed(int previous)
Checks that all open ops in the op stream have matching close ops.
|
void |
close()
Close the current level, by emitting a
CloseOp . |
int |
depth()
Returns the number of unclosed open ops in the input stream.
|
FormatterDiagnostic |
diagnostic(String message)
Create a
FormatterDiagnostic at the current position. |
void |
drain()
Output any remaining tokens from the input stream (e.g.
|
void |
forcedBreak()
Emit a forced
Doc.Break . |
void |
forcedBreak(Indent plusIndent)
Emit a forced
Doc.Break . |
Input |
getInput()
Get the
OpsBuilder 's Input . |
void |
guessToken(String token)
Emit an optional token iff it exists on the input.
|
void |
markForPartialFormat()
Make the boundary of a region that can be partially formatted.
|
void |
op(String op)
Emit a single- or multi-character op by breaking it into single-character
Doc.Token s. |
void |
open(Indent plusIndent)
Open a new level by emitting an
OpenOp . |
Optional<String> |
peekToken()
Return the text of the next
Input.Token , or absent if there is none. |
void |
space()
Emit a
Doc.Space . |
void |
sync(int inputPosition)
Sync to position in the input.
|
void |
token(String token,
Doc.Token.RealOrImaginary realOrImaginary,
Indent plusIndentCommentsBefore,
Optional<Indent> breakAndIndentTrailingComment) |
String |
toString() |
public int actualSize(int position, int length)
public Integer actualStartColumn(int position)
position
, including leading comments.public int depth()
public void checkClosed(int previous)
FormattingError
- if any ops were unclosedpublic FormatterDiagnostic diagnostic(String message)
FormatterDiagnostic
at the current position.public final void sync(int inputPosition)
inputPosition
- the 0
-based input positionpublic final void drain()
public final void open(Indent plusIndent)
OpenOp
.plusIndent
- the extra indent for the new levelpublic final void close()
CloseOp
.public final Optional<String> peekToken()
Input.Token
, or absent if there is none.public final void guessToken(String token)
token
- the optional tokenpublic final void token(String token, Doc.Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional<Indent> breakAndIndentTrailingComment)
public final void op(String op)
Doc.Token
s.op
- the operator to emitpublic final void space()
Doc.Space
.public final void breakOp()
Doc.Break
.public final void breakOp(Indent plusIndent)
Doc.Break
.plusIndent
- extra indent if takenpublic final void breakToFill()
Doc.Break
.public final void forcedBreak()
Doc.Break
.public final void forcedBreak(Indent plusIndent)
Doc.Break
.plusIndent
- extra indent if takenpublic final void breakToFill(String flat)
flat
- the Doc.Break
when not brokenpublic final void breakOp(Doc.FillMode fillMode, String flat, Indent plusIndent)
Doc.Break
.fillMode
- the Doc.FillMode
flat
- the Doc.Break
when not brokenplusIndent
- extra indent if takenpublic final void breakOp(Doc.FillMode fillMode, String flat, Indent plusIndent, Optional<Output.BreakTag> optionalTag)
Doc.Break
.fillMode
- the Doc.FillMode
flat
- the Doc.Break
when not brokenplusIndent
- extra indent if takenoptionalTag
- an optional tag for remembering whether the break was takenpublic void markForPartialFormat()
public final void blankLineWanted(OpsBuilder.BlankLineWanted wanted)
wanted
- whether to force (true
) or suppress false
) the blank linepublic final ImmutableList<Op> build()
Op
s from the OpsBuilder
.Op
sCopyright © 2015–2017 Google Inc.. All rights reserved.