|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object polyglot.util.CodeWriter
public abstract class CodeWriter
A CodeWriter
is a pretty-printing engine. It formats
structured text onto an output stream o
in the minimum number
of lines, while keeping the width of the output within width
characters if possible. Newlines occur in the output only at places where a
line break is permitted by the use of allowBreak
and
unifiedBreak
.
Line breaks can have different levels, which is useful for implementing
things like "miser mode" layout.
Constructor Summary | |
---|---|
CodeWriter()
|
Method Summary | |
---|---|
void |
allowBreak(int n)
The most common use of "allowBreak": level 1, with an alternative of a single space. |
abstract void |
allowBreak(int n,
int level,
String alt,
int altlen)
Insert a break (an optional newline). |
void |
allowBreak(int n,
String alt)
|
abstract void |
begin(int n)
Start a new block with a relative indentation of n
characters. |
abstract void |
close()
Flush all formatted text, reset formatter state, and close the underlying writer. |
abstract void |
end()
Terminate the most recent outstanding begin . |
abstract boolean |
flush()
Flush all formatted text to the underlying writer. |
abstract boolean |
flush(boolean format)
Like flush , but passing format=false
causes output to be generated in the fastest way possible, with
all breaks broken. |
void |
newline()
Force a newline. |
void |
newline(int n)
Like newline(), but forces a newline with a specified indentation. |
abstract void |
newline(int n,
int level)
newline with a specified indentation and level. |
abstract String |
toString()
Return a readable representation of all the structured input given to the CodeWriter since the last flush. |
void |
unifiedBreak(int n)
The most common use of "unifiedBreak": level 1, with an alternative of a single space. |
abstract void |
unifiedBreak(int n,
int level,
String alt,
int altlen)
Insert a unified break. |
abstract void |
write(String s)
Print the string s verbatim on the output stream. |
abstract void |
write(String s,
int length)
Print the string s on the output stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CodeWriter()
Method Detail |
---|
public abstract void write(String s)
s
verbatim on the output stream.
s
- the string to print.public abstract void write(String s, int length)
s
on the output stream. Pretend that it
has width length
even if it has a different number of
characters. This is useful when the string contains escape sequences,
HTML character entity references, etc.
s
- length
- public abstract void begin(int n)
n
characters.
public abstract void end()
begin
.
public abstract void allowBreak(int n, int level, String alt, int altlen)
n
- indentation relative to the current block if the newline is
inserted. Requires: n >= 0alt
- if no newline is inserted, the string alt
is
output instead. Requires: alt != nulllevel
- the level of the break. Requires: level >= 0public abstract void unifiedBreak(int n, int level, String alt, int altlen)
allowBreak
, but unified breaks should also break if any break of
the same level in the same block is broken, whereas ordinary breaks do
not necessarily break in this case. That is, unified breaks act as if
they were slightly lower level than other breaks of the same level
(including other unified breaks!).
n
- the relative indentationlevel
- the level of the breakalt
- the alternative textallowBreak(int, int, java.lang.String, int)
public void unifiedBreak(int n)
n
- the indentation relative to the current block.public void allowBreak(int n)
n
- the indentation relative to the current block.public void allowBreak(int n, String alt)
public void newline()
public void newline(int n)
public abstract void newline(int n, int level)
public abstract boolean flush() throws IOException
IOException
public abstract void close() throws IOException
IOException
public abstract boolean flush(boolean format) throws IOException
flush
, but passing format=false
causes output to be generated in the fastest way possible, with
all breaks broken.
format
- whether to pretty-print the output
IOException
public abstract String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |