Package org.codehaus.janino.util
Class AutoIndentWriter
java.lang.Object
java.io.Writer
java.io.FilterWriter
org.codehaus.janino.util.AutoIndentWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
A
FilterWriter
that indents lines by processing some control characters in the character stream.
INDENT
or UNINDENT
may precede lines and indicate that the line and all following lines should
be (un)indented by one position.
TABULATOR
s may appear anywhere in lines and dictate that portions of all following lines should be
vertically aligned (see resolveTabs(List)
).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
Special character at the beginning of a line that flushes a tabular layout.static final char
Special character at the beginning of a line that indents the following text by one position.private int
private final StringBuilder
Buffer for the "current line", including the trailing line break (CR, LF or CRLF).static final char
Special character indicating a tabular layout of all following lines untilUNINDENT
.private List
<StringBuilder> Iff non-null, then we are in "tab mode".private int
Theindentation
when tab mode started.static final char
Special character at the beginning of a line that unindents the following text by one position.Fields inherited from class java.io.FilterWriter
out
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
private void
private void
private static void
resolveTabs
(List<StringBuilder> lineGroup) Expands allTABULATOR
s in the givenList
ofStringBuilder
s with spaces, so that the characters immediately following theTABULATOR
s are vertically aligned, like this:private static String
spaces
(int n) void
write
(char[] cbuf, int off, int len) void
write
(int c) void
-
Field Details
-
TABULATOR
public static final char TABULATORSpecial character indicating a tabular layout of all following lines untilUNINDENT
.- See Also:
-
CLEAR_TABULATORS
public static final char CLEAR_TABULATORSSpecial character at the beginning of a line that flushes a tabular layout.- See Also:
-
INDENT
public static final char INDENTSpecial character at the beginning of a line that indents the following text by one position.- See Also:
-
UNINDENT
public static final char UNINDENTSpecial character at the beginning of a line that unindents the following text by one position.- See Also:
-
lineBuffer
Buffer for the "current line", including the trailing line break (CR, LF or CRLF). -
indentation
private int indentation -
tabulatorBuffer
Iff non-null, then we are in "tab mode". While in tab mode, lines are not printed immediately, but stored in this buffer. Tab mode starts when a line contains aTABULATOR
. Tab mode ends when output is unindented beyond the level when tab mode started, or when this writer is closed.When tab mode ends, all buffered lines are vertically aligned at the
TABULATOR
s and printed. -
tabulatorIndentation
private int tabulatorIndentationTheindentation
when tab mode started.
-
-
Constructor Details
-
AutoIndentWriter
-
-
Method Details
-
write
- Overrides:
write
in classFilterWriter
- Throws:
IOException
-
write
- Overrides:
write
in classFilterWriter
- Throws:
IOException
-
write
- Overrides:
write
in classFilterWriter
- Throws:
IOException
-
line
- Throws:
IOException
-
flushTabulatorBuffer
- Throws:
IOException
-
resolveTabs
Expands allTABULATOR
s in the givenList
ofStringBuilder
s with spaces, so that the characters immediately following theTABULATOR
s are vertically aligned, like this:Input:
a @b @c\r\n aa @bb @cc\r\n aaa @bbb @ccc\r\n
Output:
a b c\r\n aa bb cc\r\n aaa bbb ccc\r\n
-
spaces
- Returns:
- a
String
ofn
spaces
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterWriter
- Throws:
IOException
-