java.lang.Object
com.google.googlejavaformat.OpsBuilder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A request to add or remove a blank line in the output. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
actualSize
(int position, int length) Returns the actual size of the AST node at position, including comments.actualStartColumn
(int position) Returns the start column of the token atposition
, including leading comments.final void
Add anOp
, and record open/close ops for later validation of unclosed levels.final void
Add a list ofOp
s.final void
Force or suppress a blank line here in the output.final void
breakOp()
Emit aDoc.Break
.final void
breakOp
(Doc.FillMode fillMode, String flat, Indent plusIndent) Emit a genericDoc.Break
.final void
breakOp
(Doc.FillMode fillMode, String flat, Indent plusIndent, Optional<Output.BreakTag> optionalTag) Emit a genericDoc.Break
.final void
Emit aDoc.Break
.final void
final void
Emit a filledDoc.Break
.final void
breakToFill
(String flat) final ImmutableList
<Op> build()
Build a list ofOp
s from theOpsBuilder
.void
checkClosed
(int previous) Checks that all open ops in the op stream have matching close ops.final void
close()
Close the current level, by emitting aCloseOp
.int
depth()
Returns the number of unclosed open ops in the input stream.diagnostic
(String message) Create aFormatterDiagnostic
at the current position.final void
drain()
Output any remaining tokens from the input stream (e.g.final void
Emit a forcedDoc.Break
.final void
forcedBreak
(Indent plusIndent) Emit a forcedDoc.Break
.final Input
getInput()
Get theOpsBuilder
'sInput
.final void
guessToken
(String token) Emit an optional token iff it exists on the input.void
Make the boundary of a region that can be partially formatted.final void
Emit a single- or multi-character op by breaking it into single-characterDoc.Token
s.final void
Open a new level by emitting anOpenOp
.Return the text of the nextInput.Token
, or absent if there is none.peekToken
(int skip) Return the text of an upcomingInput.Token
, or absent if there is none.peekTokens
(int startPosition, Predicate<Input.Tok> predicate) Returns theInput.Tok
s starting at the current source position, which are satisfied by the given predicate.final void
space()
Emit aDoc.Space
.final void
sync
(int inputPosition) Sync to position in the input.final void
token
(String token, Doc.Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional<Indent> breakAndIndentTrailingComment) final String
toString()
-
Constructor Details
-
Method Details
-
actualSize
public int actualSize(int position, int length) Returns the actual size of the AST node at position, including comments. -
actualStartColumn
Returns the start column of the token atposition
, including leading comments. -
add
Add anOp
, and record open/close ops for later validation of unclosed levels. -
addAll
Add a list ofOp
s. -
getInput
Get theOpsBuilder
'sInput
. -
depth
public int depth()Returns the number of unclosed open ops in the input stream. -
checkClosed
public void checkClosed(int previous) Checks that all open ops in the op stream have matching close ops.- Throws:
FormattingError
- if any ops were unclosed
-
diagnostic
Create aFormatterDiagnostic
at the current position. -
sync
public final void sync(int inputPosition) Sync to position in the input. If we've skipped outputting any tokens that were present in the input tokens, output them here and optionally complain.- Parameters:
inputPosition
- the0
-based input position
-
drain
public final void drain()Output any remaining tokens from the input stream (e.g. terminal whitespace). -
open
Open a new level by emitting anOpenOp
.- Parameters:
plusIndent
- the extra indent for the new level
-
close
public final void close()Close the current level, by emitting aCloseOp
. -
peekToken
Return the text of the nextInput.Token
, or absent if there is none. -
peekToken
Return the text of an upcomingInput.Token
, or absent if there is none. -
peekTokens
Returns theInput.Tok
s starting at the current source position, which are satisfied by the given predicate. -
guessToken
Emit an optional token iff it exists on the input. This is used to emit tokens whose existence has been lost in the AST.- Parameters:
token
- the optional token
-
token
public final void token(String token, Doc.Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional<Indent> breakAndIndentTrailingComment) -
op
Emit a single- or multi-character op by breaking it into single-characterDoc.Token
s.- Parameters:
op
- the operator to emit
-
space
public final void space()Emit aDoc.Space
. -
breakOp
public final void breakOp()Emit aDoc.Break
. -
breakOp
Emit aDoc.Break
.- Parameters:
plusIndent
- extra indent if taken
-
breakToFill
public final void breakToFill()Emit a filledDoc.Break
. -
forcedBreak
public final void forcedBreak()Emit a forcedDoc.Break
. -
forcedBreak
Emit a forcedDoc.Break
.- Parameters:
plusIndent
- extra indent if taken
-
breakOp
- Parameters:
flat
- theDoc.Break
when not broken
-
breakToFill
- Parameters:
flat
- theDoc.Break
when not broken
-
breakOp
Emit a genericDoc.Break
.- Parameters:
fillMode
- theDoc.FillMode
flat
- theDoc.Break
when not brokenplusIndent
- extra indent if taken
-
breakOp
public final void breakOp(Doc.FillMode fillMode, String flat, Indent plusIndent, Optional<Output.BreakTag> optionalTag) Emit a genericDoc.Break
.- Parameters:
fillMode
- theDoc.FillMode
flat
- theDoc.Break
when not brokenplusIndent
- extra indent if takenoptionalTag
- an optional tag for remembering whether the break was taken
-
markForPartialFormat
public void markForPartialFormat()Make the boundary of a region that can be partially formatted. The boundary will be included in the following region, e.g.: [[boundary0, boundary1), [boundary1, boundary2), ...]. -
blankLineWanted
Force or suppress a blank line here in the output.- Parameters:
wanted
- whether to force (true
) or suppressfalse
) the blank line
-
build
Build a list ofOp
s from theOpsBuilder
.- Returns:
- the list of
Op
s
-
toString
-