|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.Writer | +--de.hunsicker.jalopy.printer.NodeWriter
The writer to be used to print a Java AST. This class contains some basic support methods to be used by printers.
Printer
Field Summary | |
protected int |
column
Current column position. |
protected boolean |
continuation
Should indenting use an added contination amount? |
protected int |
continuationIndentSize
Number of spaces to use for continuation indentation. |
protected Environment |
environment
The envrionment to use. |
protected boolean |
footer
Should a footer be inserted at the end of every file? |
static boolean |
INDENT_NO
Indicates that no indentation should be performed. |
static boolean |
INDENT_YES
Indicates that indentation should be performed. |
protected int |
indentSize
Number of spaces to take for one indent. |
protected boolean |
insertTrailingEmpty
Indicates wether a trailing empty line should be inserted at the end of a file. |
protected int |
last
Holds the type of the last printed token. |
protected int |
leftBraceIndent
Number of spaces to print before left curly braces. |
protected boolean |
leftBraceNewline
Print left curly braces on a new line? |
protected int |
line
Current line number. |
protected java.lang.String |
lineSeparator
Used line separator. |
protected int |
mode
Printing mode. |
protected boolean |
newline
Indicates whether we're at the beginning of a new line ( column == 1 ). |
static boolean |
NEWLINE_NO
Print NO newline after a token. |
static boolean |
NEWLINE_YES
Print a newline after a token. |
protected boolean |
nextNewline
Indicates that the line following this is a new line Used for printing commas in blocks without white space after the new line |
protected java.lang.String |
originalLineSeparator
The original line separator of the file as reported by the lexer. |
protected Convention |
settings
The code convention settings that controls the output style. |
protected boolean |
useLeadingTabs
Should tabs only be used to print leading indentation? |
protected boolean |
useTabs
Should tabs be used to print indentation? |
Fields inherited from class java.io.Writer |
lock |
Constructor Summary | |
protected |
NodeWriter(CompositeFactory factory)
Creates a new NodeWriter object. |
|
NodeWriter(java.io.Writer out,
CompositeFactory factory,
java.lang.String filename,
java.util.Map issues,
java.lang.String lineSeparator,
java.lang.String originalLineSeparator)
Creates a new NodeWriter object with the given file output format. |
Method Summary | |
void |
close()
Closes the stream, flushing it first. |
void |
flush()
Flushes the stream. |
int |
getColumn()
Returns the line column position of the last written character. |
CompositeFactory |
getCompositeFactory()
|
java.lang.String |
getFilename()
Returns the name of the parsed file. |
int |
getIndentLength()
Returns the length of the current indent string. |
int |
getIndentLevel()
Returns the current indent level. |
int |
getIndentSize()
Returns the number of spaces to use for indentation. |
JavaNodeFactory |
getJavaNodeFactory()
|
int |
getLast()
Returns the type of the token last printed. |
int |
getLine()
Returns the current line number. |
java.lang.String |
getLineSeparator()
Returns the current line separator. |
java.lang.String |
getString(int length)
Returns a string of the given length. |
void |
indent()
Increases the current indent level one level. |
int |
print(java.lang.String string,
int type)
Outputs the given string of the given type to the underlying writer. |
void |
printBlankLines(int amount)
Prints the given number of blank lines. |
int |
printLeftBrace()
Outputs a left curly brace. |
int |
printLeftBrace(boolean newlineBefore,
boolean newlineAfter)
Outputs a leftcurly brace. |
int |
printLeftBrace(boolean newlineBefore,
boolean newlineAfter,
boolean indent)
Outputs a left curly brace. |
void |
printNewline()
Outputs a line break. |
int |
printRightBrace()
Outputs a closing curly brace. |
int |
printRightBrace(boolean newlineAfter)
Outputs a right curly brace. |
int |
printRightBrace(int type,
boolean newlineAfter)
Outputs a right curly brace. |
int |
printRightBrace(int type,
boolean whitespaceBefore,
boolean newlineAfter)
Outputs a right curly brace. |
void |
setEnvironment(Environment environment)
Sets the environment to use. |
void |
setFilename(java.lang.String filename)
Sets the filename of the file beeing printed. |
void |
setIndentLevel(int level)
Sets the current indent level. |
void |
setLast(int type)
Sets the type of the token last printed. |
void |
setLineSeparator(java.lang.String lineSeparator)
Sets the separator string to use for newlines. |
void |
setTracking(boolean tracking)
Sets whether the tree that is to be printed contains nodes that needs their positions tracked. |
void |
setWriter(java.io.Writer out)
Sets the underlying writer to actually write to. |
void |
unindent()
Decreases the current indent level one level. |
void |
write(char[] cbuf,
int off,
int len)
Write a portion of an array of characters. |
Methods inherited from class java.io.Writer |
write, write, write, write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final boolean INDENT_NO
public static final boolean INDENT_YES
public static final boolean NEWLINE_NO
public static final boolean NEWLINE_YES
protected Convention settings
protected Environment environment
protected java.lang.String lineSeparator
protected java.lang.String originalLineSeparator
protected boolean continuation
protected boolean footer
protected boolean insertTrailingEmpty
protected boolean leftBraceNewline
protected boolean newline
column == 1
).
protected boolean nextNewline
protected boolean useLeadingTabs
protected boolean useTabs
protected int column
protected int continuationIndentSize
protected int indentSize
protected int last
protected int leftBraceIndent
protected int line
protected int mode
Constructor Detail |
public NodeWriter(java.io.Writer out, CompositeFactory factory, java.lang.String filename, java.util.Map issues, java.lang.String lineSeparator, java.lang.String originalLineSeparator)
out
- the output stream to write to.filename
- name of the parsed file.issues
- holds the issues found during a run.lineSeparator
- the lineSeparator to use.originalLineSeparator
- the original line separator of the file.protected NodeWriter(CompositeFactory factory)
Method Detail |
public CompositeFactory getCompositeFactory()
public JavaNodeFactory getJavaNodeFactory()
public int getColumn()
public void setEnvironment(Environment environment)
environment
- environment.public void setFilename(java.lang.String filename)
filename
- filename of the source files beeing printed.public java.lang.String getFilename()
public int getIndentLength()
public void setIndentLevel(int level)
level
- new indent level.public int getIndentLevel()
public int getIndentSize()
public void setLast(int type)
type
- type of the tokenpublic int getLast()
JavaTokenTypes.BOF
if nothing was printed yet.public int getLine()
public void setLineSeparator(java.lang.String lineSeparator)
lineSeparator
- separator string. Either "\n", "\r" or
"\r\n".public java.lang.String getLineSeparator()
public java.lang.String getString(int length)
length
- length of the string to return.
public void setTracking(boolean tracking)
tracking
- true
to indicate that certain nodes needs their
positions tracked.public void setWriter(java.io.Writer out)
out
- writer to write to.public void close() throws java.io.IOException
close
in class java.io.Writer
java.io.IOException
- if an I/O error occured.public void flush() throws java.io.IOException
flush
in class java.io.Writer
java.io.IOException
- if an I/O error occured.public void indent()
public int print(java.lang.String string, int type) throws java.io.IOException
string
- string to write.type
- type of the string.
java.io.IOException
- if an I/O error occured.public void printBlankLines(int amount) throws java.io.IOException
amount
- number of blank lines to print.
java.io.IOException
- if an I/O error occured.public int printLeftBrace() throws java.io.IOException
java.io.IOException
- if an I/O error occured.public int printLeftBrace(boolean newlineBefore, boolean newlineAfter) throws java.io.IOException
newlineBefore
- true
if a newline should be printed before the
brace.newlineAfter
- true
if a newline should be printed after the
brace.
java.io.IOException
- if an I/O error occured.public int printLeftBrace(boolean newlineBefore, boolean newlineAfter, boolean indent) throws java.io.IOException
newlineBefore
- true
if a newline should be printed before the
brace.newlineAfter
- true
if a newline should be printed after the
brace.indent
- if true
the brace will be indented relative to the
current indentation level.
java.io.IOException
- if an I/O error occured.public void printNewline() throws java.io.IOException
java.io.IOException
- if an I/O error occured.public int printRightBrace() throws java.io.IOException
java.io.IOException
- if an I/O error occured.public int printRightBrace(boolean newlineAfter) throws java.io.IOException
newlineAfter
- true
if a newline should be printed after the
brace.
java.io.IOException
- if an I/O error occured.public int printRightBrace(int type, boolean newlineAfter) throws java.io.IOException
type
- the type of the brace. Either RCURLY or OBJBLOCK.newlineAfter
- if true
a newline will be printed after the
brace.
java.io.IOException
- if an I/O error occured.public int printRightBrace(int type, boolean whitespaceBefore, boolean newlineAfter) throws java.io.IOException
type
- the type of the brace. Either RCURLY or OBJBLOCK.whitespaceBefore
- if true
outputs indentation whitespace
(depending on the code convention setting).newlineAfter
- if true
a newline will be printed after the
brace.
java.io.IOException
- if an I/O error occured.public void unindent()
public void write(char[] cbuf, int off, int len) throws java.io.IOException
write
in class java.io.Writer
cbuf
- array of characters.off
- offset from which to start writing characters.len
- number of characters to write.
java.io.IOException
- if an I/O error occured.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |