Package com.google.googlejavaformat
Class OpsBuilder
java.lang.Object
com.google.googlejavaformat.OpsBuilder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA request to add or remove a blank line in the output. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintactualSize(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 voidAdd a list ofOps.final voidForce or suppress a blank line here in the output.final voidbreakOp()Emit aDoc.Break.final voidbreakOp(Doc.FillMode fillMode, String flat, Indent plusIndent) Emit a genericDoc.Break.final voidbreakOp(Doc.FillMode fillMode, String flat, Indent plusIndent, Optional<Output.BreakTag> optionalTag) Emit a genericDoc.Break.final voidEmit aDoc.Break.final voidfinal voidEmit a filledDoc.Break.final voidbreakToFill(String flat) final com.google.common.collect.ImmutableList<Op>build()Build a list ofOps from theOpsBuilder.voidcheckClosed(int previous) Checks that all open ops in the op stream have matching close ops.final voidclose()Close the current level, by emitting aCloseOp.intdepth()Returns the number of unclosed open ops in the input stream.diagnostic(String message) Create aFormatterDiagnosticat the current position.final voiddrain()Output any remaining tokens from the input stream (e.g.final voidEmit a forcedDoc.Break.final voidforcedBreak(Indent plusIndent) Emit a forcedDoc.Break.final InputgetInput()Get theOpsBuilder'sInput.final voidguessToken(String token) Emit an optional token iff it exists on the input.voidMake the boundary of a region that can be partially formatted.final voidEmit a single- or multi-character op by breaking it into single-characterDoc.Tokens.final voidOpen 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.com.google.common.collect.ImmutableList<Input.Tok>peekTokens(int startPosition, com.google.common.base.Predicate<Input.Tok> predicate) Returns theInput.Toks starting at the current source position, which are satisfied by the given predicate.final voidspace()Emit aDoc.Space.final voidsync(int inputPosition) Sync to position in the input.final voidtoken(String token, Doc.Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional<Indent> breakAndIndentTrailingComment) final StringtoString()
-
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. -
addAll
Add a list ofOps. -
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 aFormatterDiagnosticat 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
public com.google.common.collect.ImmutableList<Input.Tok> peekTokens(int startPosition, com.google.common.base.Predicate<Input.Tok> predicate) Returns theInput.Toks 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.Tokens.- 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.Breakwhen not broken
-
breakToFill
- Parameters:
flat- theDoc.Breakwhen not broken
-
breakOp
Emit a genericDoc.Break.- Parameters:
fillMode- theDoc.FillModeflat- theDoc.Breakwhen 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.FillModeflat- theDoc.Breakwhen 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 ofOps from theOpsBuilder.- Returns:
- the list of
Ops
-
toString
-