com.octagroup.foregej.antlr
Class NodeWriter

java.lang.Object
  |
  +--com.octagroup.foregej.antlr.NodeWriter
Direct Known Subclasses:
HtmlNodeWriter, JavaNodeWriter

public class NodeWriter
extends java.lang.Object

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 JavaNodeWritershould 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

WRAP_NOT

public static final int WRAP_NOT
Integer used to signal that we cannot wrap on a char or string.

WRAP_BEFORE

public static final int WRAP_BEFORE
Integer used to signal that we can wrap before a char or string.

WRAP_AFTER

public static final int WRAP_AFTER
Integer used to signal that we can wrap after a char or string.

WRAP_ON

public static final int WRAP_ON
Integer used to signal that we can wrap on a char or string.

parents_

protected java.util.Vector parents_
the parent node

writtenTokens_

protected java.util.HashSet writtenTokens_
a hashmap of all the written tokens before and after a node.

latestWrapProspectIndent_

protected java.lang.String latestWrapProspectIndent_
A reference to the indentation at the latest wrap prospect.

latestWrapProspectType_

protected int latestWrapProspectType_
Signals how the wrapping choulb be performed. ie should the character be removed, or should wrapping occurr before or after.

latestWrapProspectPos_

protected int latestWrapProspectPos_
The position of the latest line wrap prospect. If this is the same as the lastLineWrap we have not discovered any characters that we can wrap at.

lastLineWrapPos_

protected int lastLineWrapPos_
The position of the last line wrap.

canWrapLines_

protected boolean canWrapLines_
How do we deal with lines that exceed the maximum number of characters.

lastAST_

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.
Constructor Detail

NodeWriter

public NodeWriter()
Method Detail

toString

public java.lang.String toString()
Returns the output of the underlying buffer
Overrides:
toString in class java.lang.Object
Returns:
The text written to the underlying buffer.

copyThisStateTo

public void copyThisStateTo(NodeWriter nw)
Copies the state from one node writer to another.

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.

Parameters:
nw -  

write

public void write(antlr.collections.AST ast)
Writes the supplied ast to the underlying stream.
Parameters:
ast - the ast to write.
Throws:
java.lang.RuntimeException - if ast is null

write

public 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.
Parameters:
token - the token to get the text from.

write

public void write(antlr.Token token,
                  boolean checkWritten)
Writes data to the underlying buffer.
Parameters:
token - the token to get the text from.
checkWritten -  

write

public void write(java.lang.String s)
Writes data to the underlying buffer.
Parameters:
s - the string to output

canWrapOn

protected int canWrapOn(char c)
Returns how we can wrap on the supplied character.
Parameters:
c - the char to switch on
Returns:
an integer specifying which wrap algorithm to use.

canWrapBetween

protected boolean canWrapBetween(antlr.collections.AST firstAst,
                                 antlr.collections.AST secondAst)
Returns how we can wrap between the supplied asts.
Parameters:
firstAst - the ast to switch on
secondAst - the ast to switch on
Returns:
true if we can wrap between the asts.

removeSpacesAfter

public void removeSpacesAfter(int startPos)
Helper method that removes all the spaces after the supplied position.

This method is used when we wrap the lines to make sure that the indentation becomes correct.

Parameters:
startPos -  

newLine

public void newLine()
Writes a new line sequence and then an indentation to the underlying buffer.

pushIndentation

public void pushIndentation()
Indents with the number of spaces defined in the settings.


pushIndentation

public void pushIndentation(java.lang.String indent)
Indents with the supplied string.

Parameters:
indent -  

pushIndentation

public void pushIndentation(int indent)
Indents with the supplied number of spaces.

Parameters:
indent -  

pushIndentationCurrentPos

public void pushIndentationCurrentPos()
Pushes an indentaion string with the same number of spaces as the the number of characters on the last line.

popIndentationAndWrite

public java.lang.String popIndentationAndWrite(java.lang.String s)
This is the same as writing popIndentation()and then write(s).
It exists because the JavaNodeWritershould be able to write comments before popping the indentation.
Parameters:
s - the string to write
Returns:
the last indentation.

popIndentation

public java.lang.String popIndentation()
Pops an indentation level off the stack.
Returns:
the indentation level that was removed.

getIndentation

public java.lang.String getIndentation()
Returns the indentation level.
Returns:
the indentation level.

getPreviousAST

public antlr.collections.AST getPreviousAST()
Returns:
 

getPreviousAST

public antlr.collections.AST getPreviousAST(antlr.collections.AST ast)
Parameters:
ast -  
Returns:
 

markAsWritten

public void markAsWritten(antlr.Token token)
Marks the supplied token as written.
Parameters:
token - the token to mark.

isWritten

public boolean isWritten(antlr.Token token)
Returns true if the supplied token is written.
Parameters:
token - the token to determine if written.
Returns:
true if the supplied token is written.

writeStatement

public void writeStatement(antlr.collections.AST ast)
Helper method that writes the supplied ast as a statement.

This method is invoked from the ifand whileasts.

Parameters:
ast - the ast to write

writeInParenthesis

public void writeInParenthesis(antlr.collections.AST op)
Helper method that writes the supplied ast in parenthesis.

This method is invoked from the asts that may need this functionality to separate two operands with same precidence.

Parameters:
op - the operator to write in the parenthesis

isLastLineEmpty

public boolean isLastLineEmpty()
Returns true if the last line is empty.

This method returns true if the internal string buffer ends with the new line fetched frm the settings and the current indentation.

Returns:
 

enableWrapping

public boolean enableWrapping(boolean b)
Sets the flag that indicates if we are allowed to wrap lines.
Parameters:
b - should wrapping be enabled
Returns:
the old status.


Copyright © 2003 El Icognito des Noboby. All Rights Reserved.