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 Detail

      • lineSeparator

        private final java.lang.String lineSeparator
      • javaInput

        private final Input javaInput
      • partialFormatRanges

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

        private final java.util.List<java.lang.String> mutableLines
      • kN

        private final int kN
      • iLine

        private int iLine
      • lastK

        private int lastK
      • newlinesPending

        private int newlinesPending
      • lineBuilder

        private java.lang.StringBuilder lineBuilder
      • spacesPending

        private java.lang.StringBuilder spacesPending
    • Constructor Detail

      • JavaOutput

        public JavaOutput​(java.lang.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 Detail

      • 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
      • append

        public void append​(java.lang.String text,
                           com.google.common.collect.Range<java.lang.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.
      • getFormatReplacements

        public com.google.common.collect.ImmutableList<Replacement> getFormatReplacements​(com.google.common.collect.RangeSet<java.lang.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<java.lang.Integer> expandToBreakableRegions​(com.google.common.collect.Range<java.lang.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 java.lang.String applyReplacements​(java.lang.String input,
                                                         java.util.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​(java.lang.String text)
      • union

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

        public java.lang.String toString()
        Overrides:
        toString in class Output