001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package org.codehaus.aspectwerkz.expression;
008:
009: import org.codehaus.aspectwerkz.expression.ast.ASTAnd;
010: import org.codehaus.aspectwerkz.expression.ast.ASTAttribute;
011: import org.codehaus.aspectwerkz.expression.ast.ASTCall;
012: import org.codehaus.aspectwerkz.expression.ast.ASTCflow;
013: import org.codehaus.aspectwerkz.expression.ast.ASTCflowBelow;
014: import org.codehaus.aspectwerkz.expression.ast.ASTClassPattern;
015: import org.codehaus.aspectwerkz.expression.ast.ASTConstructorPattern;
016: import org.codehaus.aspectwerkz.expression.ast.ASTExecution;
017: import org.codehaus.aspectwerkz.expression.ast.ASTExpression;
018: import org.codehaus.aspectwerkz.expression.ast.ASTFieldPattern;
019: import org.codehaus.aspectwerkz.expression.ast.ASTGet;
020: import org.codehaus.aspectwerkz.expression.ast.ASTHandler;
021: import org.codehaus.aspectwerkz.expression.ast.ASTMethodPattern;
022: import org.codehaus.aspectwerkz.expression.ast.ASTModifier;
023: import org.codehaus.aspectwerkz.expression.ast.ASTNot;
024: import org.codehaus.aspectwerkz.expression.ast.ASTOr;
025: import org.codehaus.aspectwerkz.expression.ast.ASTParameter;
026: import org.codehaus.aspectwerkz.expression.ast.ASTPointcutReference;
027: import org.codehaus.aspectwerkz.expression.ast.ASTRoot;
028: import org.codehaus.aspectwerkz.expression.ast.ASTSet;
029: import org.codehaus.aspectwerkz.expression.ast.ASTStaticInitialization;
030: import org.codehaus.aspectwerkz.expression.ast.ASTWithin;
031: import org.codehaus.aspectwerkz.expression.ast.ASTWithinCode;
032: import org.codehaus.aspectwerkz.expression.ast.ExpressionParserVisitor;
033: import org.codehaus.aspectwerkz.expression.ast.SimpleNode;
034: import org.codehaus.aspectwerkz.expression.ast.ASTArgs;
035: import org.codehaus.aspectwerkz.expression.ast.ASTArgParameter;
036: import org.codehaus.aspectwerkz.expression.ast.ASTHasField;
037: import org.codehaus.aspectwerkz.expression.ast.ASTHasMethod;
038: import org.codehaus.aspectwerkz.expression.ast.ASTTarget;
039: import org.codehaus.aspectwerkz.expression.ast.ASTThis;
040: import org.codehaus.aspectwerkz.expression.ast.Node;
041:
042: /**
043: * TODO: do we need that, there is a dump() method in jjtree API
044: *
045: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
046: * @author Michael Nascimento
047: */
048: public class DumpVisitor implements ExpressionParserVisitor {
049: private Node m_root;
050:
051: private int indent = 0;
052:
053: private DumpVisitor(final Node root) {
054: m_root = root;
055: }
056:
057: public static void dumpAST(final Node root) {
058: DumpVisitor dumper = new DumpVisitor(root);
059: dumper.visit((SimpleNode) dumper.m_root, null);
060: }
061:
062: public Object visit(SimpleNode node, Object data) {
063: System.out.println(indentString() + node);
064: ++indent;
065: data = node.jjtGetChild(0).jjtAccept(this , data);
066: --indent;
067: return data;
068: }
069:
070: public Object visit(ASTRoot node, Object data) {
071: System.out.println(indentString() + node);
072: ++indent;
073: data = node.jjtGetChild(0).jjtAccept(this , data);
074: --indent;
075: return data;
076: }
077:
078: public Object visit(ASTExpression node, Object data) {
079: System.out.println(indentString() + node);
080: ++indent;
081: data = node.jjtGetChild(0).jjtAccept(this , data);
082: --indent;
083: return data;
084: }
085:
086: public Object visit(ASTOr node, Object data) {
087: System.out.println(indentString() + node);
088: ++indent;
089: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
090: data = node.jjtGetChild(i).jjtAccept(this , data);
091: }
092: --indent;
093: return data;
094: }
095:
096: public Object visit(ASTAnd node, Object data) {
097: System.out.println(indentString() + node);
098: ++indent;
099: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
100: data = node.jjtGetChild(i).jjtAccept(this , data);
101: }
102: --indent;
103: return data;
104: }
105:
106: public Object visit(ASTNot node, Object data) {
107: System.out.println(indentString() + node);
108: ++indent;
109: data = node.jjtGetChild(0).jjtAccept(this , data);
110: --indent;
111: return data;
112: }
113:
114: public Object visit(ASTExecution node, Object data) {
115: System.out.println(indentString() + node);
116: ++indent;
117: data = node.jjtGetChild(0).jjtAccept(this , data);
118: --indent;
119: return data;
120: }
121:
122: public Object visit(ASTCall node, Object data) {
123: System.out.println(indentString() + node);
124: ++indent;
125: data = node.jjtGetChild(0).jjtAccept(this , data);
126: --indent;
127: return data;
128: }
129:
130: public Object visit(ASTSet node, Object data) {
131: System.out.println(indentString() + node);
132: ++indent;
133: data = node.jjtGetChild(0).jjtAccept(this , data);
134: --indent;
135: return data;
136: }
137:
138: public Object visit(ASTGet node, Object data) {
139: System.out.println(indentString() + node);
140: ++indent;
141: data = node.jjtGetChild(0).jjtAccept(this , data);
142: --indent;
143: return data;
144: }
145:
146: public Object visit(ASTHandler node, Object data) {
147: System.out.println(indentString() + node);
148: ++indent;
149: data = node.jjtGetChild(0).jjtAccept(this , data);
150: --indent;
151: return data;
152: }
153:
154: public Object visit(ASTWithin node, Object data) {
155: System.out.println(indentString() + node);
156: ++indent;
157: data = node.jjtGetChild(0).jjtAccept(this , data);
158: --indent;
159: return data;
160: }
161:
162: public Object visit(ASTWithinCode node, Object data) {
163: System.out.println(indentString() + node);
164: ++indent;
165: data = node.jjtGetChild(0).jjtAccept(this , data);
166: --indent;
167: return data;
168: }
169:
170: public Object visit(ASTStaticInitialization node, Object data) {
171: System.out.println(indentString() + node);
172: ++indent;
173: data = node.jjtGetChild(0).jjtAccept(this , data);
174: --indent;
175: return data;
176: }
177:
178: public Object visit(ASTCflow node, Object data) {
179: System.out.println(indentString() + node);
180: ++indent;
181: data = node.jjtGetChild(0).jjtAccept(this , data);
182: --indent;
183: return data;
184: }
185:
186: public Object visit(ASTCflowBelow node, Object data) {
187: System.out.println(indentString() + node);
188: ++indent;
189: data = node.jjtGetChild(0).jjtAccept(this , data);
190: --indent;
191: return data;
192: }
193:
194: public Object visit(ASTHasMethod node, Object data) {
195: System.out.println(indentString() + node);
196: ++indent;
197: data = node.jjtGetChild(0).jjtAccept(this , data);
198: --indent;
199: return data;
200: }
201:
202: public Object visit(ASTHasField node, Object data) {
203: System.out.println(indentString() + node);
204: ++indent;
205: data = node.jjtGetChild(0).jjtAccept(this , data);
206: --indent;
207: return data;
208: }
209:
210: public Object visit(ASTTarget node, Object data) {
211: System.out.println(indentString() + node);
212: ++indent;
213: System.out.println(node.getIdentifier());
214: --indent;
215: return data;
216: }
217:
218: public Object visit(ASTThis node, Object data) {
219: System.out.println(indentString() + node);
220: ++indent;
221: System.out.println(node.getIdentifier());
222: --indent;
223: return data;
224: }
225:
226: public Object visit(ASTClassPattern node, Object data) {
227: System.out.println(indentString() + node);
228: ++indent;
229: int nr = node.jjtGetNumChildren();
230: for (int i = 0; i < nr; i++) {
231: data = node.jjtGetChild(i).jjtAccept(this , data);
232: }
233: --indent;
234: return data;
235: }
236:
237: public Object visit(ASTMethodPattern node, Object data) {
238: System.out.println(indentString() + node);
239: ++indent;
240: int nr = node.jjtGetNumChildren();
241: for (int i = 0; i < nr; i++) {
242: data = node.jjtGetChild(i).jjtAccept(this , data);
243: }
244: --indent;
245: return data;
246: }
247:
248: public Object visit(ASTConstructorPattern node, Object data) {
249: System.out.println(indentString() + node);
250: ++indent;
251: int nr = node.jjtGetNumChildren();
252: for (int i = 0; i < nr; i++) {
253: data = node.jjtGetChild(i).jjtAccept(this , data);
254: }
255: --indent;
256: return data;
257: }
258:
259: public Object visit(ASTFieldPattern node, Object data) {
260: System.out.println(indentString() + node);
261: ++indent;
262: int nr = node.jjtGetNumChildren();
263: for (int i = 0; i < nr; i++) {
264: data = node.jjtGetChild(i).jjtAccept(this , data);
265: }
266: --indent;
267: return data;
268: }
269:
270: public Object visit(ASTPointcutReference node, Object data) {
271: System.out.println(indentString() + node);
272: return data;
273: }
274:
275: public Object visit(ASTParameter node, Object data) {
276: System.out.println(indentString() + node);
277: return data;
278: }
279:
280: public Object visit(ASTArgs node, Object data) {
281: System.out.println(indentString() + node);
282: ++indent;
283: if (node.jjtGetNumChildren() > 0) {
284: data = node.jjtGetChild(0).jjtAccept(this , data);
285: }
286: --indent;
287: return data;
288: }
289:
290: public Object visit(ASTArgParameter node, Object data) {
291: System.out.println(indentString() + node);
292: return data;
293: }
294:
295: public Object visit(ASTAttribute node, Object data) {
296: System.out.println(indentString() + node);
297: return data;
298: }
299:
300: public Object visit(ASTModifier node, Object data) {
301: System.out.println(indentString() + node);
302: return data;
303: }
304:
305: private String indentString() {
306: StringBuffer sb = new StringBuffer();
307: for (int i = 0; i < indent; ++i) {
308: sb.append(" ");
309: }
310: return sb.toString();
311: }
312: }
|