Class AutoIndentWriter

java.lang.Object
java.io.Writer
java.io.FilterWriter
org.codehaus.janino.util.AutoIndentWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class AutoIndentWriter extends FilterWriter
A FilterWriter that indents lines by processing some control characters in the character stream.

INDENT or UNINDENT may precede lines and indicate that the line and all following lines should be (un)indented by one position.

TABULATORs may appear anywhere in lines and dictate that portions of all following lines should be vertically aligned (see resolveTabs(List)).

  • Field Details

    • TABULATOR

      public static final char TABULATOR
      Special character indicating a tabular layout of all following lines until UNINDENT.
      See Also:
    • CLEAR_TABULATORS

      public static final char CLEAR_TABULATORS
      Special character at the beginning of a line that flushes a tabular layout.
      See Also:
    • INDENT

      public static final char INDENT
      Special character at the beginning of a line that indents the following text by one position.
      See Also:
    • UNINDENT

      public static final char UNINDENT
      Special character at the beginning of a line that unindents the following text by one position.
      See Also:
    • lineBuffer

      private final StringBuilder lineBuffer
      Buffer for the "current line", including the trailing line break (CR, LF or CRLF).
    • indentation

      private int indentation
      The current indentation level; incremented by a INDENT char at the beginning of a line, and decremented by a UNINDENT char at the beginning of a line.
    • tabulatorBuffer

      @Nullable private List<StringBuilder> tabulatorBuffer
      Iff non-null, then we are in "tab mode". While in tab mode, lines are not printed immediately, but stored in this buffer. Tab mode starts when a line contains a TABULATOR. Tab mode ends when output is unindented beyond the level when tab mode started, or when this writer is closed.

      When tab mode ends, all buffered lines are vertically aligned at the TABULATORs and printed.

    • tabulatorIndentation

      private int tabulatorIndentation
      The indentation when tab mode started.
  • Constructor Details

    • AutoIndentWriter

      public AutoIndentWriter(Writer out)
  • Method Details