KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > VTransformer > AddAcceptVisitor


1
2 /*
3  * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4  * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has
5  * intellectual property rights relating to technology embodied in the product
6  * that is described in this document. In particular, and without limitation,
7  * these intellectual property rights may include one or more of the U.S.
8  * patents listed at http://www.sun.com/patents and one or more additional
9  * patents or pending patent applications in the U.S. and in other countries.
10  * U.S. Government Rights - Commercial software. Government users are subject
11  * to the Sun Microsystems, Inc. standard license agreement and applicable
12  * provisions of the FAR and its supplements. Use is subject to license terms.
13  * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
14  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This
15  * product is covered and controlled by U.S. Export Control laws and may be
16  * subject to the export or import laws in other countries. Nuclear, missile,
17  * chemical biological weapons or nuclear maritime end uses or end users,
18  * whether direct or indirect, are strictly prohibited. Export or reexport
19  * to countries subject to U.S. embargo or to entities identified on U.S.
20  * export exclusion lists, including, but not limited to, the denied persons
21  * and specially designated nationals lists is strictly prohibited.
22  */

23
24
25 package VTransformer;
26
27 import java.io.PrintStream JavaDoc;
28
29 public class AddAcceptVisitor extends UnparseVisitor
30 {
31
32   public AddAcceptVisitor(PrintStream JavaDoc o)
33   {
34     super(o);
35   }
36
37
38   public Object JavaDoc visit(ASTClassBodyDeclaration node, Object JavaDoc data)
39   {
40     /* Are we the first child of our parent? */
41     if (node == node.jjtGetParent().jjtGetChild(0)) {
42
43       /** Attempt to make the new code match the indentation of the
44           node. */

45       StringBuffer JavaDoc pre = new StringBuffer JavaDoc("");
46       for (int i = 1; i < node.getFirstToken().beginColumn; ++i) {
47     pre.append(" ");
48       }
49
50       out.println(pre + "");
51       out.println(pre + "/** Accept the visitor. **/");
52       out.println(pre + "public Object jjtAccept(JavaParserVisitor visitor, Object data) {");
53       out.println(pre + " return visitor.visit(this, data);");
54       out.println(pre + "}");
55     }
56     return super.visit(node, data);
57   }
58
59 }
60
Popular Tags