KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > expression > DumpVisitor


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.expression;
5
6 import com.tc.aspectwerkz.expression.ast.*;
7
8 /**
9  * TODO: do we need that, there is a dump() method in jjtree API
10  *
11  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
12  * @author Michael Nascimento
13  */

14 public class DumpVisitor implements ExpressionParserVisitor {
15   private Node m_root;
16
17   private int indent = 0;
18
19   private DumpVisitor(final Node root) {
20     m_root = root;
21   }
22
23   public static void dumpAST(final Node root) {
24     DumpVisitor dumper = new DumpVisitor(root);
25     dumper.visit((SimpleNode) dumper.m_root, null);
26   }
27
28   public Object JavaDoc visit(SimpleNode node, Object JavaDoc data) {
29     System.out.println(indentString() + node);
30     ++indent;
31     data = node.jjtGetChild(0).jjtAccept(this, data);
32     --indent;
33     return data;
34   }
35
36   public Object JavaDoc visit(ASTRoot node, Object JavaDoc data) {
37     System.out.println(indentString() + node);
38     ++indent;
39     data = node.jjtGetChild(0).jjtAccept(this, data);
40     --indent;
41     return data;
42   }
43
44   public Object JavaDoc visit(ASTExpression node, Object JavaDoc data) {
45     System.out.println(indentString() + node);
46     ++indent;
47     data = node.jjtGetChild(0).jjtAccept(this, data);
48     --indent;
49     return data;
50   }
51
52   public Object JavaDoc visit(ASTOr node, Object JavaDoc data) {
53     System.out.println(indentString() + node);
54     ++indent;
55     for (int i = 0; i < node.jjtGetNumChildren(); i++) {
56       data = node.jjtGetChild(i).jjtAccept(this, data);
57     }
58     --indent;
59     return data;
60   }
61
62   public Object JavaDoc visit(ASTAnd node, Object JavaDoc data) {
63     System.out.println(indentString() + node);
64     ++indent;
65     for (int i = 0; i < node.jjtGetNumChildren(); i++) {
66       data = node.jjtGetChild(i).jjtAccept(this, data);
67     }
68     --indent;
69     return data;
70   }
71
72   public Object JavaDoc visit(ASTNot node, Object JavaDoc data) {
73     System.out.println(indentString() + node);
74     ++indent;
75     data = node.jjtGetChild(0).jjtAccept(this, data);
76     --indent;
77     return data;
78   }
79
80   public Object JavaDoc visit(ASTExecution node, Object JavaDoc data) {
81     System.out.println(indentString() + node);
82     ++indent;
83     data = node.jjtGetChild(0).jjtAccept(this, data);
84     --indent;
85     return data;
86   }
87
88   public Object JavaDoc visit(ASTCall node, Object JavaDoc data) {
89     System.out.println(indentString() + node);
90     ++indent;
91     data = node.jjtGetChild(0).jjtAccept(this, data);
92     --indent;
93     return data;
94   }
95
96   public Object JavaDoc visit(ASTSet node, Object JavaDoc data) {
97     System.out.println(indentString() + node);
98     ++indent;
99     data = node.jjtGetChild(0).jjtAccept(this, data);
100     --indent;
101     return data;
102   }
103
104   public Object JavaDoc visit(ASTGet node, Object JavaDoc data) {
105     System.out.println(indentString() + node);
106     ++indent;
107     data = node.jjtGetChild(0).jjtAccept(this, data);
108     --indent;
109     return data;
110   }
111
112   public Object JavaDoc visit(ASTHandler node, Object JavaDoc data) {
113     System.out.println(indentString() + node);
114     ++indent;
115     data = node.jjtGetChild(0).jjtAccept(this, data);
116     --indent;
117     return data;
118   }
119
120   public Object JavaDoc visit(ASTWithin node, Object JavaDoc data) {
121     System.out.println(indentString() + node);
122     ++indent;
123     data = node.jjtGetChild(0).jjtAccept(this, data);
124     --indent;
125     return data;
126   }
127
128   public Object JavaDoc visit(ASTWithinCode node, Object JavaDoc data) {
129     System.out.println(indentString() + node);
130     ++indent;
131     data = node.jjtGetChild(0).jjtAccept(this, data);
132     --indent;
133     return data;
134   }
135
136   public Object JavaDoc visit(ASTStaticInitialization node, Object JavaDoc data) {
137     System.out.println(indentString() + node);
138     ++indent;
139     data = node.jjtGetChild(0).jjtAccept(this, data);
140     --indent;
141     return data;
142   }
143
144   public Object JavaDoc visit(ASTIf node, Object JavaDoc data) {
145     System.out.println(indentString() + "if()");
146     return data;
147   }
148
149   public Object JavaDoc visit(ASTCflow node, Object JavaDoc data) {
150     System.out.println(indentString() + node);
151     ++indent;
152     data = node.jjtGetChild(0).jjtAccept(this, data);
153     --indent;
154     return data;
155   }
156
157   public Object JavaDoc visit(ASTCflowBelow node, Object JavaDoc data) {
158     System.out.println(indentString() + node);
159     ++indent;
160     data = node.jjtGetChild(0).jjtAccept(this, data);
161     --indent;
162     return data;
163   }
164
165
166   public Object JavaDoc visit(ASTHasMethod node, Object JavaDoc data) {
167     System.out.println(indentString() + node);
168     ++indent;
169     data = node.jjtGetChild(0).jjtAccept(this, data);
170     --indent;
171     return data;
172   }
173
174
175   public Object JavaDoc visit(ASTHasField node, Object JavaDoc data) {
176     System.out.println(indentString() + node);
177     ++indent;
178     data = node.jjtGetChild(0).jjtAccept(this, data);
179     --indent;
180     return data;
181   }
182
183   public Object JavaDoc visit(ASTTarget node, Object JavaDoc data) {
184     System.out.println(indentString() + node);
185     ++indent;
186     System.out.println(node.getIdentifier());
187     --indent;
188     return data;
189   }
190
191   public Object JavaDoc visit(ASTThis node, Object JavaDoc data) {
192     System.out.println(indentString() + node);
193     ++indent;
194     System.out.println(node.getIdentifier());
195     --indent;
196     return data;
197   }
198
199   public Object JavaDoc visit(ASTClassPattern node, Object JavaDoc data) {
200     System.out.println(indentString() + node);
201     ++indent;
202     int nr = node.jjtGetNumChildren();
203     for (int i = 0; i < nr; i++) {
204       data = node.jjtGetChild(i).jjtAccept(this, data);
205     }
206     --indent;
207     return data;
208   }
209
210   public Object JavaDoc visit(ASTMethodPattern node, Object JavaDoc data) {
211     System.out.println(indentString() + node);
212     ++indent;
213     int nr = node.jjtGetNumChildren();
214     for (int i = 0; i < nr; i++) {
215       data = node.jjtGetChild(i).jjtAccept(this, data);
216     }
217     --indent;
218     return data;
219   }
220
221   public Object JavaDoc visit(ASTConstructorPattern node, Object JavaDoc data) {
222     System.out.println(indentString() + node);
223     ++indent;
224     int nr = node.jjtGetNumChildren();
225     for (int i = 0; i < nr; i++) {
226       data = node.jjtGetChild(i).jjtAccept(this, data);
227     }
228     --indent;
229     return data;
230   }
231
232   public Object JavaDoc visit(ASTFieldPattern node, Object JavaDoc data) {
233     System.out.println(indentString() + node);
234     ++indent;
235     int nr = node.jjtGetNumChildren();
236     for (int i = 0; i < nr; i++) {
237       data = node.jjtGetChild(i).jjtAccept(this, data);
238     }
239     --indent;
240     return data;
241   }
242
243   public Object JavaDoc visit(ASTPointcutReference node, Object JavaDoc data) {
244     System.out.println(indentString() + node);
245     return data;
246   }
247
248   public Object JavaDoc visit(ASTParameter node, Object JavaDoc data) {
249     System.out.println(indentString() + node);
250     return data;
251   }
252
253   public Object JavaDoc visit(ASTArgs node, Object JavaDoc data) {
254     System.out.println(indentString() + node);
255     ++indent;
256     if (node.jjtGetNumChildren() > 0) {
257       data = node.jjtGetChild(0).jjtAccept(this, data);
258     }
259     --indent;
260     return data;
261   }
262
263   public Object JavaDoc visit(ASTArgParameter node, Object JavaDoc data) {
264     System.out.println(indentString() + node);
265     return data;
266   }
267
268   public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data) {
269     System.out.println(indentString() + node);
270     return data;
271   }
272
273   public Object JavaDoc visit(ASTModifier node, Object JavaDoc data) {
274     System.out.println(indentString() + node);
275     return data;
276   }
277
278   private String JavaDoc indentString() {
279     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
280     for (int i = 0; i < indent; ++i) {
281       sb.append(" ");
282     }
283     return sb.toString();
284   }
285 }
Popular Tags