KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > expression > DumpVisitor


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.expression;
9
10 import org.codehaus.aspectwerkz.expression.ast.ASTAnd;
11 import org.codehaus.aspectwerkz.expression.ast.ASTAttribute;
12 import org.codehaus.aspectwerkz.expression.ast.ASTCall;
13 import org.codehaus.aspectwerkz.expression.ast.ASTCflow;
14 import org.codehaus.aspectwerkz.expression.ast.ASTCflowBelow;
15 import org.codehaus.aspectwerkz.expression.ast.ASTClassPattern;
16 import org.codehaus.aspectwerkz.expression.ast.ASTConstructorPattern;
17 import org.codehaus.aspectwerkz.expression.ast.ASTExecution;
18 import org.codehaus.aspectwerkz.expression.ast.ASTExpression;
19 import org.codehaus.aspectwerkz.expression.ast.ASTFieldPattern;
20 import org.codehaus.aspectwerkz.expression.ast.ASTGet;
21 import org.codehaus.aspectwerkz.expression.ast.ASTHandler;
22 import org.codehaus.aspectwerkz.expression.ast.ASTMethodPattern;
23 import org.codehaus.aspectwerkz.expression.ast.ASTModifier;
24 import org.codehaus.aspectwerkz.expression.ast.ASTNot;
25 import org.codehaus.aspectwerkz.expression.ast.ASTOr;
26 import org.codehaus.aspectwerkz.expression.ast.ASTParameter;
27 import org.codehaus.aspectwerkz.expression.ast.ASTPointcutReference;
28 import org.codehaus.aspectwerkz.expression.ast.ASTRoot;
29 import org.codehaus.aspectwerkz.expression.ast.ASTSet;
30 import org.codehaus.aspectwerkz.expression.ast.ASTStaticInitialization;
31 import org.codehaus.aspectwerkz.expression.ast.ASTWithin;
32 import org.codehaus.aspectwerkz.expression.ast.ASTWithinCode;
33 import org.codehaus.aspectwerkz.expression.ast.ExpressionParserVisitor;
34 import org.codehaus.aspectwerkz.expression.ast.SimpleNode;
35 import org.codehaus.aspectwerkz.expression.ast.ASTArgs;
36 import org.codehaus.aspectwerkz.expression.ast.ASTArgParameter;
37 import org.codehaus.aspectwerkz.expression.ast.ASTHasField;
38 import org.codehaus.aspectwerkz.expression.ast.ASTHasMethod;
39 import org.codehaus.aspectwerkz.expression.ast.ASTTarget;
40 import org.codehaus.aspectwerkz.expression.ast.ASTThis;
41 import org.codehaus.aspectwerkz.expression.ast.Node;
42
43 /**
44  * TODO: do we need that, there is a dump() method in jjtree API
45  *
46  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
47  * @author Michael Nascimento
48  */

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