Class AutoIndentWriter

  • All Implemented Interfaces:
    STWriter
    Direct Known Subclasses:
    NoIndentWriter

    public class AutoIndentWriter
    extends java.lang.Object
    implements STWriter
    Essentially a char filter that knows how to auto-indent output by maintaining a stack of indent levels.

    The indent stack is a stack of strings so we can repeat original indent not just the same number of columns (don't have to worry about tabs vs spaces then). Anchors are char positions (tabs won't work) that indicate where all future wraps should justify to. The wrap position is actually the larger of either the last anchor or the indentation level.

    This is a filter on a Writer.

    \n is the proper way to say newline for options and templates. Templates can mix \r\n and \n them, but use \n in options like wrap="\n". This writer will render newline characters according to newline. The default value is taken from the line.separator system property, and can be overridden by passing in a String to the appropriate constructor.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      int[] anchors
      Stack of integer anchors (char positions in line); avoid Integer creation overhead.
      int anchors_sp  
      boolean atStartOfLine  
      int charIndex
      The absolute char index into the output of the next char to be written.
      int charPosition
      Track char position in the line (later we can think about tabs).
      java.util.List<java.lang.String> indents
      Stack of indents.
      int lineWidth  
      java.lang.String newline
      \n or \r\n?
      java.io.Writer out  
    • Constructor Summary

      Constructors 
      Constructor Description
      AutoIndentWriter​(java.io.Writer out)  
      AutoIndentWriter​(java.io.Writer out, java.lang.String newline)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int indent()  
      int index()
      Return the absolute char index into the output of the char we're about to write.
      void popAnchorPoint()  
      java.lang.String popIndentation()  
      void pushAnchorPoint()  
      void pushIndentation​(java.lang.String indent)  
      void setLineWidth​(int lineWidth)  
      int write​(java.lang.String str)
      Write out a string literal or attribute expression or expression element.
      int write​(java.lang.String str, java.lang.String wrap)
      Write out a string literal or attribute expression or expression element.
      int writeSeparator​(java.lang.String str)
      Write a separator.
      int writeWrap​(java.lang.String wrap)
      Because we evaluate ST instance by invoking Interpreter.exec(STWriter, InstanceScope) again, we can't pass options in.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait