|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.octagroup.foregej.antlr.NodeWriter
Class used to write output from nodes.
Field Summary | |
protected boolean |
canWrapLines_
How do we deal with lines that exceed the maximum number of characters. |
protected antlr.collections.AST |
lastAST_
This variable is assigned as we exit the write(AST) method and used to check if we can wrap lines between two asts as we enter it again with a new ast. |
protected int |
lastLineWrapPos_
The position of the last line wrap. |
protected java.lang.String |
latestWrapProspectIndent_
A reference to the indentation at the latest wrap prospect. |
protected int |
latestWrapProspectPos_
The position of the latest line wrap prospect. |
protected int |
latestWrapProspectType_
Signals how the wrapping choulb be performed. ie should the character be removed, or should wrapping occurr before or after. |
protected java.util.Vector |
parents_
the parent node |
static int |
WRAP_AFTER
Integer used to signal that we can wrap after a char or string. |
static int |
WRAP_BEFORE
Integer used to signal that we can wrap before a char or string. |
static int |
WRAP_NOT
Integer used to signal that we cannot wrap on a char or string. |
static int |
WRAP_ON
Integer used to signal that we can wrap on a char or string. |
protected java.util.HashSet |
writtenTokens_
a hashmap of all the written tokens before and after a node. |
Constructor Summary | |
NodeWriter()
|
Method Summary | |
protected boolean |
canWrapBetween(antlr.collections.AST firstAst,
antlr.collections.AST secondAst)
Returns how we can wrap between the supplied asts. |
protected int |
canWrapOn(char c)
Returns how we can wrap on the supplied character. |
void |
copyThisStateTo(NodeWriter nw)
Copies the state from one node writer to another. |
boolean |
enableWrapping(boolean b)
Sets the flag that indicates if we are allowed to wrap lines. |
java.lang.String |
getIndentation()
Returns the indentation level. |
antlr.collections.AST |
getPreviousAST()
|
antlr.collections.AST |
getPreviousAST(antlr.collections.AST ast)
|
boolean |
isLastLineEmpty()
Returns true if the last line is empty. |
boolean |
isWritten(antlr.Token token)
Returns true if the supplied token is written. |
void |
markAsWritten(antlr.Token token)
Marks the supplied token as written. |
void |
newLine()
Writes a new line sequence and then an indentation to the underlying buffer. |
java.lang.String |
popIndentation()
Pops an indentation level off the stack. |
java.lang.String |
popIndentationAndWrite(java.lang.String s)
This is the same as writing popIndentation() and then
write(s) .It exists because the JavaNodeWriter should be able to
write comments before popping the indentation. |
void |
pushIndentation()
Indents with the number of spaces defined in the settings. |
void |
pushIndentation(int indent)
Indents with the supplied number of spaces. |
void |
pushIndentation(java.lang.String indent)
Indents with the supplied string. |
void |
pushIndentationCurrentPos()
Pushes an indentaion string with the same number of spaces as the the number of characters on the last line. |
void |
removeSpacesAfter(int startPos)
Helper method that removes all the spaces after the supplied position. |
java.lang.String |
toString()
Returns the output of the underlying buffer |
void |
write(antlr.collections.AST ast)
Writes the supplied ast to the underlying stream. |
void |
write(java.lang.String s)
Writes data to the underlying buffer. |
void |
write(antlr.Token token)
Writes data to the underlying buffer. It checks if the token has been written before and does not write it if that is the case. |
void |
write(antlr.Token token,
boolean checkWritten)
Writes data to the underlying buffer. |
void |
writeInParenthesis(antlr.collections.AST op)
Helper method that writes the supplied ast in parenthesis. |
void |
writeStatement(antlr.collections.AST ast)
Helper method that writes the supplied ast as a statement. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int WRAP_NOT
public static final int WRAP_BEFORE
public static final int WRAP_AFTER
public static final int WRAP_ON
protected java.util.Vector parents_
protected java.util.HashSet writtenTokens_
protected java.lang.String latestWrapProspectIndent_
protected int latestWrapProspectType_
protected int latestWrapProspectPos_
protected int lastLineWrapPos_
protected boolean canWrapLines_
protected antlr.collections.AST lastAST_
Constructor Detail |
public NodeWriter()
Method Detail |
public java.lang.String toString()
toString
in class java.lang.Object
public void copyThisStateTo(NodeWriter nw)
This method is used when we need to change the implementation of the node writer. For example when we switch between writing java code and java comments.
nw
- public void write(antlr.collections.AST ast)
ast
- the ast to write.java.lang.RuntimeException
- if ast is nullpublic void write(antlr.Token token)
token
- the token to get the text from.public void write(antlr.Token token, boolean checkWritten)
token
- the token to get the text from.checkWritten
- public void write(java.lang.String s)
s
- the string to outputprotected int canWrapOn(char c)
c
- the char to switch onprotected boolean canWrapBetween(antlr.collections.AST firstAst, antlr.collections.AST secondAst)
firstAst
- the ast to switch onsecondAst
- the ast to switch onpublic void removeSpacesAfter(int startPos)
This method is used when we wrap the lines to make sure that the indentation becomes correct.
startPos
- public void newLine()
public void pushIndentation()
public void pushIndentation(java.lang.String indent)
indent
- public void pushIndentation(int indent)
indent
- public void pushIndentationCurrentPos()
public java.lang.String popIndentationAndWrite(java.lang.String s)
popIndentation()
and then
write(s)
.JavaNodeWriter
should be able to
write comments before popping the indentation.s
- the string to writepublic java.lang.String popIndentation()
public java.lang.String getIndentation()
public antlr.collections.AST getPreviousAST()
public antlr.collections.AST getPreviousAST(antlr.collections.AST ast)
ast
- public void markAsWritten(antlr.Token token)
token
- the token to mark.public boolean isWritten(antlr.Token token)
token
- the token to determine if written.public void writeStatement(antlr.collections.AST ast)
This method is invoked from the if
and
while
asts.
ast
- the ast to writepublic void writeInParenthesis(antlr.collections.AST op)
This method is invoked from the asts that may need this functionality to separate two operands with same precidence.
op
- the operator to write in the parenthesispublic boolean isLastLineEmpty()
This method returns true if the internal string buffer ends with the new line fetched frm the settings and the current indentation.
public boolean enableWrapping(boolean b)
b
- should wrapping be enabled
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |