|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.stringtemplate.v4.AutoIndentWriter
public class AutoIndentWriter
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 for sure in 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 | |
|---|---|
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). |
List<String> |
indents
stack of indents; use List as it's much faster than Stack. |
int |
lineWidth
|
String |
newline
\n or \r\n? |
Writer |
out
|
| Fields inherited from interface org.stringtemplate.v4.STWriter |
|---|
NO_WRAP |
| Constructor Summary | |
|---|---|
AutoIndentWriter(Writer out)
|
|
AutoIndentWriter(Writer out,
String newline)
|
|
| Method Summary | |
|---|---|
int |
indent()
|
int |
index()
Return the absolute char index into the output of the char we're about to write. |
void |
popAnchorPoint()
|
String |
popIndentation()
|
void |
pushAnchorPoint()
|
void |
pushIndentation(String indent)
|
void |
setLineWidth(int lineWidth)
|
int |
write(String str)
Write out a string literal or attribute expression or expression element. |
int |
write(String str,
String wrap)
Write out a string literal or attribute expression or expression element. |
int |
writeSeparator(String str)
Write a separator. |
int |
writeWrap(String wrap)
Because we evaluate ST instance by invoking exec() 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 |
| Field Detail |
|---|
public List<String> indents
public int[] anchors
public int anchors_sp
public String newline
public Writer out
public boolean atStartOfLine
public int charPosition
public int charIndex
public int lineWidth
| Constructor Detail |
|---|
public AutoIndentWriter(Writer out,
String newline)
public AutoIndentWriter(Writer out)
| Method Detail |
|---|
public void setLineWidth(int lineWidth)
setLineWidth in interface STWriterpublic void pushIndentation(String indent)
pushIndentation in interface STWriterpublic String popIndentation()
popIndentation in interface STWriterpublic void pushAnchorPoint()
pushAnchorPoint in interface STWriterpublic void popAnchorPoint()
popAnchorPoint in interface STWriterpublic int index()
STWriter
index in interface STWriter
public int write(String str)
throws IOException
write in interface STWriterIOException
public int writeSeparator(String str)
throws IOException
STWriter
writeSeparator in interface STWriterIOException
public int write(String str,
String wrap)
throws IOException
write in interface STWriterIOException
public int writeWrap(String wrap)
throws IOException
STWriter
writeWrap in interface STWriterIOException
public int indent()
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||