Class CodeBuffer

    • Constructor Detail

      • CodeBuffer

        public CodeBuffer()
    • Method Detail

      • getOutput

        public final java.lang.String getOutput()
        Returns buffer as String.
      • getCurrentLength

        public final int getCurrentLength()
        Returns the current length of the buffer.
      • getLastChar

        public final char getLastChar()
        Returns the last character in the buffer.
      • getNextCharIndex

        public final int getNextCharIndex()
        Returns nextCharIndex.
      • getNextLineIndex

        public final int getNextLineIndex()
        Returns nextLineIndex.
      • getLastCharIndex

        public final int getLastCharIndex()
        Returns lastCharIndex.
      • getLastLineIndex

        public final int getLastLineIndex()
        Returns the index of the line which contains the last character at lastCharIndex. It is always the same or 1 index behind nextLineIndex.
      • append

        public final CodeBuffer append​(@Nullable
                                       java.lang.String str)
        Appends str to the buffer. The string is safe to contain newlines. nextCharIndex and nextLineIndex will be updated accordingly.

        Prefer to use append(char c) API to append characters for efficiency.

      • append

        public final CodeBuffer append​(char c)
        Appends c to the buffer and update nextCharIndex.
      • append

        public final CodeBuffer append​(java.lang.Object o)
        Appends the toString representation of o to the buffer.
      • startNewLine

        public final CodeBuffer startNewLine()
        Appends a newline to buffer, resetting nextCharIndex and incrementing nextLineIndex.
      • deleteLastChar

        public final CodeBuffer deleteLastChar()
        Deletes the last character in the buffer and updates the nextCharIndex and nextLineIndex.
      • deleteLastChars

        public final CodeBuffer deleteLastChars​(int n)
        Deletes last n characters in the buffer.
      • reset

        public final CodeBuffer reset()
        Clears the contents of the buffer and resets nextCharIndex and nextLineIndex.
      • deleteLastCharIfCharIs

        public void deleteLastCharIfCharIs​(char ch)
        Deletes the last character from the string builder if the character is as given.

        Subclasses can modify this method in order to delete more in cases where they've added extra delimiters.

        Parameters:
        ch - the character to delete
      • deleteEndingIfEndingIs

        public void deleteEndingIfEndingIs​(java.lang.String s)
        Deletes the end of the buffer if it exactly equals s.