Class DocBuilder
- java.lang.Object
-
- com.google.googlejavaformat.DocBuilder
-
public final class DocBuilder extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description DocBuilder()Start to build aDocBuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidadd(Doc doc)(package private) voidbreakDoc(Doc.Break breakDoc)Docbuild()Return theDoc.(package private) voidclose()Close the currentDoc.Level.(package private) voidopen(Indent plusIndent)Open a newDoc.Level.java.lang.StringtoString()DocBuilderwithOps(java.util.List<Op> ops)Add a list ofOps to theOpsBuilder.
-
-
-
Field Detail
-
base
private final Doc.Level base
-
stack
private final java.util.ArrayDeque<Doc.Level> stack
-
appendLevel
private Doc.Level appendLevel
A possibly earlierDoc.Levelfor appending text, à la Philip Wadler.Processing
Docs presents a subtle problem. Suppose we have aDocfor to an assignment node,a = b, with an optionalDoc.Breakfollowing the=. Suppose we have 5 characters to write it, so that we think we don't need the break. Unfortunately, thisDoclies in an expression statementDocfor the statementa = b;and this statement does not fit in 3 characters. This is why many formatters sometimes emit lines that are too long, or cheat by using a narrower line length to avoid such problems.One solution to this problem is not to decide whether a
Doc.Levelshould be broken until later (in this case, after the semicolon has been seen). A simpler approach is to rewrite theDocas here, so that the semicolon moves inside the innerDoc, and we can decide whether to break thatDocwithout seeing later text.
-
-
Method Detail
-
withOps
public DocBuilder withOps(java.util.List<Op> ops)
Add a list ofOps to theOpsBuilder.- Parameters:
ops- theOps- Returns:
- the
OpsBuilder
-
open
void open(Indent plusIndent)
Open a newDoc.Level.- Parameters:
plusIndent- the extra indent for theDoc.Level
-
close
void close()
Close the currentDoc.Level.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-