java.lang.Object
com.google.googlejavaformat.OpsBuilder
public final class OpsBuilder extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOpsBuilder.BlankLineWantedA request to add or remove a blank line in the output. -
Constructor Summary
Constructors Constructor Description OpsBuilder(Input input, Output output)TheOpsBuilderconstructor. -
Method Summary
Modifier and Type Method Description intactualSize(int position, int length)IntegeractualStartColumn(int position)voidaddAll(List<Op> ops)Add a list ofOps.voidblankLineWanted(OpsBuilder.BlankLineWanted wanted)Force or suppress a blank line here in the output.voidbreakOp()Emit aDoc.Break.voidbreakOp(Doc.FillMode fillMode, String flat, Indent plusIndent)Emit a genericDoc.Break.voidbreakOp(Doc.FillMode fillMode, String flat, Indent plusIndent, Optional<Output.BreakTag> optionalTag)Emit a genericDoc.Break.voidbreakOp(Indent plusIndent)Emit aDoc.Break.voidbreakOp(String flat)voidbreakToFill()Emit a filledDoc.Break.voidbreakToFill(String flat)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.voidclose()Close the current level, by emitting aCloseOp.intdepth()Returns the number of unclosed open ops in the input stream.FormatterDiagnosticdiagnostic(String message)Create aFormatterDiagnosticat the current position.voiddrain()Output any remaining tokens from the input stream (e.g.voidforcedBreak()Emit a forcedDoc.Break.voidforcedBreak(Indent plusIndent)Emit a forcedDoc.Break.InputgetInput()Get theOpsBuilder'sInput.voidguessToken(String token)Emit an optional token iff it exists on the input.voidmarkForPartialFormat()Make the boundary of a region that can be partially formatted.voidop(String op)Emit a single- or multi-character op by breaking it into single-characterDoc.Tokens.voidopen(Indent plusIndent)Open a new level by emitting anOpenOp.Optional<String>peekToken()Return the text of the nextInput.Token, or absent if there is none.Optional<String>peekToken(int skip)Return the text of an upcomingInput.Token, or absent if there is none.voidspace()Emit aDoc.Space.voidsync(int inputPosition)Sync to position in the input.voidtoken(String token, Doc.Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional<Indent> breakAndIndentTrailingComment)StringtoString()
-
Constructor Details
-
OpsBuilder
TheOpsBuilderconstructor.
-
-
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 at
position, 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. -
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
-