Class Doc

java.lang.Object
com.google.googlejavaformat.Doc
Direct Known Subclasses:
Doc.Break, Doc.Level, Doc.Space, Doc.Tok, Doc.Token

public abstract class Doc extends Object
JavaInputAstVisitor outputs a sequence of Ops using OpsBuilder. This linear sequence is then transformed by DocBuilder into a tree-structured Doc. The top-level Doc is a Doc.Level, which contains a sequence of Docs, including other Doc.Levels. Leaf Docs are Doc.Tokens, representing language-level tokens; Doc.Toks, which may also represent non-token Input.Toks, including comments and other white-space; Doc.Spaces, representing single spaces; and Doc.Breaks, which represent optional line-breaks.
  • Field Details

    • 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:
    • EMPTY_RANGE

      private static final com.google.common.collect.Range<Integer> EMPTY_RANGE
    • INTEGERS

      private static final com.google.common.collect.DiscreteDomain<Integer> INTEGERS
    • width

      private final com.google.common.base.Supplier<Integer> width
    • flat

      private final com.google.common.base.Supplier<String> flat
    • range

      private final com.google.common.base.Supplier<com.google.common.collect.Range<Integer>> range
  • Constructor Details

    • Doc

      public Doc()
  • Method Details

    • getWidth

      final int getWidth()
      Return the width of a Doc.
      Returns:
      the width
    • getFlat

      final String getFlat()
      Return a Doc's flat-string value; not defined (and never called) if the Doc contains forced breaks.
      Returns:
      the flat-string value
    • range

      final com.google.common.collect.Range<Integer> range()
      Return the Range of a Doc.
      Returns:
      the Doc's Range
    • computeWidth

      abstract int computeWidth()
      Compute the Doc's width.
      Returns:
      the width
    • computeFlat

      abstract String computeFlat()
      Compute the Doc's flat value. Not defined (and never called) if contains forced breaks.
      Returns:
      the flat value
    • computeRange

      abstract com.google.common.collect.Range<Integer> computeRange()
      Compute the Doc's Range of Input.Tokens.
      Returns:
      the Range
    • computeBreaks

      public abstract Doc.State computeBreaks(CommentsHelper commentsHelper, int maxWidth, Doc.State state)
      Make breaking decisions for a Doc.
      Parameters:
      maxWidth - the maximum line width
      state - the current output state
      Returns:
      the new output state
    • write

      public abstract void write(Output output)
      Write a Doc to an Output, after breaking decisions have been made.