gnu.text

Class PrettyWriter

public class PrettyWriter extends Writer

A pretty printer. This code is transcribed from pprint.lisp in Steel Bank Common Lisp, which is again based on the code in CMU Common Lisp.
Field Summary
char[]buffer
Holds all the text that has been output but not yet printed.
intbufferFillPointer
The index into BUFFER where more text should be put.
static ThreadLocationindentLoc
static intinitialBufferSize
static ThreadLocationlineLengthLoc
static ThreadLocationmiserWidthLoc
static intNEWLINE_FILL
static intNEWLINE_LINEAR
static intNEWLINE_LITERAL
static intNEWLINE_MANDATORY
static intNEWLINE_MISER
static intNEWLINE_SPACE
A non-nested ' ' gets an implicit NEWLINE_SPACE.
protected Writerout
intpendingBlocksCount
Number of startLogicalBlock - number of endLogicalBlock.
Constructor Summary
PrettyWriter(Writer out)
PrettyWriter(Writer out, int lineLength)
PrettyWriter(Writer out, boolean prettyPrintingMode)
Method Summary
voidaddIndentation(int amount, boolean current)
voidclearBuffer()
voidclearWordEnd()
voidclose()
voidendLogicalBlock()
voidendLogicalBlock(String suffix)
intenqueue(int kind, int size)
intenqueueIndent(char kind, int amount)
voidenqueueNewline(int kind)
voidflush()
voidforcePrettyOutput()
intgetColumnNumber()
Not meaningful if {@code prettyPrintingMode > 0}.
protected intgetMiserWidth()
intgetPrettyPrintingMode()
Return pretty-printing mode.
booleanisPrettyPrinting()
Is pretty printing enabled?
voidlineAbbreviationHappened()
voidsetColumnNumber(int column)
voidsetIndentation(int column)
voidsetPrettyPrinting(boolean mode)
Turn pretty printing on or off.
voidsetPrettyPrintingMode(int mode)
Control pretty-printing mode.
voidstartLogicalBlock(String prefix, boolean perLine, String suffix)
voidwrite(int ch)
voidwrite(String str)
voidwrite(String str, int start, int count)
voidwrite(char[] str)
voidwrite(char[] str, int start, int count)
voidwriteBreak(int kind)
voidwriteWordEnd()
Note the end of a "word".
voidwriteWordStart()
Maybe write a word-separating space.

Field Detail

buffer

public char[] buffer
Holds all the text that has been output but not yet printed.

bufferFillPointer

public int bufferFillPointer
The index into BUFFER where more text should be put.

indentLoc

public static ThreadLocation indentLoc

initialBufferSize

public static int initialBufferSize

lineLengthLoc

public static ThreadLocation lineLengthLoc

miserWidthLoc

public static ThreadLocation miserWidthLoc

NEWLINE_FILL

public static final int NEWLINE_FILL

NEWLINE_LINEAR

public static final int NEWLINE_LINEAR

NEWLINE_LITERAL

public static final int NEWLINE_LITERAL

NEWLINE_MANDATORY

public static final int NEWLINE_MANDATORY

NEWLINE_MISER

public static final int NEWLINE_MISER

NEWLINE_SPACE

public static final int NEWLINE_SPACE
A non-nested ' ' gets an implicit NEWLINE_SPACE. This is treated similarly to NEWLINE_FILL, but not quite.

out

protected Writer out

pendingBlocksCount

public int pendingBlocksCount
Number of startLogicalBlock - number of endLogicalBlock.

Constructor Detail

PrettyWriter

public PrettyWriter(Writer out)

PrettyWriter

public PrettyWriter(Writer out, int lineLength)

PrettyWriter

public PrettyWriter(Writer out, boolean prettyPrintingMode)

Method Detail

addIndentation

public void addIndentation(int amount, boolean current)

clearBuffer

public void clearBuffer()

clearWordEnd

public void clearWordEnd()

close

public void close()

endLogicalBlock

public void endLogicalBlock()

endLogicalBlock

public void endLogicalBlock(String suffix)

enqueue

public int enqueue(int kind, int size)

enqueueIndent

public int enqueueIndent(char kind, int amount)

enqueueNewline

public void enqueueNewline(int kind)

flush

public void flush()

forcePrettyOutput

public void forcePrettyOutput()

getColumnNumber

public int getColumnNumber()
Not meaningful if {@code prettyPrintingMode > 0}.

getMiserWidth

protected int getMiserWidth()

getPrettyPrintingMode

public int getPrettyPrintingMode()
Return pretty-printing mode.

Returns: 0, 1, 2, as described for {@link #setPrettyPrintingMode(int)}.

isPrettyPrinting

public boolean isPrettyPrinting()
Is pretty printing enabled?

lineAbbreviationHappened

public void lineAbbreviationHappened()

setColumnNumber

public void setColumnNumber(int column)

setIndentation

public void setIndentation(int column)

setPrettyPrinting

public void setPrettyPrinting(boolean mode)
Turn pretty printing on or off. Equivalent to {@code setPrettyPrintingMode(mode?1:0)}.

setPrettyPrintingMode

public void setPrettyPrintingMode(int mode)
Control pretty-printing mode.

Parameters: mode the value 0 disables pretty-printing; the value 1 enables ecplicit pretty-printing; the value 2 enables pretty-printing with auto-fill, which means that spaces are treated like enqueing NEWLINE_SPACE (essentiall a 'fill').

startLogicalBlock

public void startLogicalBlock(String prefix, boolean perLine, String suffix)

write

public void write(int ch)

write

public void write(String str)

write

public void write(String str, int start, int count)

write

public void write(char[] str)

write

public void write(char[] str, int start, int count)

writeBreak

public final void writeBreak(int kind)

writeWordEnd

public void writeWordEnd()
Note the end of a "word". See {@link #writeWordStart}.

writeWordStart

public void writeWordStart()
Maybe write a word-separating space. Specifically, write a space if the previous output was {@link #writeWordEnd}. Otherwise, do nothing.