Package com.google.googlejavaformat
Class Doc
- java.lang.Object
-
- com.google.googlejavaformat.Doc
-
public abstract class Doc extends java.lang.ObjectJavaInputAstVisitoroutputs a sequence ofOps usingOpsBuilder. This linear sequence is then transformed byDocBuilderinto a tree-structuredDoc. The top-levelDocis aDoc.Level, which contains a sequence ofDocs, including otherDoc.Levels. LeafDocs areDoc.Tokens, representing language-level tokens;Doc.Toks, which may also represent non-tokenInput.Toks, including comments and other white-space;Doc.Spaces, representing single spaces; andDoc.Breaks, which represent optional line-breaks.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDoc.BreakA leaf node in aDocfor an optional break.static classDoc.FillMode(package private) static classDoc.LevelALevelinside aDoc.(package private) static classDoc.SpaceA Leaf node in aDocfor a non-breaking space.static classDoc.StateState for writing.(package private) static classDoc.TokA leaf node in aDocfor a non-token.static classDoc.TokenA leafDocfor a token.
-
Field Summary
Fields Modifier and Type Field Description private static com.google.common.collect.Range<java.lang.Integer>EMPTY_RANGEprivate com.google.common.base.Supplier<java.lang.String>flatprivate static com.google.common.collect.DiscreteDomain<java.lang.Integer>INTEGERSstatic intMAX_LINE_WIDTHThe maximum supported line width.private com.google.common.base.Supplier<com.google.common.collect.Range<java.lang.Integer>>rangeprivate com.google.common.base.Supplier<java.lang.Integer>width
-
Constructor Summary
Constructors Constructor Description Doc()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Doc.StatecomputeBreaks(CommentsHelper commentsHelper, int maxWidth, Doc.State state)Make breaking decisions for aDoc.(package private) abstract java.lang.StringcomputeFlat()Compute theDoc's flat value.(package private) abstract com.google.common.collect.Range<java.lang.Integer>computeRange()(package private) abstract intcomputeWidth()Compute theDoc's width.(package private) java.lang.StringgetFlat()Return aDoc's flat-string value; not defined (and never called) if theDoccontains forced breaks.(package private) intgetWidth()Return the width of aDoc.(package private) com.google.common.collect.Range<java.lang.Integer>range()Return theRangeof aDoc.abstract voidwrite(Output output)Write aDocto anOutput, after breaking decisions have been made.
-
-
-
Field Detail
-
MAX_LINE_WIDTH
public static final int MAX_LINE_WIDTH
The maximum supported line width.This can be used as a sentinel/threshold for
Docs that break unconditionally.The value was selected to be obviously too large for any practical line, but small enough to prevent accidental overflow.
- See Also:
- Constant Field Values
-
EMPTY_RANGE
private static final com.google.common.collect.Range<java.lang.Integer> EMPTY_RANGE
-
INTEGERS
private static final com.google.common.collect.DiscreteDomain<java.lang.Integer> INTEGERS
-
width
private final com.google.common.base.Supplier<java.lang.Integer> width
-
flat
private final com.google.common.base.Supplier<java.lang.String> flat
-
range
private final com.google.common.base.Supplier<com.google.common.collect.Range<java.lang.Integer>> range
-
-
Method Detail
-
getWidth
final int getWidth()
Return the width of aDoc.- Returns:
- the width
-
getFlat
final java.lang.String getFlat()
Return aDoc's flat-string value; not defined (and never called) if theDoccontains forced breaks.- Returns:
- the flat-string value
-
range
final com.google.common.collect.Range<java.lang.Integer> range()
Return theRangeof aDoc.- Returns:
- the
Doc'sRange
-
computeWidth
abstract int computeWidth()
Compute theDoc's width.- Returns:
- the width
-
computeFlat
abstract java.lang.String computeFlat()
Compute theDoc's flat value. Not defined (and never called) if contains forced breaks.- Returns:
- the flat value
-
computeRange
abstract com.google.common.collect.Range<java.lang.Integer> computeRange()
- Returns:
- the
Range
-
computeBreaks
public abstract Doc.State computeBreaks(CommentsHelper commentsHelper, int maxWidth, Doc.State state)
Make breaking decisions for aDoc.- Parameters:
maxWidth- the maximum line widthstate- the current output state- Returns:
- the new output state
-
-