Package com.tonic.analysis.source.emit
Class IndentingWriter
- java.lang.Object
-
- com.tonic.analysis.source.emit.IndentingWriter
-
public class IndentingWriter extends Object
A writer that inserts the configured indent unit at the start of each line.
-
-
Constructor Summary
Constructors Constructor Description IndentingWriter(Writer writer)Creates a writer indenting with tabs.IndentingWriter(Writer writer, String indentString)Creates a writer with the given indent unit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidblankLine()Writes an empty line.voiddedent()Decreases the indentation level, never going below zero.voidflush()Flushes the underlying writer.intgetCurrentLine()intgetIndentLevel()voidindent()Increases the indentation level.voidnewLine()Writes a newline.StringtoString()Flushes and returns the accumulated output.static IndentingWritertoStringWriter()Creates a writer accumulating into a StringWriter, readable via toString().voidwrite(String text)Writes text, emitting the indent before the first character of each line.voidwriteLine(String text)Writes text followed by a newline.voidwriteRaw(String text)Writes already-formatted text without adding indentation, still tracking lines.
-
-
-
Constructor Detail
-
IndentingWriter
public IndentingWriter(Writer writer)
Creates a writer indenting with tabs.- Parameters:
writer- the underlying writer
-
-
Method Detail
-
toStringWriter
public static IndentingWriter toStringWriter()
Creates a writer accumulating into a StringWriter, readable via toString().- Returns:
- the string-backed writer
-
indent
public void indent()
Increases the indentation level.
-
dedent
public void dedent()
Decreases the indentation level, never going below zero.
-
write
public void write(String text)
Writes text, emitting the indent before the first character of each line.- Parameters:
text- the text to write- Throws:
RuntimeException- if the underlying writer fails
-
writeLine
public void writeLine(String text)
Writes text followed by a newline.- Parameters:
text- the text to write
-
newLine
public void newLine()
Writes a newline.- Throws:
RuntimeException- if the underlying writer fails
-
blankLine
public void blankLine()
Writes an empty line.
-
getIndentLevel
public int getIndentLevel()
- Returns:
- the current indentation level
-
writeRaw
public void writeRaw(String text)
Writes already-formatted text without adding indentation, still tracking lines.- Parameters:
text- the text to write- Throws:
RuntimeException- if the underlying writer fails
-
getCurrentLine
public int getCurrentLine()
- Returns:
- the 1-based line number the next character will be written to
-
flush
public void flush()
Flushes the underlying writer.- Throws:
RuntimeException- if flushing fails
-
-