|
Java™ Pretty Printer Library v0.5 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.uka.ilkd.pp.Layouter<Exc>
de.uka.ilkd.pp.DataLayouter<Exc>
Exc
- The type of exceptions that might be thrown by the backend.public class DataLayouter<Exc extends java.lang.Exception>
An extension of Layouter
to print
arbitrary Java data. There is a print(Object)
method
that prints objects according to their type. In particular,
there are special layouts for (nested) collections, maps, and
arrays. Classes implementing the interface PrettyPrintable
provide their own method for printing themselves to a DataLayouter.
Like most methods of Layouter
, the methods of this
class return this
, so calls can be sequenced as in
l.beginC().print(...).brk(...)
.
The intended main use of this class is to produce more readable
debugging output than what System.err.println()
would
give, or for data output that should be human-readable. It produces
standard representations of data, like Object.toString()
.
Application-specific types will usually wish to define their own
pretty printing, using the methods of Layouter
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class de.uka.ilkd.pp.Layouter |
---|
Layouter.BreakConsistency, Layouter.IndentationBase |
Field Summary |
---|
Fields inherited from class de.uka.ilkd.pp.Layouter |
---|
DEFAULT_INDENTATION, DEFAULT_LINE_WIDTH |
Constructor Summary | |
---|---|
DataLayouter(Backend<Exc> back,
int indentation)
Construts a newly allocated DataLayouter which will send output to the given Backend and has the given default indentation. |
Method Summary | |
---|---|
DataLayouter<Exc> |
begin(boolean consistent)
Deprecated. use begin(de.uka.ilkd.pp.Layouter.BreakConsistency, de.uka.ilkd.pp.Layouter.IndentationBase, int) |
DataLayouter<Exc> |
begin(boolean consistent,
int indent)
Deprecated. use begin(de.uka.ilkd.pp.Layouter.BreakConsistency, de.uka.ilkd.pp.Layouter.IndentationBase, int) |
DataLayouter<Exc> |
begin(Layouter.BreakConsistency consistent,
Layouter.IndentationBase fromPos,
int indent)
Begin a block. |
DataLayouter<Exc> |
beginC()
Begin a consistent block. |
DataLayouter<Exc> |
beginC(int indent)
Begin a consistent block. |
DataLayouter<Exc> |
beginCInd()
Begin a consistent block. |
DataLayouter<Exc> |
beginCInd(int indent)
Begin a consistent block. |
DataLayouter<Exc> |
beginI()
Begin an inconsistent block. |
DataLayouter<Exc> |
beginI(int indent)
Begin an inconsistent block. |
DataLayouter<Exc> |
beginIInd()
Begin an inconsistent block. |
DataLayouter<Exc> |
beginIInd(int indent)
Begin an inconsistent block. |
DataLayouter<Exc> |
brk()
Print a break with zero offset and width one. |
DataLayouter<Exc> |
brk(int width)
Print a break with zero offset. |
DataLayouter<Exc> |
brk(int width,
int offset)
Print a break. |
DataLayouter<Exc> |
end()
Ends the innermost block. |
DataLayouter<Exc> |
flush()
Output any information currently kept in buffers. |
static DataLayouter<java.io.IOException> |
getWriterDataLayouter(java.io.Writer writer)
Factory method for a DataLayouter with a WriterBackend . |
static DataLayouter<java.io.IOException> |
getWriterDataLayouter(java.io.Writer writer,
int lineWidth)
Factory method for a DataLayouter with a WriterBackend . |
static DataLayouter<java.io.IOException> |
getWriterDataLayouter(java.io.Writer writer,
int lineWidth,
int indentation)
Factory method for a DataLayouter with a WriterBackend . |
DataLayouter<Exc> |
ind()
Indent with zero offset and zero width. |
DataLayouter<Exc> |
ind(int width,
int offset)
Indent relative to the indentation level if surrounding block is broken. |
DataLayouter<Exc> |
mark(java.lang.Object o)
This leads to a call of the Backend.mark(Object) method of the
backend, when the material preceding the call to mark has
been printed to the backend, including any inserted line breaks and
indentation. |
DataLayouter<Exc> |
nl()
Print a break with zero offset and large width. |
DataLayouter<Exc> |
pre(java.lang.String s)
Layout prefromated text. |
DataLayouter<Exc> |
print(java.util.Collection<?> c)
Print a collection. |
DataLayouter<Exc> |
print(java.util.Map<?,?> m)
Print a map. |
DataLayouter<Exc> |
print(java.lang.Object o)
o to this DataLayouter. |
DataLayouter<Exc> |
print(java.lang.String s)
Output text material. |
DataLayouter<Exc> |
printArray(java.lang.Object o)
Print an array of reference or primitive elements. |
DataLayouter<Exc> |
printEntry(java.util.Map.Entry<?,?> e)
Print a map entry. |
Methods inherited from class de.uka.ilkd.pp.Layouter |
---|
close, getStringLayouter, getStringLayouter, getStringLayouter, getWriterLayouter, getWriterLayouter, getWriterLayouter |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DataLayouter(Backend<Exc> back, int indentation)
Backend
and has the given default indentation.
back
- the Backendindentation
- the default indentationMethod Detail |
---|
public static DataLayouter<java.io.IOException> getWriterDataLayouter(java.io.Writer writer)
WriterBackend
.
The line width is taken to be Layouter.DEFAULT_LINE_WIDTH
, and the
default indentation Layouter.DEFAULT_INDENTATION
.
writer
- the Writer
the Backend is going to usepublic static DataLayouter<java.io.IOException> getWriterDataLayouter(java.io.Writer writer, int lineWidth)
WriterBackend
.
The default indentation is taken from Layouter.DEFAULT_INDENTATION
.
writer
- the Writer
the Backend is going to uselineWidth
- the maximum lineWidth the Backend is going to usepublic static DataLayouter<java.io.IOException> getWriterDataLayouter(java.io.Writer writer, int lineWidth, int indentation)
WriterBackend
.
writer
- the Writer
the Backend is going to uselineWidth
- the maximum lineWidth the Backend is going to useindentation
- the default indentationpublic DataLayouter<Exc> print(java.lang.Object o) throws Exc extends java.lang.Exception
o
to this DataLayouter.
If o
is an instance of PrettyPrintable
,
it is printed using its prettyPrint
method.
Otherwise, if o
a is a collection, and array,
or a map, it is printed as descibed in the methods
print(Collection)
, printArray(Object)
,
and print(Map)
, respectively. If everything else
fails, o.toString()
is used.
o
- the object to be pretty printed
Exc extends java.lang.Exception
public DataLayouter<Exc> print(java.util.Collection<?> c) throws Exc extends java.lang.Exception
[xxx, yyy, zzz]if it fits on one line, and as
[xxx, yyy, zzz]otherwise.
c
- A collection
Exc extends java.lang.Exception
public DataLayouter<Exc> printArray(java.lang.Object o) throws Exc extends java.lang.Exception
o
- an object, has to be an array!
Exc extends java.lang.Exception
public DataLayouter<Exc> print(java.util.Map<?,?> m) throws Exc extends java.lang.Exception
{k1=v1, k2=v2, k3=v3]if it fits on one line, and as
{key1=val1, key2=val2, key3=val3]otherwise. If values don't fit on one line, the key-value pairs will also be spread over two lines, as indicated for
printEntry(java.util.Map.Entry)
.
Exc extends java.lang.Exception
public DataLayouter<Exc> printEntry(java.util.Map.Entry<?,?> e) throws Exc extends java.lang.Exception
key=valif it fits on one line, and as
key= valotherwise. This is mainly to prevent key from adding too much indentation.
Exc extends java.lang.Exception
public DataLayouter<Exc> begin(Layouter.BreakConsistency consistent, Layouter.IndentationBase fromPos, int indent)
Layouter
cons
indicates whether this is a
consistent block or an inconsistent one. In consistent blocks, breaks are
either all broken or none is broken. The indentation level is increased
by indent
, either relative to the current position,
or relative to the surrounding block's indentation level, depending on
the parameter indBase
.
begin
in class Layouter<Exc extends java.lang.Exception>
consistent
- true
for consistent blockfromPos
- increment relative to current pos, not indentationindent
- increment to indentation level
public DataLayouter<Exc> begin(boolean consistent, int indent)
begin(de.uka.ilkd.pp.Layouter.BreakConsistency, de.uka.ilkd.pp.Layouter.IndentationBase, int)
Layouter
consistent
is set, breaks are either all
broken or all not broken. The indentation level is increased by
indent
, relative to the current position.
begin
in class Layouter<Exc extends java.lang.Exception>
consistent
- true
for consistent blockindent
- increment to indentation level
public DataLayouter<Exc> begin(boolean consistent)
begin(de.uka.ilkd.pp.Layouter.BreakConsistency, de.uka.ilkd.pp.Layouter.IndentationBase, int)
Layouter
begin
in class Layouter<Exc extends java.lang.Exception>
consistent
- true
for consistent block
public DataLayouter<Exc> beginC()
Layouter
beginC
in class Layouter<Exc extends java.lang.Exception>
public DataLayouter<Exc> beginC(int indent)
Layouter
indent
to the indentation
level, relative to the current position.
beginC
in class Layouter<Exc extends java.lang.Exception>
indent
- the indentation for this block
public DataLayouter<Exc> beginI()
Layouter
beginI
in class Layouter<Exc extends java.lang.Exception>
public DataLayouter<Exc> beginI(int indent)
Layouter
indent
to the indentation
level, relative to the current position.
beginI
in class Layouter<Exc extends java.lang.Exception>
indent
- the indentation for this block
public DataLayouter<Exc> beginCInd()
Layouter
beginCInd
in class Layouter<Exc extends java.lang.Exception>
public DataLayouter<Exc> beginCInd(int indent)
Layouter
indent
, relative to the surrounding block's indentation
level.
beginCInd
in class Layouter<Exc extends java.lang.Exception>
indent
- the indentation for this block
public DataLayouter<Exc> beginIInd()
Layouter
beginIInd
in class Layouter<Exc extends java.lang.Exception>
public DataLayouter<Exc> beginIInd(int indent)
Layouter
indent
, relative to the surrounding block's indentation
level.
beginIInd
in class Layouter<Exc extends java.lang.Exception>
indent
- the indentation for this block
public DataLayouter<Exc> brk() throws Exc extends java.lang.Exception
Layouter
brk
in class Layouter<Exc extends java.lang.Exception>
Exc extends java.lang.Exception
public DataLayouter<Exc> brk(int width, int offset) throws Exc extends java.lang.Exception
Layouter
width
spaces if the line is
not broken at this point. If it is broken,
indentation is added to the current indentation level, plus the value of
offset
.
brk
in class Layouter<Exc extends java.lang.Exception>
width
- space to insert if not brokenoffset
- offset relative to current indentation level
Exc extends java.lang.Exception
public DataLayouter<Exc> brk(int width) throws Exc extends java.lang.Exception
Layouter
brk
in class Layouter<Exc extends java.lang.Exception>
width
- space to insert if not broken
Exc extends java.lang.Exception
public DataLayouter<Exc> end() throws Exc extends java.lang.Exception
Layouter
end
in class Layouter<Exc extends java.lang.Exception>
Exc extends java.lang.Exception
public DataLayouter<Exc> flush() throws Exc extends java.lang.Exception
Layouter
flush
or Layouter.close()
then.
flush
in class Layouter<Exc extends java.lang.Exception>
Exc extends java.lang.Exception
public DataLayouter<Exc> ind() throws Exc extends java.lang.Exception
Layouter
ind
in class Layouter<Exc extends java.lang.Exception>
Exc extends java.lang.Exception
public DataLayouter<Exc> ind(int width, int offset) throws Exc extends java.lang.Exception
Layouter
width
spaces. Otherwise, indent to the current indentation level, plus
offset
, unless that position has already been exceeded on
the current line. If that is the case, nothing is printed. No line break
is possible at this point.
ind
in class Layouter<Exc extends java.lang.Exception>
width
- space to insert if not brokenoffset
- offset relative to current indentation level
Exc extends java.lang.Exception
public DataLayouter<Exc> mark(java.lang.Object o) throws Exc extends java.lang.Exception
Layouter
Backend.mark(Object)
method of the
backend, when the material preceding the call to mark
has
been printed to the backend, including any inserted line breaks and
indentation. The Object
argument to mark
is passed
through unchanged to the backend and may be used by the application to
pass information about the purpose of the mark.
mark
in class Layouter<Exc extends java.lang.Exception>
o
- an object to be passed through to the backend.
Exc extends java.lang.Exception
public DataLayouter<Exc> nl() throws Exc extends java.lang.Exception
Layouter
nl
in class Layouter<Exc extends java.lang.Exception>
Exc extends java.lang.Exception
public DataLayouter<Exc> pre(java.lang.String s) throws Exc extends java.lang.Exception
Layouter
s
(separated by \n) gets
printed as a string and newlines become forced breaks.
pre
in class Layouter<Exc extends java.lang.Exception>
s
- the pre-formatted string
Exc extends java.lang.Exception
public DataLayouter<Exc> print(java.lang.String s) throws Exc extends java.lang.Exception
Layouter
s
should not contain
newline characters. If you have a string with newline characters, and
want to retain its formatting, consider using the Layouter.pre(String s)
method. The Layouter will not insert any line breaks in such a string.
print
in class Layouter<Exc extends java.lang.Exception>
s
- the String to print.
Exc extends java.lang.Exception
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |