public class PrettyWriter
extends java.lang.Object
PrettyWriter
class formats output for the backend code
generators. Formatted output is sent to a PrintWriter
class.
The pretty writer supports two optional formatting modes. The first mode
is "line breaking", in which long lines are broken at a specified column
and optional end-of-line or start-of-line continuation strings are printed
for the broken lines. For example, Fortran line breaking would set the
break column at 72 with a start-of-line string of " &" and a null
end-of-line string. Python line breaking might set a line break at column
78 with an end-of-line string of "\" and a null start-of-line string. In
all cases, the continued line is indented one tab level. The second mode
is "block commenting", in which optional line-start or after-tab strings
are printed for comment blocks. For example, a Fortran comment block might
set the line-start string to "C" and the after-tab string to null whereas
Python would set the line-start string to null and the after-tab string to
"#". In all cases, comment block mode supercedes line breaking mode such
that lines are not broken in comment blocks. Column numbers start with
zero as the first column in a line. Note also that newlines are output
as '\n' and not using the print writer default println() command, which
adds the extra DOS endo-of-line characters that confuses cygwin utilities
like automake.Constructor and Description |
---|
PrettyWriter(java.io.PrintWriter writer)
Create a new
PrettyWriter instance that will send
output to the specified print writer object. |
Modifier and Type | Method and Description |
---|---|
void |
backTab()
Decrease the tab level by one so that newlines begin at the previous
tab stop.
|
void |
changeTabLevel(int delta)
Change the current tab level at the beginning of a new lines by
the specified positive or negative amount.
|
void |
close()
Flush and close the associated print writer stream.
|
void |
defineBlockComment(java.lang.String line_start,
java.lang.String after_tab)
Define the pretty printer parameters for block comment mode.
|
void |
disableBlockComment()
Disable block comment mode.
|
void |
disableLineBreak()
Disable line breaking mode.
|
void |
enableBlockComment()
Enable block comment mode.
|
void |
enableLineBreak()
Enable line breaking mode.
|
void |
enableLineBreak(int column,
java.lang.String start,
java.lang.String end)
Define the pretty printer parameters for line breaking.
|
void |
flushPrintWriter()
Flush the underlying print writer stream.
|
java.io.PrintWriter |
getPrintWriter()
Retrieve the underlying print writer stream.
|
void |
popLineBreak()
Restore the line break status to its previous value.
|
void |
print(java.lang.String s)
Print the specified string to the print writer output stream.
|
void |
printAligned(java.lang.String text,
int field)
Print the text string in a field of the specified width.
|
void |
println()
Advance the output stream to the next line.
|
void |
println(java.lang.String s)
Print the specified string followed by a newline to the print writer
output stream.
|
void |
printlnUnformatted(java.lang.String s)
Print unformatted text to the print writer stream.
|
void |
printSpaces(int nspaces)
Print the specified number of spaces to the pretty writer.
|
void |
printUnformatted(java.lang.String s)
Print unformatted text to the print writer stream.
|
void |
pushLineBreak(boolean linebreak)
Change the line break status to
linebreak and save the
previous value on a stack. |
void |
restoreFirstTabStop()
Restore the default first tab stop to its original value before the
call to
setTemporaryFirstTabStop . |
void |
setFirstTabStop(int column)
Set the first tab stop for this pretty writer.
|
void |
setLineBreakString(java.lang.String s)
Set the line breaking characters.
|
void |
setStrictBreaking() |
void |
setTabSpacing(int spacing)
Set the tab spacing for this pretty writer.
|
void |
setTemporaryFirstTabStop()
Set a temporary tab stop at the current cursor location.
|
void |
tab()
Increase the tab level by one so that newlines begin at the next
tab stop.
|
public PrettyWriter(java.io.PrintWriter writer)
PrettyWriter
instance that will send
output to the specified print writer object. The first tab stop
is set to column zero with a tab spacing of three. Both line
breaking and block commenting modes are disabled.public void close()
public java.io.PrintWriter getPrintWriter()
public void flushPrintWriter()
public void enableLineBreak(int column, java.lang.String start, java.lang.String end)
public void enableLineBreak()
public void disableLineBreak()
public void pushLineBreak(boolean linebreak)
linebreak
and save the
previous value on a stack.public void popLineBreak()
public void setStrictBreaking()
public void setLineBreakString(java.lang.String s)
public void defineBlockComment(java.lang.String line_start, java.lang.String after_tab)
public void enableBlockComment()
public void disableBlockComment()
public void setFirstTabStop(int column)
public void changeTabLevel(int delta)
public void tab()
public void backTab()
public void setTabSpacing(int spacing)
public void setTemporaryFirstTabStop()
public void restoreFirstTabStop()
setTemporaryFirstTabStop
.public void print(java.lang.String s)
println
is called on
the substrings between the newlines.public void println(java.lang.String s)
println
is called on the
substrings between the newlines. This method flushes the output
stream.public void printUnformatted(java.lang.String s)
public void printlnUnformatted(java.lang.String s)
public void println()
public void printSpaces(int nspaces)
public void printAligned(java.lang.String text, int field)