|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.antlr.stringtemplate.AutoIndentWriter
public class AutoIndentWriter
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). 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 them but use \n for sure and options like wrap="\n". ST will generate the right thing. Override the default (locale) newline by passing in a string to the constructor.
| Field Summary | |
|---|---|
protected int[] |
anchors
Stack of integer anchors (char positions in line); avoid Integer creation overhead. |
protected int |
anchors_sp
|
protected boolean |
atStartOfLine
|
protected int |
charPosition
Track char position in the line (later we can think about tabs). |
protected int |
charPositionOfStartOfExpr
|
protected java.util.List |
indents
stack of indents; use List as it's much faster than Stack. |
protected int |
lineWidth
|
protected java.lang.String |
newline
\n or \r\n? |
protected java.io.Writer |
out
|
| Fields inherited from interface org.antlr.stringtemplate.StringTemplateWriter |
|---|
NO_WRAP |
| Constructor Summary | |
|---|---|
AutoIndentWriter(java.io.Writer out)
|
|
AutoIndentWriter(java.io.Writer out,
java.lang.String newline)
|
|
| Method Summary | |
|---|---|
int |
getIndentationWidth()
|
protected java.lang.StringBuffer |
getIndentString(int spaces)
|
int |
indent()
|
int |
indent(int spaces)
|
void |
popAnchorPoint()
|
java.lang.String |
popIndentation()
|
void |
pushAnchorPoint()
|
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. |
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 |
writeWrapSeparator(java.lang.String wrap)
Because we might need to wrap at a non-atomic string boundary (such as when we wrap in between template applications |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.List indents
protected int[] anchors
protected int anchors_sp
protected java.lang.String newline
protected java.io.Writer out
protected boolean atStartOfLine
protected int charPosition
protected int lineWidth
protected int charPositionOfStartOfExpr
| Constructor Detail |
|---|
public AutoIndentWriter(java.io.Writer out,
java.lang.String newline)
public AutoIndentWriter(java.io.Writer out)
| Method Detail |
|---|
public void setLineWidth(int lineWidth)
setLineWidth in interface StringTemplateWriterpublic void pushIndentation(java.lang.String indent)
pushIndentation in interface StringTemplateWriterpublic java.lang.String popIndentation()
popIndentation in interface StringTemplateWriterpublic void pushAnchorPoint()
pushAnchorPoint in interface StringTemplateWriterpublic void popAnchorPoint()
popAnchorPoint in interface StringTemplateWriterpublic int getIndentationWidth()
public int write(java.lang.String str)
throws java.io.IOException
write in interface StringTemplateWriterjava.io.IOException
public int writeSeparator(java.lang.String str)
throws java.io.IOException
StringTemplateWriter
writeSeparator in interface StringTemplateWriterjava.io.IOException
public int write(java.lang.String str,
java.lang.String wrap)
throws java.io.IOException
write in interface StringTemplateWriterjava.io.IOException
public int writeWrapSeparator(java.lang.String wrap)
throws java.io.IOException
StringTemplateWriter
writeWrapSeparator in interface StringTemplateWriterjava.io.IOException
public int indent()
throws java.io.IOException
java.io.IOException
public int indent(int spaces)
throws java.io.IOException
java.io.IOExceptionprotected java.lang.StringBuffer getIndentString(int spaces)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||