| java.lang.Object java.io.Writer gnu.text.PrettyWriter
PrettyWriter | public class PrettyWriter extends java.io.Writer (Code) | | 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 | |
final public static int | NEWLINE_FILL | final public static int | NEWLINE_LINEAR | final public static int | NEWLINE_LITERAL | final public static int | NEWLINE_MANDATORY | final public static int | NEWLINE_MISER | final public static int | NEWLINE_SPACE A non-nested ' ' gets an implicit NEWLINE_SPACE.
This is treated similarly to NEWLINE_FILL, but not quite. | final static int | QITEM_BASE_SIZE Size of "base part" of a QITEM. | final static int | QITEM_BLOCK_END_SIZE | final static int | QITEM_BLOCK_END_TYPE | final static int | QITEM_BLOCK_START_BLOCK_END If the QITEM_BLOCK_START_BLOCK_END < 0, it points to
the previous (outer) un-closed block-start.
If QITEM_BLOCK_START_BLOCK_END > 0, it points to the
corresponding block-end node.
In both cases the pointers are relative to the current BLOCK_START. | final static int | QITEM_BLOCK_START_PREFIX | final static int | QITEM_BLOCK_START_SIZE | final static int | QITEM_BLOCK_START_SUFFIX | final static int | QITEM_BLOCK_START_TYPE A "block-start" queue item. | final static int | QITEM_INDENTATION_AMOUNT | final static char | QITEM_INDENTATION_BLOCK | final static char | QITEM_INDENTATION_CURRENT | final static int | QITEM_INDENTATION_KIND | final static int | QITEM_INDENTATION_SIZE | final static int | QITEM_INDENTATION_TYPE | final static int | QITEM_NEWLINE_KIND | final static int | QITEM_NEWLINE_SIZE | final static int | QITEM_NEWLINE_TYPE A newline queue item. | final static int | QITEM_NOP_TYPE A dummy queue item used at the high end of the queue buffer
when there isn't enough space for the needed queue item. | final static int | QITEM_POSN | final static int | QITEM_SECTION_START_DEPTH | final static int | QITEM_SECTION_START_SECTION_END | final static int | QITEM_SECTION_START_SIZE "Abstract" type for beginning of section.
A section is from a block-start to a newline, from a newline to
the next newline (in the same block?), or from a newline to
the block end (?). | final static int | QITEM_TAB_COLINC | final static int | QITEM_TAB_COLNUM | final static int | QITEM_TAB_FLAGS | final static int | QITEM_TAB_IS_RELATIVE | final static int | QITEM_TAB_IS_SECTION | final static int | QITEM_TAB_SIZE | final static int | QITEM_TAB_TYPE | final static int | QITEM_TYPE_AND_SIZE The first it QITEM contains it type code and size.
The type code is one of the QITEM_XXX_TYPE values below.
The size is the corresponding QITEM_XXX_SIZE value below,
except for the case of QITEM_NOP_TYPE (which is used as a filler). | final static int | QUEUE_INIT_ALLOC_SIZE | int | blockDepth The "stack pointer" in the
blocks array. | int[] | blocks Stack of logical blocks in effect at the buffer start.
I.e. | public char[] | buffer Holds all the text that has been output but not yet printed. | public int | bufferFillPointer The index into BUFFER where more text should be put. | int | bufferOffset Total amount of stuff that has been shifted out of the buffer.
Whenever we output stuff from the buffer, we shift the remaining noise
over. | int | bufferStartColumn The column the first character in the buffer will appear in.
Normally zero, but if we end up with a very long line with no breaks in it
we might have to output part of it. | int | currentBlock If >= 0, index (into queueInts) of current unclosed begin-block node. | public static ThreadLocation | indentLoc | public static int | initialBufferSize | int | lineLength Line length we should format to. | public static ThreadLocation | lineLengthLoc | int | lineNumber The line number we are currently on. | int | miserWidth | public static ThreadLocation | miserWidthLoc | protected Writer | out | public int | pendingBlocksCount Number of startLogicalBlock - number of endLogicalBlock. | char[] | prefix Buffer holding the per-line prefix active at the buffer start.
Indentation is included in this. | int | prettyPrintingMode The current pretty-printing mode.
See setPrettyPrintingMode for valid values. | int[] | queueInts A queue of pending operations.
This is primarily stored in the circular buffer queueInts. | int | queueSize Number of elements (in queueInts and queueStrings) in use. | String[] | queueStrings For simplicity, queueStrings is the same size as queueInts. | int | queueTail Index in queueInts and queueStrings of oldest enqueued operation. | char[] | suffix Buffer holding the total remaining suffix active at the buffer start.
The characters are right-justified in the buffer to make it easier
to output the buffer. | boolean | wordEndSeen |
Method Summary | |
public void | addIndentation(int amount, boolean current) | public void | clearBuffer() | public void | clearWordEnd() | public void | close() | int | computeTabSize(int tab, int sectionStart, int column) | public void | endLogicalBlock() | public void | endLogicalBlock(String suffix) | public int | enqueue(int kind, int size) | public int | enqueueIndent(char kind, int amount) | public void | enqueueNewline(int kind) | int | enqueueTab(int flags, int colnum, int colinc) | int | ensureSpaceInBuffer(int want) | void | expandTabs(int through) | int | fitsOnLine(int sectionEnd, boolean forceNewlines) Return 1 if true; -1 if false; 0 if don't know. | public void | flush() | public void | forcePrettyOutput() | public int | getColumnNumber() Not meaningful if
prettyPrintingMode > 0 . | int | getMaxLines() | protected int | getMiserWidth() | public int | getPrettyPrintingMode() Return pretty-printing mode. | int | indexColumn(int index) | boolean | isMisering() | public boolean | isPrettyPrinting() | public void | lineAbbreviationHappened() | boolean | maybeOutput(boolean forceNewlines, boolean flushing) | void | outputLine(int newline) Output a new line. | void | outputPartialLine() | boolean | printReadably() | void | reallyEndLogicalBlock() | void | reallyStartLogicalBlock(int column, String prefix, String suffix) | public void | setColumnNumber(int column) | public void | setIndentation(int column) | public void | setPrettyPrinting(boolean mode) Turn pretty printing on or off. | public void | setPrettyPrintingMode(int mode) Control pretty-printing mode. | public void | startLogicalBlock(String prefix, boolean perLine, String suffix) | public void | write(int ch) | public void | write(String str) | public void | write(String str, int start, int count) | public void | write(char[] str) | public void | write(char[] str, int start, int count) | final public void | writeBreak(int kind) | public void | writeWordEnd() Note the end of a "word". | public void | writeWordStart() Maybe write a word-separating space.
Specifically, write a space if the previous output
was
PrettyWriter.writeWordEnd . |
NEWLINE_FILL | final public static int NEWLINE_FILL(Code) | | |
NEWLINE_LINEAR | final public static int NEWLINE_LINEAR(Code) | | |
NEWLINE_LITERAL | final public static int NEWLINE_LITERAL(Code) | | |
NEWLINE_MANDATORY | final public static int NEWLINE_MANDATORY(Code) | | |
NEWLINE_MISER | final public static int NEWLINE_MISER(Code) | | |
NEWLINE_SPACE | final public static int NEWLINE_SPACE(Code) | | A non-nested ' ' gets an implicit NEWLINE_SPACE.
This is treated similarly to NEWLINE_FILL, but not quite.
|
QITEM_BASE_SIZE | final static int QITEM_BASE_SIZE(Code) | | Size of "base part" of a QITEM.
|
QITEM_BLOCK_END_SIZE | final static int QITEM_BLOCK_END_SIZE(Code) | | |
QITEM_BLOCK_END_TYPE | final static int QITEM_BLOCK_END_TYPE(Code) | | |
QITEM_BLOCK_START_BLOCK_END | final static int QITEM_BLOCK_START_BLOCK_END(Code) | | If the QITEM_BLOCK_START_BLOCK_END < 0, it points to
the previous (outer) un-closed block-start.
If QITEM_BLOCK_START_BLOCK_END > 0, it points to the
corresponding block-end node.
In both cases the pointers are relative to the current BLOCK_START.
|
QITEM_BLOCK_START_PREFIX | final static int QITEM_BLOCK_START_PREFIX(Code) | | |
QITEM_BLOCK_START_SIZE | final static int QITEM_BLOCK_START_SIZE(Code) | | |
QITEM_BLOCK_START_SUFFIX | final static int QITEM_BLOCK_START_SUFFIX(Code) | | |
QITEM_BLOCK_START_TYPE | final static int QITEM_BLOCK_START_TYPE(Code) | | A "block-start" queue item.
|
QITEM_INDENTATION_AMOUNT | final static int QITEM_INDENTATION_AMOUNT(Code) | | |
QITEM_INDENTATION_BLOCK | final static char QITEM_INDENTATION_BLOCK(Code) | | |
QITEM_INDENTATION_CURRENT | final static char QITEM_INDENTATION_CURRENT(Code) | | |
QITEM_INDENTATION_KIND | final static int QITEM_INDENTATION_KIND(Code) | | |
QITEM_INDENTATION_SIZE | final static int QITEM_INDENTATION_SIZE(Code) | | |
QITEM_INDENTATION_TYPE | final static int QITEM_INDENTATION_TYPE(Code) | | |
QITEM_NEWLINE_KIND | final static int QITEM_NEWLINE_KIND(Code) | | |
QITEM_NEWLINE_SIZE | final static int QITEM_NEWLINE_SIZE(Code) | | |
QITEM_NEWLINE_TYPE | final static int QITEM_NEWLINE_TYPE(Code) | | A newline queue item.
|
QITEM_NOP_TYPE | final static int QITEM_NOP_TYPE(Code) | | A dummy queue item used at the high end of the queue buffer
when there isn't enough space for the needed queue item.
|
QITEM_POSN | final static int QITEM_POSN(Code) | | Relative offset of POSN field of a QITEM>
|
QITEM_SECTION_START_DEPTH | final static int QITEM_SECTION_START_DEPTH(Code) | | |
QITEM_SECTION_START_SECTION_END | final static int QITEM_SECTION_START_SECTION_END(Code) | | |
QITEM_SECTION_START_SIZE | final static int QITEM_SECTION_START_SIZE(Code) | | "Abstract" type for beginning of section.
A section is from a block-start to a newline, from a newline to
the next newline (in the same block?), or from a newline to
the block end (?).
|
QITEM_TAB_COLINC | final static int QITEM_TAB_COLINC(Code) | | |
QITEM_TAB_COLNUM | final static int QITEM_TAB_COLNUM(Code) | | |
QITEM_TAB_FLAGS | final static int QITEM_TAB_FLAGS(Code) | | |
QITEM_TAB_IS_RELATIVE | final static int QITEM_TAB_IS_RELATIVE(Code) | | |
QITEM_TAB_IS_SECTION | final static int QITEM_TAB_IS_SECTION(Code) | | |
QITEM_TAB_SIZE | final static int QITEM_TAB_SIZE(Code) | | |
QITEM_TAB_TYPE | final static int QITEM_TAB_TYPE(Code) | | |
QITEM_TYPE_AND_SIZE | final static int QITEM_TYPE_AND_SIZE(Code) | | The first it QITEM contains it type code and size.
The type code is one of the QITEM_XXX_TYPE values below.
The size is the corresponding QITEM_XXX_SIZE value below,
except for the case of QITEM_NOP_TYPE (which is used as a filler).
|
QUEUE_INIT_ALLOC_SIZE | final static int QUEUE_INIT_ALLOC_SIZE(Code) | | |
blockDepth | int blockDepth(Code) | | The "stack pointer" in the
blocks array.
|
blocks | int[] blocks(Code) | | Stack of logical blocks in effect at the buffer start.
I.e. blocks for which
reallyStartLogicalBlock has been called.
Each block uses
LOGICAL_BLOCK_LENGTH
int in this array.
|
buffer | public char[] buffer(Code) | | Holds all the text that has been output but not yet printed.
|
bufferFillPointer | public int bufferFillPointer(Code) | | The index into BUFFER where more text should be put.
|
bufferOffset | int bufferOffset(Code) | | Total amount of stuff that has been shifted out of the buffer.
Whenever we output stuff from the buffer, we shift the remaining noise
over. This makes it difficult to keep references to locations in
the buffer.
|
bufferStartColumn | int bufferStartColumn(Code) | | The column the first character in the buffer will appear in.
Normally zero, but if we end up with a very long line with no breaks in it
we might have to output part of it. Then this will no longer be zero.
Ditto after emitting a prompt.
|
currentBlock | int currentBlock(Code) | | If >= 0, index (into queueInts) of current unclosed begin-block node.
This is a head of a linked linked of queued BLOCK_START for which
we haven't seen the matching BLOCK_END
|
initialBufferSize | public static int initialBufferSize(Code) | | |
lineLength | int lineLength(Code) | | Line length we should format to.
|
lineNumber | int lineNumber(Code) | | The line number we are currently on. Used for *print-lines* abrevs and
to tell when sections have been split across multiple lines.
|
miserWidth | int miserWidth(Code) | | |
pendingBlocksCount | public int pendingBlocksCount(Code) | | Number of startLogicalBlock - number of endLogicalBlock.
|
prefix | char[] prefix(Code) | | Buffer holding the per-line prefix active at the buffer start.
Indentation is included in this. The length of this is stored
in the logical block stack.
|
prettyPrintingMode | int prettyPrintingMode(Code) | | The current pretty-printing mode.
See setPrettyPrintingMode for valid values.
|
queueInts | int[] queueInts(Code) | | A queue of pending operations.
This is primarily stored in the circular buffer queueInts. There
are different kinds of operation types, and each operation can
require a variable number of elements in the buffer, depending on
the operation type. Given an operation at 'index', the type
operation type code is 'getQueueType(index)' (one of the
QITEM_XXX_TYPE macros below), and the number of elements in the
buffer is 'getQueueSize(index)' (one of the QITEM_XXX_SIZE values
below). You can think of the various QITEM_XXX_TYPEs as
"sub-classes" of queued operations, but instead of creating
actual Java objects, we allocate the objects' fields in the
queueInts and QueueStrings arrays, to avoid expensive object
allocation. The special QITEM_NOP_TYPE is a used as a marker for
when there isn't enough space in the rest of buffer, so we have
to wrap around to the start. The other QITEM_XXX macros are the
offsets of the various "fields" relative to the start index.
|
queueSize | int queueSize(Code) | | Number of elements (in queueInts and queueStrings) in use.
|
queueStrings | String[] queueStrings(Code) | | For simplicity, queueStrings is the same size as queueInts.
|
queueTail | int queueTail(Code) | | Index in queueInts and queueStrings of oldest enqueued operation.
|
suffix | char[] suffix(Code) | | Buffer holding the total remaining suffix active at the buffer start.
The characters are right-justified in the buffer to make it easier
to output the buffer. The length is stored in the logical block stack.
|
wordEndSeen | boolean wordEndSeen(Code) | | |
addIndentation | public void addIndentation(int amount, boolean current)(Code) | | |
clearBuffer | public void clearBuffer()(Code) | | |
clearWordEnd | public void clearWordEnd()(Code) | | |
computeTabSize | int computeTabSize(int tab, int sectionStart, int column)(Code) | | |
endLogicalBlock | public void endLogicalBlock()(Code) | | |
endLogicalBlock | public void endLogicalBlock(String suffix)(Code) | | |
enqueue | public int enqueue(int kind, int size)(Code) | | |
enqueueIndent | public int enqueueIndent(char kind, int amount)(Code) | | |
enqueueNewline | public void enqueueNewline(int kind)(Code) | | |
enqueueTab | int enqueueTab(int flags, int colnum, int colinc)(Code) | | |
ensureSpaceInBuffer | int ensureSpaceInBuffer(int want)(Code) | | |
expandTabs | void expandTabs(int through)(Code) | | |
fitsOnLine | int fitsOnLine(int sectionEnd, boolean forceNewlines)(Code) | | Return 1 if true; -1 if false; 0 if don't know.
|
flush | public void flush()(Code) | | |
getColumnNumber | public int getColumnNumber()(Code) | | Not meaningful if
prettyPrintingMode > 0 .
|
getMaxLines | int getMaxLines()(Code) | | |
getMiserWidth | protected int getMiserWidth()(Code) | | |
indexColumn | int indexColumn(int index)(Code) | | |
isMisering | boolean isMisering()(Code) | | |
isPrettyPrinting | public boolean isPrettyPrinting()(Code) | | Is pretty printing enabled?
|
lineAbbreviationHappened | public void lineAbbreviationHappened()(Code) | | |
maybeOutput | boolean maybeOutput(boolean forceNewlines, boolean flushing)(Code) | | |
outputLine | void outputLine(int newline) throws IOException(Code) | | Output a new line.
Parameters: newline - index of a newline queue item |
outputPartialLine | void outputPartialLine()(Code) | | |
printReadably | boolean printReadably()(Code) | | |
reallyEndLogicalBlock | void reallyEndLogicalBlock()(Code) | | |
reallyStartLogicalBlock | void reallyStartLogicalBlock(int column, String prefix, String suffix)(Code) | | |
setColumnNumber | public void setColumnNumber(int column)(Code) | | |
setIndentation | public void setIndentation(int column)(Code) | | |
setPrettyPrinting | public void setPrettyPrinting(boolean mode)(Code) | | Turn pretty printing on or off.
Equivalent to
setPrettyPrintingMode(mode?1:0) .
|
setPrettyPrintingMode | public void setPrettyPrintingMode(int mode)(Code) | | 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 thatspaces are treated like enqueing NEWLINE_SPACE (essentiall a 'fill'). |
startLogicalBlock | public void startLogicalBlock(String prefix, boolean perLine, String suffix)(Code) | | |
write | public void write(int ch)(Code) | | |
write | public void write(String str, int start, int count)(Code) | | |
write | public void write(char[] str)(Code) | | |
write | public void write(char[] str, int start, int count)(Code) | | |
writeBreak | final public void writeBreak(int kind)(Code) | | |
writeWordStart | public void writeWordStart()(Code) | | Maybe write a word-separating space.
Specifically, write a space if the previous output
was
PrettyWriter.writeWordEnd . Otherwise, do nothing.
|
|
|