parser
Class ExpressionParser.Default.Node

java.lang.Object
  |
  +--parser.ExpressionParser.Default.Node
All Implemented Interfaces:
ExpressionParser.Node
Direct Known Subclasses:
ExpressionParser.Default.Addition, ExpressionParser.Default.Division, ExpressionParser.Default.Multiplication, ExpressionParser.Default.Number, ExpressionParser.Default.Root, ExpressionParser.Default.Subtraction, ExpressionParser.Default.Token
Enclosing class:
ExpressionParser.Default

public abstract static class ExpressionParser.Default.Node
extends Object
implements ExpressionParser.Node

Provides a simple implementation of ExpressionParser.Node.

Since:
notavaCC 1.0

Constructor Summary
ExpressionParser.Default.Node(List childNodes)
          Constucts an instance.
 
Method Summary
 void accept(ExpressionParser.Visitor visitor)
          Traverses the (sub-)tree whose root is this node.
 List getChildNodes()
          Returns the list given by the constructor.
 ExpressionParser.Node getParentNode()
          Returns the parent node of this, or null if and only if this node is the root of the tree.
protected  void replaceChild(ExpressionParser.Node oldChild, ExpressionParser.Node newChild)
          Replaces the child node oldChild with newChild.
 void replaceSubtree(ExpressionParser.Node node)
          Replaces the sub-tree whose root is this with the sub-tree whose root is node.
 void setParentNode(ExpressionParser.Node parentNode)
          Sets the result of getParentNode().
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExpressionParser.Default.Node

public ExpressionParser.Default.Node(List childNodes)
Constucts an instance.

The parent node of childNodes is set to this.

Parameters:
childNodes - a list of child nodes, which is not copied and returned by getChildNodes().
Since:
notavaCC 1.0
Method Detail

getChildNodes

public List getChildNodes()
Returns the list given by the constructor.

Specified by:
getChildNodes in interface ExpressionParser.Node
Returns:
the list of the child nodes of this.
Since:
notavaCC 1.0

accept

public final void accept(ExpressionParser.Visitor visitor)
Traverses the (sub-)tree whose root is this node.

this node is passed to the visitor, then the child nodes are traversed recursively (preorder traversal). A node is passed to the methods of the visitor, using reflection, that is public, whose name is visit, that have only one argument whose type is compatible with this node, and that have no throws clause.

Specified by:
accept in interface ExpressionParser.Node
Parameters:
visitor - a visitor.
Since:
notavacc 1.0

getParentNode

public ExpressionParser.Node getParentNode()
Description copied from interface: ExpressionParser.Node
Returns the parent node of this, or null if and only if this node is the root of the tree.

This method simply returns the value the method ExpressionParser.Node.setParentNode(parser.ExpressionParser.Node) set, so the above specification should be maintained by the user of this object.

Specified by:
getParentNode in interface ExpressionParser.Node
Returns:
the parent node of this, or null if this node is the root of the tree.

setParentNode

public void setParentNode(ExpressionParser.Node parentNode)
Description copied from interface: ExpressionParser.Node
Sets the result of ExpressionParser.Node.getParentNode().

Specified by:
setParentNode in interface ExpressionParser.Node

replaceChild

protected void replaceChild(ExpressionParser.Node oldChild,
                            ExpressionParser.Node newChild)
Replaces the child node oldChild with newChild. Correctly, the method replaces the sub-tree whose root is oldChild with the sub-tree whose root is newChild.

The method dose not replace only the element of ExpressionParser.Node.getChildNodes(), but also the values returned by the methods that are defined by the classes in ExpressionParser and that return the child node(s) labeled in the notavaCC source.

The method calls newChild.setParentNode(this) and oldChild.setParentNode(null).

Parameters:
oldChild - a replaced child node.
newChild - a child node to replace oldChild.
Since:
notavaCC 1.0

replaceSubtree

public void replaceSubtree(ExpressionParser.Node node)
                    throws IllegalStateException
Replaces the sub-tree whose root is this with the sub-tree whose root is node.

The method calls node.setParentNode and this.setParentNode(null).

Precondition: (this.getParentNode() instanceof DefaultNode) sould be true.

Parameters:
node - a node to replace.
Throws:
IllegalStateException - parent == null || !(parent instanceof DefaultNode)
Since:
notavaCC 1.0

toString

public String toString()
Overrides:
toString in class Object