Class JavaOutput


public final class JavaOutput extends Output
JavaOutput extends Output to represent a Java output document. It includes methods to emit the output document.
  • Field Details

    • lineSeparator

      private final String lineSeparator
    • javaInput

      private final Input javaInput
    • commentsHelper

      private final CommentsHelper commentsHelper
    • blankLines

      private final Map<Integer,OpsBuilder.BlankLineWanted> blankLines
    • partialFormatRanges

      private final com.google.common.collect.RangeSet<Integer> partialFormatRanges
    • mutableLines

      private final List<String> mutableLines
    • kN

      private final int kN
    • iLine

      private int iLine
    • lastK

      private int lastK
    • newlinesPending

      private int newlinesPending
    • lineBuilder

      private StringBuilder lineBuilder
    • spacesPending

      private StringBuilder spacesPending
  • Constructor Details

    • JavaOutput

      public JavaOutput(String lineSeparator, Input javaInput, CommentsHelper commentsHelper)
      JavaOutput constructor.
      Parameters:
      javaInput - the Input, used to match up blank lines in the output
      commentsHelper - the CommentsHelper, used to rewrite comments
  • Method Details

    • blankLine

      public void blankLine(int k, OpsBuilder.BlankLineWanted wanted)
      Description copied from class: Output
      A blank line is or is not wanted here.
      Specified by:
      blankLine in class Output
      Parameters:
      k - the Input.Tok index
      wanted - whether a blank line is wanted here
    • markForPartialFormat

      public void markForPartialFormat(Input.Token start, Input.Token end)
      Description copied from class: Output
      Marks a region that can be partially formatted.
      Specified by:
      markForPartialFormat in class Output
    • append

      public void append(String text, com.google.common.collect.Range<Integer> range)
      Description copied from class: Output
      Output a string.
      Specified by:
      append in class Output
      Parameters:
      text - the string
      range - the Range corresponding to the string
    • indent

      public void indent(int indent)
      Description copied from class: Output
      Indent by outputting indent spaces.
      Specified by:
      indent in class Output
      Parameters:
      indent - the current indent
    • flush

      public void flush()
      Flush any incomplete last line, then add the EOF token into our data structures.
    • getCommentsHelper

      public CommentsHelper getCommentsHelper()
      Description copied from class: Output
      Specified by:
      getCommentsHelper in class Output
      Returns:
      the CommentsHelper
    • getFormatReplacements

      public com.google.common.collect.ImmutableList<Replacement> getFormatReplacements(com.google.common.collect.RangeSet<Integer> iRangeSet0)
      Emit a list of Replacements to convert from input to output.
      Returns:
      a list of Replacements, sorted by start index, without overlaps
    • expandToBreakableRegions

      private com.google.common.collect.Range<Integer> expandToBreakableRegions(com.google.common.collect.Range<Integer> iRange)
      Expand a token range to start and end on acceptable boundaries for re-formatting.
      Parameters:
      iRange - the Range of tokens
      Returns:
      the expanded token range
    • applyReplacements

      public static String applyReplacements(String input, List<Replacement> replacements)
    • startPosition

      public static int startPosition(Input.Token token)
      The earliest position of any Tok in the Token, including leading whitespace.
    • startTok

      public static Input.Tok startTok(Input.Token token)
      The earliest non-whitespace Tok in the Token.
    • endTok

      public static Input.Tok endTok(Input.Token token)
      The last non-whitespace Tok in the Token.
    • isComment

      private boolean isComment(String text)
    • union

      private static com.google.common.collect.Range<Integer> union(com.google.common.collect.Range<Integer> x, com.google.common.collect.Range<Integer> y)
    • toString

      public String toString()
      Overrides:
      toString in class Output