Package com.palantir.javaformat
Class OpsBuilder
java.lang.Object
com.palantir.javaformat.OpsBuilder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA request to add or remove a blank line in the output.static interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintactualSize(int position, int length) Return the actual size of the AST node at position, including comments.actualStartColumn(int position) Return the start column of the token atposition, including leading comments.voidAdd a list ofOps.voidForce or suppress a blank line here in the output.voidbreakOp()Emit aBreak.voidEmit a self-builtBreak.voidEmit a genericBreak.voidEmit a genericBreak.voidEmit aBreak.voidvoidEmit a filledBreak.voidbreakToFill(String flat) 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.com.palantir.javaformat.java.FormatterDiagnosticdiagnostic(String message) Create aFormatterDiagnosticat the current position.voiddrain()Output any remaining tokens from the input stream (e.g.voidEmit a forcedBreak.voidforcedBreak(Indent plusIndent) Emit a forcedBreak.getInput()Get theOpsBuilder'sInput.voidguessToken(String token) Emit an optional token iff it exists on the input.voidMake the boundary of a region that can be partially formatted.booleanReturn whether the last token emitted is followed by a newline.voidEmit a single- or multi-character op by breaking it into single-characterTokens.voidOpen a new level by emitting anOpenOp.voidopen(Indent plusIndent, BreakBehaviour breakBehaviour, LastLevelBreakability breakabilityIfLastLevel) Open a new level by emitting anOpenOp.voidvoidOpen 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.voidspace()Emit aNonBreakingSpace.voidsync(int inputPosition) Sync to position in the input.voidtoken(String token, Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional<Indent> breakAndIndentTrailingComment) toString()
-
Constructor Details
-
OpsBuilder
TheOpsBuilderconstructor.- Parameters:
input- theInput, used for retrieve information from the AST
-
-
Method Details
-
actualSize
public int actualSize(int position, int length) Return the actual size of the AST node at position, including comments. -
actualStartColumn
Return 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 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 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
-
open
Open a new level by emitting anOpenOp.- Parameters:
debugName- a representative name for this lambdaplusIndent- the extra indent for the new level
-
open
public void open(Indent plusIndent, BreakBehaviour breakBehaviour, LastLevelBreakability breakabilityIfLastLevel) Open a new level by emitting anOpenOp.- Parameters:
plusIndent- the extra indent for the new levelbreakBehaviour- how to decide whether to break this level or notbreakabilityIfLastLevel- if last level, when to break this rather than parent
-
open
-
close
public void close()Close the current level, by emitting aCloseOp. -
peekToken
Return the text of the nextInput.Token, or absent if there is none. -
mostRecentTokenFollowedByNewline
public boolean mostRecentTokenFollowedByNewline()Return whether the last token emitted is followed by a newline. -
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 void token(String token, Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional<Indent> breakAndIndentTrailingComment) -
op
Emit a single- or multi-character op by breaking it into single-characterTokens.- Parameters:
op- the operator to emit
-
space
public void space()Emit aNonBreakingSpace. -
breakOp
public void breakOp()Emit aBreak. -
breakOp
Emit aBreak.- Parameters:
plusIndent- extra indent if taken
-
breakToFill
public void breakToFill()Emit a filledBreak. -
forcedBreak
public void forcedBreak()Emit a forcedBreak. -
forcedBreak
Emit a forcedBreak.- Parameters:
plusIndent- extra indent if taken
-
breakOp
- Parameters:
flat- theBreakwhen not broken
-
breakToFill
- Parameters:
flat- theBreakwhen not broken
-
breakOp
Emit a genericBreak. -
breakOp
public void breakOp(FillMode fillMode, String flat, Indent plusIndent, Optional<BreakTag> optionalTag) Emit a genericBreak. -
breakOp
Emit a self-builtBreak. -
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. -
toString
-