Class Doc

Direct Known Subclasses:
Break, Comment, Level, NonBreakingSpace, Token

public abstract class Doc extends HasUniqueId
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 Level, which contains a sequence of Docs, including other Levels. Leaf Docs are Tokens, representing language-level tokens; Comments, which may also represent non-token Input.Toks, including comments and other white-space; NonBreakingSpaces, representing single spaces; and Breaks, which represent optional line-breaks.
  • Constructor Details

    • Doc

      public Doc()
  • Method Details

    • getFlat

      public 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
    • computeWidth

      protected abstract float computeWidth()
      Compute the Doc's width.
      Returns:
      the width, or Float.POSITIVE_INFINITY if it must be broken
    • computeFlat

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

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

      public abstract State computeBreaks(CommentsHelper commentsHelper, int maxWidth, State state, Obs.ExplorationNode explorationNode)
      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(State state, Output output)
      Write a Doc to an Output, after breaking decisions have been made.