|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectpolyglot.util.CodeWriter
polyglot.util.SimpleCodeWriter
public class SimpleCodeWriter
SimpleCodeWriter is a simple, fast, bulletproof implementation of the CodeWriter interface. However, it does not try very hard to use vertical space optimally or to stay within the horizontal margins. If aesthetically appealing output is desired, use OptimalCodeWriter.
| Nested Class Summary | |
|---|---|
protected class |
SimpleCodeWriter.State
|
| Field Summary | |
|---|---|
protected boolean |
breakAll
|
protected int |
lmargin
|
protected Stack |
lmargins
|
protected PrintWriter |
output
|
protected int |
pos
|
protected int |
rmargin
|
protected int |
width
|
| Constructor Summary | |
|---|---|
SimpleCodeWriter(OutputStream o,
int width_)
|
|
SimpleCodeWriter(PrintWriter o,
int width_)
|
|
SimpleCodeWriter(Writer o,
int width_)
|
|
| Method Summary | |
|---|---|
void |
allowBreak(int n,
int level,
String alt,
int altlen)
Insert a break (an optional newline). |
void |
begin(int n)
Start a new block with a relative indentation of n
characters. |
void |
close()
Flush all formatted text, reset formatter state, and close the underlying writer. |
void |
end()
Terminate the most recent outstanding begin. |
boolean |
flush()
Flush all formatted text to the underlying writer. |
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,
int level)
newline with a specified indentation and level. |
String |
toString()
toString is not really supported by this implementation. |
void |
unifiedBreak(int n,
int level,
String alt,
int altlen)
Insert a unified break. |
void |
write(String s)
Print the string s verbatim on the output stream. |
void |
write(String s,
int length)
Print the string s on the output stream. |
| Methods inherited from class polyglot.util.CodeWriter |
|---|
allowBreak, allowBreak, newline, unifiedBreak |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected PrintWriter output
protected int width
protected int rmargin
protected int lmargin
protected boolean breakAll
protected Stack lmargins
protected int pos
| Constructor Detail |
|---|
public SimpleCodeWriter(OutputStream o,
int width_)
public SimpleCodeWriter(PrintWriter o,
int width_)
public SimpleCodeWriter(Writer o,
int width_)
| Method Detail |
|---|
public void write(String s)
CodeWriters verbatim on the output stream.
write in class CodeWriters - the string to print.
public void write(String s,
int length)
CodeWriters 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.
write in class CodeWriterpublic void begin(int n)
CodeWritern
characters.
begin in class CodeWriterpublic void end()
CodeWriterbegin.
end in class CodeWriter
public void allowBreak(int n,
int level,
String alt,
int altlen)
CodeWriter
allowBreak in class CodeWritern - indentation relative to the current block if the newline is
inserted. Requires: n >= 0level - the level of the break. Requires: level >= 0alt - if no newline is inserted, the string alt is
output instead. Requires: alt != null
public void unifiedBreak(int n,
int level,
String alt,
int altlen)
CodeWriterallowBreak, 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!).
unifiedBreak in class CodeWritern - the relative indentationlevel - the level of the breakalt - the alternative textCodeWriter.allowBreak(int, int, java.lang.String, int)public void newline()
CodeWriter
newline in class CodeWriter
public void newline(int n,
int level)
CodeWriter
newline in class CodeWriter
public boolean flush()
throws IOException
CodeWriter
flush in class CodeWriterIOException
public boolean flush(boolean format)
throws IOException
CodeWriterflush, but passing format=false
causes output to be generated in the fastest way possible, with
all breaks broken.
flush in class CodeWriterformat - whether to pretty-print the output
IOException
public void close()
throws IOException
CodeWriter
close in class CodeWriterIOExceptionpublic String toString()
toString in class CodeWriter
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||