Class AutoIndentWriter
- All Implemented Interfaces:
STWriter
- Direct Known Subclasses:
NoIndentWriter
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
FieldsModifier and TypeFieldDescriptionint[]Stack of integer anchors (char positions in line); avoidIntegercreation overhead.intbooleanintThe absolute char index into the output of the next char to be written.intTrack char position in the line (later we can think about tabs).Stack of indents.int\nor\r\n? -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintindent()intindex()Return the absolute char index into the output of the char we're about to write.voidvoidvoidpushIndentation(String indent) voidsetLineWidth(int lineWidth) intWrite out a string literal or attribute expression or expression element.intWrite out a string literal or attribute expression or expression element.intwriteSeparator(String str) Write a separator.intBecause we evaluate ST instance by invokingInterpreter.exec(STWriter, InstanceScope)again, we can't pass options in.
-
Field Details
-
indents
-
anchors
public int[] anchorsStack of integer anchors (char positions in line); avoidIntegercreation overhead. -
anchors_sp
public int anchors_sp -
newline
\nor\r\n? -
out
-
atStartOfLine
public boolean atStartOfLine -
charPosition
public int charPositionTrack char position in the line (later we can think about tabs). Indexed from 0. We want to keepcharPosition <=lineWidth. This is the position we are about to write, not the position last written to. -
charIndex
public int charIndexThe absolute char index into the output of the next char to be written. -
lineWidth
public int lineWidth
-
-
Constructor Details
-
AutoIndentWriter
-
AutoIndentWriter
-
-
Method Details
-
setLineWidth
public void setLineWidth(int lineWidth) - Specified by:
setLineWidthin interfaceSTWriter
-
pushIndentation
- Specified by:
pushIndentationin interfaceSTWriter
-
popIndentation
- Specified by:
popIndentationin interfaceSTWriter
-
pushAnchorPoint
public void pushAnchorPoint()- Specified by:
pushAnchorPointin interfaceSTWriter
-
popAnchorPoint
public void popAnchorPoint()- Specified by:
popAnchorPointin interfaceSTWriter
-
index
-
write
Write out a string literal or attribute expression or expression element.- Specified by:
writein interfaceSTWriter- Throws:
IOException
-
writeSeparator
Description copied from interface:STWriterWrite a separator. Same asSTWriter.write(String)except that a"\n"cannot be inserted before emitting a separator.- Specified by:
writeSeparatorin interfaceSTWriter- Throws:
IOException
-
write
Write out a string literal or attribute expression or expression element.If doing line wrap, then check
wrapbefore emittingstr. If at or beyond desired line width then emit anewlineand any indentation before spitting outstr.- Specified by:
writein interfaceSTWriter- Throws:
IOException
-
writeWrap
Description copied from interface:STWriterBecause we evaluate ST instance by invokingInterpreter.exec(STWriter, InstanceScope)again, we can't pass options in. So theBytecode.INSTR_WRITEinstruction of an applied template (such as when we wrap in between template applications like<data:{v|[<v>]}; wrap>) we need to write thewrapstring before callingInterpreter.exec(STWriter, InstanceScope). We expose just like for the separator. SeeInterpreter.writeObject(STWriter, InstanceScope, Object, String[])where it checks for ST instance. If POJO,Interpreter.writePOJO(STWriter, InstanceScope, Object, String[])passeswraptoSTWriter.write(String str, String wrap). Can't pass toInterpreter.exec(STWriter, InstanceScope).- Specified by:
writeWrapin interfaceSTWriter- Throws:
IOException
-
indent
- Throws:
IOException
-