Package org.codehaus.janino.util
Class AutoIndentWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.FilterWriter
-
- org.codehaus.janino.util.AutoIndentWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class AutoIndentWriter extends java.io.FilterWriterAFilterWriterthat automatically indents lines by looking at trailing opening braces ('{') and leading closing braces ('}').
-
-
Field Summary
Fields Modifier and Type Field Description static charCLEAR_TABULATORSSpecial character indicating to clear all tabluar layout that was configured throughTABULATOR.static charINDENTSpecial character that inserts a line break and indents the following text by one position.private intindentationprivate java.lang.StringBuilderlineBufferstatic charTABULATORSpecial character indicating a tabular layout of the following text.private java.util.List<java.lang.StringBuilder>tabulatorBufferprivate inttabulatorIndentationstatic charUNINDENTSpecial character that inserts a line break and unindents the following text by one position.
-
Constructor Summary
Constructors Constructor Description AutoIndentWriter(java.io.Writer out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()private voidflushTabulatorBuffer()private voidline(java.lang.String line)private static voidresolveTabs(java.util.List<java.lang.StringBuilder> lineGroup)private static java.lang.Stringspaces(int n)voidwrite(char[] cbuf, int off, int len)voidwrite(int c)voidwrite(java.lang.String str, int off, int len)
-
-
-
Field Detail
-
TABULATOR
public static final char TABULATOR
Special character indicating a tabular layout of the following text.- See Also:
- Constant Field Values
-
CLEAR_TABULATORS
public static final char CLEAR_TABULATORS
Special character indicating to clear all tabluar layout that was configured throughTABULATOR.- See Also:
- Constant Field Values
-
INDENT
public static final char INDENT
Special character that inserts a line break and indents the following text by one position.- See Also:
- Constant Field Values
-
UNINDENT
public static final char UNINDENT
Special character that inserts a line break and unindents the following text by one position.- See Also:
- Constant Field Values
-
lineBuffer
private final java.lang.StringBuilder lineBuffer
-
indentation
private int indentation
-
tabulatorBuffer
@Nullable private java.util.List<java.lang.StringBuilder> tabulatorBuffer
-
tabulatorIndentation
private int tabulatorIndentation
-
-
Method Detail
-
write
public void write(@Nullable char[] cbuf, int off, int len) throws java.io.IOException
- Overrides:
writein classjava.io.FilterWriter- Throws:
java.io.IOException
-
write
public void write(@Nullable java.lang.String str, int off, int len) throws java.io.IOException
- Overrides:
writein classjava.io.FilterWriter- Throws:
java.io.IOException
-
write
public void write(int c) throws java.io.IOException- Overrides:
writein classjava.io.FilterWriter- Throws:
java.io.IOException
-
line
private void line(java.lang.String line) throws java.io.IOException- Throws:
java.io.IOException
-
flushTabulatorBuffer
private void flushTabulatorBuffer() throws java.io.IOException- Throws:
java.io.IOException
-
resolveTabs
private static void resolveTabs(java.util.List<java.lang.StringBuilder> lineGroup)
-
spaces
private static java.lang.String spaces(int n)
- Returns:
- a
Stringofnspaces
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterWriter- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.FilterWriter- Throws:
java.io.IOException
-
-