KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > xjep > DeepCopyVisitor


1 /* @author rich
2  * Created on 16-Nov-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.xjep;
9
10 import org.nfunk.jep.*;
11
12 /**
13  * A Visitor which returns an exact copy of the tree.
14  * This class should be extended by visitors which
15  * modify trees and creates a new tree.
16  *
17  * @author Rich Morris
18  * Created on 16-Nov-2003
19  */

20 public class DeepCopyVisitor extends DoNothingVisitor implements ParserVisitor {
21
22     private XJep xjep;
23     /** Creates a deepCopy of a Node **/
24     public Node deepCopy(Node node,XJep xjep) throws ParseException
25     {
26         this.xjep = xjep;
27         Node res = (Node) node.jjtAccept(this,null);
28         return res;
29     }
30
31     public Object JavaDoc visit(ASTConstant node, Object JavaDoc data) throws ParseException
32     {
33         return xjep.getNodeFactory().buildConstantNode(node);
34     }
35
36     public Object JavaDoc visit(ASTVarNode node, Object JavaDoc data) throws ParseException
37     {
38         return xjep.getNodeFactory().buildVariableNode(node);
39     }
40
41     public Object JavaDoc visit(ASTFunNode node, Object JavaDoc data) throws ParseException
42     {
43         Node children[]=acceptChildrenAsArray(node,data);
44         return xjep.getNodeFactory().buildFunctionNode(node,children);
45     }
46 }
47
Popular Tags