Class TopLevelClass.Default.Node

java.lang.Object
  |
  +--TopLevelClass.Default.Node
All Implemented Interfaces:
TopLevelClass.Node
Direct Known Subclasses:
TopLevelClass.Default.LabelOrNode, TopLevelClass.Default.Token, TopLevelClass.Default.Type
Enclosing class:
TopLevelClass.Default

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

Provides a simple implementation of TopLevelClass.Node.

Since:
notavaCC 1.0

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

Constructor Detail

TopLevelClass.Default.Node

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

The returned list of getChildNodes() is the childNodes rather than a copy of it. The parent node of childNodes is set to this by TopLevelClass.Node.setParentNode(TopLevelClass.Node). The default value of getParentNode() is null.

Parameters:
childNodes - a list of child nodes.
Since:
notavaCC 1.0
Method Detail

getChildNodes

public List getChildNodes()
Description copied from interface: TopLevelClass.Node
Returns the list of the child nodes of this.

For a Node created by the program generated by ¬<><∪∪, the list should be modifiable and the nodes should be ordered by its position in the parsed text. However, the nodes constructed by the users of ¬<><∪∪ are not required to satisfy it.

Specified by:
getChildNodes in interface TopLevelClass.Node
Returns:
the list of the child nodes of this.

accept

public final void accept(TopLevelClass.Visitor visitor)
Description copied from interface: TopLevelClass.Node
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 TopLevelClass.Node
Parameters:
visitor - a visitor.

getParentNode

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

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

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

setParentNode

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

Specified by:
setParentNode in interface TopLevelClass.Node
Parameters:
parentNode - the value TopLevelClass.Node.getParentNode() returns.

replaceChild

protected void replaceChild(TopLevelClass.Node oldChild,
                            TopLevelClass.Node newChild)
Replaces the child node oldChild with newChild.

This method calls newChild.setParentNode(this) and oldChild.setParentNode(null), and replaces oldChild in getChildNodes() with newChild. Also, this method replaces the values returned by TopLevelClass.Type.label().

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

replace

public void replace(TopLevelClass.Node oldNode)
             throws IllegalStateException
Replaces oldNode with this node.

The method calls ((TopLevelClass.Default.Node) oldNode.getParentNode()).replaceChild(oldNode, this).

Parameters:
oldNode - a node to replace.
Throws:
IllegalStateException - if oldNode.getParentNode() == null || !(oldNode.getParentNode() instanceof Default.Node)
Since:
notavaCC 1.0

toString

public String toString()
Overrides:
toString in class Object