org.antlr.stringtemplate
Class AutoIndentWriter
java.lang.Object
org.antlr.stringtemplate.AutoIndentWriter
- All Implemented Interfaces:
- StringTemplateWriter
- Direct Known Subclasses:
- NoIndentWriter
- public class AutoIndentWriter
- extends java.lang.Object
- implements StringTemplateWriter
Essentially a char filter that knows how to auto-indent output
by maintaining a stack of indent levels. I set a flag upon newline
and then next nonwhitespace char resets flag and spits out indention.
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).
This is a filter on a Writer.
It may be screwed up for '\r' '\n' on PC's.
Method Summary |
int |
indent()
|
java.lang.String |
popIndentation()
|
void |
pushIndentation(java.lang.String indent)
Push even blank (null) indents as they are like scopes; must
be able to pop them back off stack. |
int |
write(java.lang.String str)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BUFFER_SIZE
public static final int BUFFER_SIZE
- See Also:
- Constant Field Values
indents
protected java.util.Stack indents
out
protected java.io.Writer out
atStartOfLine
protected boolean atStartOfLine
AutoIndentWriter
public AutoIndentWriter(java.io.Writer out)
pushIndentation
public void pushIndentation(java.lang.String indent)
- Push even blank (null) indents as they are like scopes; must
be able to pop them back off stack.
- Specified by:
pushIndentation
in interface StringTemplateWriter
popIndentation
public java.lang.String popIndentation()
- Specified by:
popIndentation
in interface StringTemplateWriter
write
public int write(java.lang.String str)
throws java.io.IOException
- Specified by:
write
in interface StringTemplateWriter
- Throws:
java.io.IOException
indent
public int indent()
throws java.io.IOException
- Throws:
java.io.IOException