gnu.text
Class PrettyWriter

java.lang.Object
  extended by java.io.Writer
      extended by gnu.text.PrettyWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class PrettyWriter
extends java.io.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.
 int bufferFillPointer
          The index into BUFFER where more text should be put.
static ThreadLocation indentLoc
           
static int initialBufferSize
           
 boolean isPrettyPrinting
           
static ThreadLocation lineLengthLoc
           
static ThreadLocation miserWidthLoc
           
static int NEWLINE_FILL
           
static int NEWLINE_LINEAR
           
static int NEWLINE_LITERAL
           
static int NEWLINE_MANDATORY
           
static int NEWLINE_MISER
           
static int NEWLINE_SPACE
          A non-nested ' ' gets an implicit NEWLINE_SPACE.
protected  java.io.Writer out
           
 int pendingBlocksCount
          Number of startLogicalBlock - number of endLogicalBlock.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
PrettyWriter(java.io.Writer out)
           
PrettyWriter(java.io.Writer out, boolean isPrettyPrinting)
           
PrettyWriter(java.io.Writer out, int lineLength)
           
 
Method Summary
 void addIndentation(int amount, boolean current)
           
 void clearBuffer()
           
 void close()
           
 void endLogicalBlock()
           
 void endLogicalBlock(java.lang.String suffix)
           
 int enqueue(int kind, int size)
           
 int enqueueIndent(char kind, int amount)
           
 void enqueueNewline(int kind)
           
 void flush()
           
 void forcePrettyOutput()
           
 int getColumnNumber()
          Not meaningful if isPrettyPrinting.
protected  int getMiserWidth()
           
 void lineAbbreviationHappened()
           
 void setColumnNumber(int column)
           
 void setIndentation(int column)
           
 void startLogicalBlock(java.lang.String prefix, boolean perLine, java.lang.String suffix)
           
 void write(char[] str)
           
 void write(char[] str, int start, int count)
           
 void write(int ch)
           
 void write(java.lang.String str)
           
 void write(java.lang.String str, int start, int count)
           
 void writeBreak(int kind)
           
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.Writer out

lineLengthLoc

public static ThreadLocation lineLengthLoc

miserWidthLoc

public static ThreadLocation miserWidthLoc

indentLoc

public static ThreadLocation indentLoc

isPrettyPrinting

public boolean isPrettyPrinting

initialBufferSize

public static int initialBufferSize

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.


pendingBlocksCount

public int pendingBlocksCount
Number of startLogicalBlock - number of endLogicalBlock.


NEWLINE_LINEAR

public static final int NEWLINE_LINEAR
See Also:
Constant Field Values

NEWLINE_LITERAL

public static final int NEWLINE_LITERAL
See Also:
Constant Field Values

NEWLINE_FILL

public static final int NEWLINE_FILL
See Also:
Constant Field Values

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.

See Also:
Constant Field Values

NEWLINE_MISER

public static final int NEWLINE_MISER
See Also:
Constant Field Values

NEWLINE_MANDATORY

public static final int NEWLINE_MANDATORY
See Also:
Constant Field Values
Constructor Detail

PrettyWriter

public PrettyWriter(java.io.Writer out)

PrettyWriter

public PrettyWriter(java.io.Writer out,
                    int lineLength)

PrettyWriter

public PrettyWriter(java.io.Writer out,
                    boolean isPrettyPrinting)
Method Detail

write

public void write(int ch)
Overrides:
write in class java.io.Writer

write

public void write(java.lang.String str)
Overrides:
write in class java.io.Writer

write

public void write(java.lang.String str,
                  int start,
                  int count)
Overrides:
write in class java.io.Writer

write

public void write(char[] str)
Overrides:
write in class java.io.Writer

write

public void write(char[] str,
                  int start,
                  int count)
Specified by:
write in class java.io.Writer

setIndentation

public void setIndentation(int column)

enqueue

public int enqueue(int kind,
                   int size)

enqueueNewline

public void enqueueNewline(int kind)

writeBreak

public final void writeBreak(int kind)

enqueueIndent

public int enqueueIndent(char kind,
                         int amount)

addIndentation

public void addIndentation(int amount,
                           boolean current)

startLogicalBlock

public void startLogicalBlock(java.lang.String prefix,
                              boolean perLine,
                              java.lang.String suffix)

endLogicalBlock

public void endLogicalBlock()

endLogicalBlock

public void endLogicalBlock(java.lang.String suffix)

getMiserWidth

protected int getMiserWidth()

lineAbbreviationHappened

public void lineAbbreviationHappened()

forcePrettyOutput

public void forcePrettyOutput()
                       throws java.io.IOException
Throws:
java.io.IOException

flush

public void flush()
Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException

getColumnNumber

public int getColumnNumber()
Not meaningful if isPrettyPrinting.


setColumnNumber

public void setColumnNumber(int column)

clearBuffer

public void clearBuffer()