openjava.ptree
Class ParseTreeObject

java.lang.Object
  |
  +--openjava.ptree.ParseTreeObject
All Implemented Interfaces:
java.lang.Cloneable, ParseTree
Direct Known Subclasses:
Leaf, List, NonLeaf

public abstract class ParseTreeObject
extends java.lang.Object
implements ParseTree, java.lang.Cloneable

The ParseTree class presents for the node of parse tree. This may be a token node, Leaf, or may be a nonterminal node, NonLeaf.

See Also:
Leaf, NonLeaf

Field Summary
protected static boolean debugFlag
          to write debugging code
protected static int debugLevel
           
protected static java.lang.String LN
          Why this modifier is not final ? - Because of javac bug in excuting it with -O option.
protected static java.io.PrintWriter out
          this is used as like grobal variable in ParseTree class-family.
protected static openjava.tools.WriterStack writerStack
          this is used as like grobal variable in ParseTree class-family.
 
Constructor Summary
ParseTreeObject()
          Arrocates new parse-tree object and set identifier number on the object.
 
Method Summary
abstract  void accept(ParseTreeVisitor visitor)
          Accepts a ParseTreeVisitor object as the role of a Visitor in the Visitor pattern, as the role of an Element in the Visitor pattern.
abstract  void childrenAccept(ParseTreeVisitor visitor)
          Accepts a ParseTreeVisitor object as the role of a Visitor in the Visitor pattern, as the role of an Element in the Visitor pattern.
protected  java.lang.Object clone()
          clone() is fixed as a shallow copy.
 boolean eq(ParseTree p)
          Tests if this parse-tree-node's value equals to the specified ptree-node's.
static boolean eq(ParseTree p, ParseTree q)
          Return true if only they refer to the same object.
static boolean equal(ParseTree p, ParseTree q)
          May return true if two ptree-nodes don't refer to not the same objects but their contents are equivalent.
abstract  boolean equals(ParseTree p)
          Tests if this parse-tree-node's value equals to the specified ptree-node's.
static void flushPrintWriter()
           
static boolean getDebugFlag()
           
static int getNest()
           
 int getObjectID()
          Returns
 ParseTreeObject getParent()
           
static java.io.PrintWriter getPrintWriter()
           
static java.lang.String getTab()
           
 int hashCode()
           
static int lastObjectID()
           
 ParseTree makeCopy()
          shallow copy
abstract  ParseTree makeRecursiveCopy()
          deep copy
static void popNest()
           
static java.io.PrintWriter popPrintWriter()
           
static void pushNest()
           
static void pushPrintWriter(java.io.PrintWriter pw)
           
 void replace(ParseTree replacement)
           
protected abstract  void replaceChildWith(ParseTree dist, ParseTree replacement)
           
static void setDebugFlag(boolean df)
           
static void setDebugLevel(int n)
           
static void setNest(int i)
           
protected  void setParent(ParseTreeObject parent)
           
static void setPrintStream(java.io.PrintStream pstream)
          Sets the writer to the one from the specified stream.
static void setTab(java.lang.String str)
           
 java.lang.String toFlattenString()
          Generates the string expression from this node.
 java.lang.String toString()
          Generates a string object of regular Java source code representing this parse-tree.
abstract  void writeCode()
          Deprecated.  
protected static void writeDebug(java.lang.String str)
           
protected  void writeDebugL()
           
protected static void writeDebugLln()
           
protected static void writeDebugln()
           
protected static void writeDebugLR()
           
protected static void writeDebugR()
           
protected static void writeDebugRln()
           
protected static void writeTab()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LN

protected static java.lang.String LN
Why this modifier is not final ? - Because of javac bug in excuting it with -O option.

writerStack

protected static openjava.tools.WriterStack writerStack
this is used as like grobal variable in ParseTree class-family.

out

protected static java.io.PrintWriter out
this is used as like grobal variable in ParseTree class-family.

debugFlag

protected static boolean debugFlag
to write debugging code

debugLevel

protected static int debugLevel
Constructor Detail

ParseTreeObject

public ParseTreeObject()
Arrocates new parse-tree object and set identifier number on the object.
Method Detail

getParent

public final ParseTreeObject getParent()

setParent

protected final void setParent(ParseTreeObject parent)

replace

public final void replace(ParseTree replacement)
                   throws ParseTreeException
Specified by:
replace in interface ParseTree

replaceChildWith

protected abstract void replaceChildWith(ParseTree dist,
                                         ParseTree replacement)
                                  throws ParseTreeException

clone

protected final java.lang.Object clone()
clone() is fixed as a shallow copy.
Overrides:
clone in class java.lang.Object
Returns:
the copy of this ptree-node.

makeCopy

public ParseTree makeCopy()
shallow copy
Specified by:
makeCopy in interface ParseTree
Following copied from interface: openjava.ptree.ParseTree
Returns:
the copy of this nonleaf-node as a ptree-node.

makeRecursiveCopy

public abstract ParseTree makeRecursiveCopy()
deep copy
Specified by:
makeRecursiveCopy in interface ParseTree
Following copied from interface: openjava.ptree.ParseTree
Returns:
the copy of this nonleaf-node as a ptree-node.

equals

public abstract boolean equals(ParseTree p)
Tests if this parse-tree-node's value equals to the specified ptree-node's.
Specified by:
equals in interface ParseTree
Returns:
true if two values are same.

eq

public final boolean eq(ParseTree p)
Tests if this parse-tree-node's value equals to the specified ptree-node's.
Specified by:
eq in interface ParseTree
Returns:
true if two this and p refer to the same ptree object.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Generates a string object of regular Java source code representing this parse-tree.
Specified by:
toString in interface ParseTree
Overrides:
toString in class java.lang.Object
Returns:
string which represents this parse-tree

setPrintStream

public static void setPrintStream(java.io.PrintStream pstream)
Sets the writer to the one from the specified stream.
Parameters:
pstrem - print stream

getPrintWriter

public static java.io.PrintWriter getPrintWriter()

popPrintWriter

public static java.io.PrintWriter popPrintWriter()

pushPrintWriter

public static void pushPrintWriter(java.io.PrintWriter pw)

flushPrintWriter

public static void flushPrintWriter()

setDebugFlag

public static void setDebugFlag(boolean df)

setDebugLevel

public static void setDebugLevel(int n)

getDebugFlag

public static boolean getDebugFlag()

setTab

public static void setTab(java.lang.String str)

getTab

public static java.lang.String getTab()

setNest

public static void setNest(int i)

getNest

public static int getNest()

pushNest

public static void pushNest()

popNest

public static void popNest()

writeDebugL

protected void writeDebugL()

writeDebugR

protected static void writeDebugR()

writeDebugLR

protected static void writeDebugLR()

writeDebugLln

protected static void writeDebugLln()

writeDebugRln

protected static void writeDebugRln()

writeDebugln

protected static void writeDebugln()

writeDebug

protected static void writeDebug(java.lang.String str)

writeTab

protected static void writeTab()

writeCode

public abstract void writeCode()
Deprecated.  

Use accept(SourceCodeWriter).
Specified by:
writeCode in interface ParseTree

eq

public static final boolean eq(ParseTree p,
                               ParseTree q)
Return true if only they refer to the same object. If two objects are both null, this returns true.
Parameters:
p - the ptree-node
q - the ptree-node
Returns:
true if p and q refer to same object.

equal

public static final boolean equal(ParseTree p,
                                  ParseTree q)
May return true if two ptree-nodes don't refer to not the same objects but their contents are equivalent.
Parameters:
p - the node
q - the node to compare
Returns:
true if p equals c

lastObjectID

public static final int lastObjectID()

getObjectID

public final int getObjectID()
Returns
Specified by:
getObjectID in interface ParseTree
Parameters:
id - ID
Returns:
Name the ID represents

toFlattenString

public java.lang.String toFlattenString()
Generates the string expression from this node. Returned string doesn't have '"' without cancel ( \" ) and doesn't have newline.

This method is useful to embed ptree objects as a string literal in source code.

Specified by:
toFlattenString in interface ParseTree
Returns:
the flatten string which this node represents

accept

public abstract void accept(ParseTreeVisitor visitor)
                     throws ParseTreeException
Accepts a ParseTreeVisitor object as the role of a Visitor in the Visitor pattern, as the role of an Element in the Visitor pattern.

This invoke an appropriate visit() method on the accepted visitor.

Specified by:
accept in interface ParseTree
Parameters:
visitor - a visitor

childrenAccept

public abstract void childrenAccept(ParseTreeVisitor visitor)
                             throws ParseTreeException
Accepts a ParseTreeVisitor object as the role of a Visitor in the Visitor pattern, as the role of an Element in the Visitor pattern.

This invoke an appropriate visit() method on each child ParseTree object with this visitor.

Specified by:
childrenAccept in interface ParseTree
Parameters:
visitor - a visitor