001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.expression;
005:
006: import com.tc.aspectwerkz.expression.ast.*;
007:
008: /**
009: * TODO: do we need that, there is a dump() method in jjtree API
010: *
011: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
012: * @author Michael Nascimento
013: */
014: public class DumpVisitor implements ExpressionParserVisitor {
015: private Node m_root;
016:
017: private int indent = 0;
018:
019: private DumpVisitor(final Node root) {
020: m_root = root;
021: }
022:
023: public static void dumpAST(final Node root) {
024: DumpVisitor dumper = new DumpVisitor(root);
025: dumper.visit((SimpleNode) dumper.m_root, null);
026: }
027:
028: public Object visit(SimpleNode node, Object data) {
029: System.out.println(indentString() + node);
030: ++indent;
031: data = node.jjtGetChild(0).jjtAccept(this , data);
032: --indent;
033: return data;
034: }
035:
036: public Object visit(ASTRoot node, Object data) {
037: System.out.println(indentString() + node);
038: ++indent;
039: data = node.jjtGetChild(0).jjtAccept(this , data);
040: --indent;
041: return data;
042: }
043:
044: public Object visit(ASTExpression node, Object data) {
045: System.out.println(indentString() + node);
046: ++indent;
047: data = node.jjtGetChild(0).jjtAccept(this , data);
048: --indent;
049: return data;
050: }
051:
052: public Object visit(ASTOr node, Object data) {
053: System.out.println(indentString() + node);
054: ++indent;
055: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
056: data = node.jjtGetChild(i).jjtAccept(this , data);
057: }
058: --indent;
059: return data;
060: }
061:
062: public Object visit(ASTAnd node, Object data) {
063: System.out.println(indentString() + node);
064: ++indent;
065: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
066: data = node.jjtGetChild(i).jjtAccept(this , data);
067: }
068: --indent;
069: return data;
070: }
071:
072: public Object visit(ASTNot node, Object data) {
073: System.out.println(indentString() + node);
074: ++indent;
075: data = node.jjtGetChild(0).jjtAccept(this , data);
076: --indent;
077: return data;
078: }
079:
080: public Object visit(ASTExecution node, Object data) {
081: System.out.println(indentString() + node);
082: ++indent;
083: data = node.jjtGetChild(0).jjtAccept(this , data);
084: --indent;
085: return data;
086: }
087:
088: public Object visit(ASTCall node, Object data) {
089: System.out.println(indentString() + node);
090: ++indent;
091: data = node.jjtGetChild(0).jjtAccept(this , data);
092: --indent;
093: return data;
094: }
095:
096: public Object visit(ASTSet node, Object data) {
097: System.out.println(indentString() + node);
098: ++indent;
099: data = node.jjtGetChild(0).jjtAccept(this , data);
100: --indent;
101: return data;
102: }
103:
104: public Object visit(ASTGet node, Object 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 visit(ASTHandler node, Object 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 visit(ASTWithin node, Object 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 visit(ASTWithinCode node, Object 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 visit(ASTStaticInitialization node, Object 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 visit(ASTIf node, Object data) {
145: System.out.println(indentString() + "if()");
146: return data;
147: }
148:
149: public Object visit(ASTCflow node, Object 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 visit(ASTCflowBelow node, Object 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: public Object visit(ASTHasMethod node, Object data) {
166: System.out.println(indentString() + node);
167: ++indent;
168: data = node.jjtGetChild(0).jjtAccept(this , data);
169: --indent;
170: return data;
171: }
172:
173: public Object visit(ASTHasField node, Object data) {
174: System.out.println(indentString() + node);
175: ++indent;
176: data = node.jjtGetChild(0).jjtAccept(this , data);
177: --indent;
178: return data;
179: }
180:
181: public Object visit(ASTTarget node, Object data) {
182: System.out.println(indentString() + node);
183: ++indent;
184: System.out.println(node.getIdentifier());
185: --indent;
186: return data;
187: }
188:
189: public Object visit(ASTThis node, Object data) {
190: System.out.println(indentString() + node);
191: ++indent;
192: System.out.println(node.getIdentifier());
193: --indent;
194: return data;
195: }
196:
197: public Object visit(ASTClassPattern node, Object data) {
198: System.out.println(indentString() + node);
199: ++indent;
200: int nr = node.jjtGetNumChildren();
201: for (int i = 0; i < nr; i++) {
202: data = node.jjtGetChild(i).jjtAccept(this , data);
203: }
204: --indent;
205: return data;
206: }
207:
208: public Object visit(ASTMethodPattern node, Object data) {
209: System.out.println(indentString() + node);
210: ++indent;
211: int nr = node.jjtGetNumChildren();
212: for (int i = 0; i < nr; i++) {
213: data = node.jjtGetChild(i).jjtAccept(this , data);
214: }
215: --indent;
216: return data;
217: }
218:
219: public Object visit(ASTConstructorPattern node, Object data) {
220: System.out.println(indentString() + node);
221: ++indent;
222: int nr = node.jjtGetNumChildren();
223: for (int i = 0; i < nr; i++) {
224: data = node.jjtGetChild(i).jjtAccept(this , data);
225: }
226: --indent;
227: return data;
228: }
229:
230: public Object visit(ASTFieldPattern node, Object data) {
231: System.out.println(indentString() + node);
232: ++indent;
233: int nr = node.jjtGetNumChildren();
234: for (int i = 0; i < nr; i++) {
235: data = node.jjtGetChild(i).jjtAccept(this , data);
236: }
237: --indent;
238: return data;
239: }
240:
241: public Object visit(ASTPointcutReference node, Object data) {
242: System.out.println(indentString() + node);
243: return data;
244: }
245:
246: public Object visit(ASTParameter node, Object data) {
247: System.out.println(indentString() + node);
248: return data;
249: }
250:
251: public Object visit(ASTArgs node, Object data) {
252: System.out.println(indentString() + node);
253: ++indent;
254: if (node.jjtGetNumChildren() > 0) {
255: data = node.jjtGetChild(0).jjtAccept(this , data);
256: }
257: --indent;
258: return data;
259: }
260:
261: public Object visit(ASTArgParameter node, Object data) {
262: System.out.println(indentString() + node);
263: return data;
264: }
265:
266: public Object visit(ASTAttribute node, Object data) {
267: System.out.println(indentString() + node);
268: return data;
269: }
270:
271: public Object visit(ASTModifier node, Object data) {
272: System.out.println(indentString() + node);
273: return data;
274: }
275:
276: private String indentString() {
277: StringBuffer sb = new StringBuffer();
278: for (int i = 0; i < indent; ++i) {
279: sb.append(" ");
280: }
281: return sb.toString();
282: }
283: }
|