KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > pointcut > ast > PointcutParserTester


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.pointcut.ast;
23
24 import java.io.StringReader JavaDoc;
25
26 public class PointcutParserTester implements PointcutExpressionParserVisitor
27 {
28    private int indent = 0;
29
30    private String JavaDoc indentString()
31    {
32       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
33       for (int i = 0; i < indent; ++i)
34       {
35          sb.append(" ");
36       }
37       return sb.toString();
38    }
39
40
41
42    public Object JavaDoc visit(SimpleNode node, Object JavaDoc data)
43    {
44       System.out.println(indentString() + node +
45               ": acceptor not unimplemented in subclass?");
46       ++indent;
47       data = node.childrenAccept(this, data);
48       --indent;
49       return data;
50    }
51
52    public Object JavaDoc visit(ASTStart node, Object JavaDoc data)
53    {
54       System.out.println(indentString() + node);
55       ++indent;
56       data = node.childrenAccept(this, data);
57       --indent;
58       return data;
59    }
60
61    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
62    {
63       System.out.println(indentString() + node);
64       ++indent;
65       data = node.childrenAccept(this, data);
66       --indent;
67       return data;
68    }
69
70    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
71    {
72       System.out.println(indentString() + node);
73       ++indent;
74       data = node.childrenAccept(this, data);
75       --indent;
76       return data;
77    }
78
79    public Object JavaDoc visit(ASTExecutionOnly node, Object JavaDoc data)
80    {
81       return null;
82    }
83
84    public Object JavaDoc visit(ASTBoolean node, Object JavaDoc data)
85    {
86       System.out.println(indentString() + node);
87       ++indent;
88       data = node.childrenAccept(this, data);
89       --indent;
90       return data;
91    }
92
93    public Object JavaDoc visit(ASTField node, Object JavaDoc data)
94    {
95       System.out.print(indentString());
96       if (node.attributes != null)
97       {
98          for (int i = 0; i < node.attributes.size(); i++)
99          {
100             ASTAttribute attr = (ASTAttribute) node.attributes.get(i);
101             System.out.print(attr.attribute + " ");
102          }
103       }
104       System.out.print(node.getTypeExpression() + " ");
105       System.out.println(node.getClassExpr() + "." + node.getFieldExpr());
106       return data;
107    }
108
109    public Object JavaDoc visit(ASTMethod node, Object JavaDoc data)
110    {
111       System.out.print(indentString());
112       System.out.print(node.getReturnTypeExpression() + " ");
113       if (node.attributes != null)
114       {
115          for (int i = 0; i < node.attributes.size(); i++)
116          {
117             ASTAttribute attr = (ASTAttribute) node.attributes.get(i);
118             System.out.print(attr.attribute + " ");
119          }
120       }
121       System.out.print(node.getClassExpr() + "." + node.getMethodExpr() + "(");
122       if (node.parameters != null && !node.isAnyParameters())
123       {
124          for (int i = 0; i < node.parameters.size(); i++)
125          {
126             if (i > 0) System.out.print(", ");
127             System.out.print(node.parameters.get(i));
128          }
129       }
130       else if (node.isAnyParameters())
131       {
132          System.out.print("..");
133       }
134       System.out.println(")");
135       return data;
136    }
137
138    public Object JavaDoc visit(ASTConstructor node, Object JavaDoc data)
139    {
140       System.out.print(indentString());
141       if (node.attributes != null)
142       {
143          for (int i = 0; i < node.attributes.size(); i++)
144          {
145             ASTAttribute attr = (ASTAttribute) node.attributes.get(i);
146             System.out.print(attr.attribute + " ");
147          }
148       }
149       System.out.print(node.getClassExpr() + "(");
150       if (node.parameters != null && !node.isAnyParameters())
151       {
152          for (int i = 0; i < node.parameters.size(); i++)
153          {
154             if (i > 0) System.out.print(", ");
155             System.out.print(node.parameters.get(i));
156          }
157       }
158       else if (node.isAnyParameters())
159       {
160          System.out.print("..");
161       }
162
163       System.out.println(")");
164       return data;
165    }
166
167    public Object JavaDoc visit(ASTParameter node, Object JavaDoc data)
168    {
169       return null;
170    }
171
172    public Object JavaDoc visit(ASTComposite node, Object JavaDoc data)
173    {
174       System.out.println(indentString() + node);
175       ++indent;
176       data = node.childrenAccept(this, data);
177       --indent;
178       return data;
179    }
180
181    public Object JavaDoc visit(ASTCFlowExpression node, Object JavaDoc data)
182    {
183       System.out.println(indentString() + node);
184       ++indent;
185       data = node.childrenAccept(this, data);
186       --indent;
187       return data;
188    }
189    public Object JavaDoc visit(ASTCFlow node, Object JavaDoc data)
190    {
191       System.out.println(indentString() + node);
192       ++indent;
193       data = node.childrenAccept(this, data);
194       --indent;
195       return data;
196    }
197
198    public Object JavaDoc visit(ASTSub node, Object JavaDoc data)
199    {
200       System.out.println(indentString() + node);
201       ++indent;
202       data = node.childrenAccept(this, data);
203       --indent;
204       return data;
205    }
206
207    public Object JavaDoc visit(ASTAnd node, Object JavaDoc data)
208    {
209       System.out.println(indentString() + node);
210       ++indent;
211       data = node.childrenAccept(this, data);
212       --indent;
213       return data;
214    }
215
216    public Object JavaDoc visit(ASTOr node, Object JavaDoc data)
217    {
218       System.out.println(indentString() + node);
219       ++indent;
220       data = node.childrenAccept(this, data);
221       --indent;
222       return data;
223    }
224
225    public Object JavaDoc visit(ASTNot node, Object JavaDoc data)
226    {
227       System.out.println(indentString() + node);
228       ++indent;
229       data = node.childrenAccept(this, data);
230       --indent;
231       return data;
232    }
233
234    public Object JavaDoc visit(ASTNotCFlow node, Object JavaDoc data)
235    {
236       System.out.println(indentString() + node);
237       ++indent;
238       data = node.childrenAccept(this, data);
239       --indent;
240       return data;
241    }
242
243    public Object JavaDoc visit(ASTCFlowBoolean node, Object JavaDoc data)
244    {
245       System.out.println(indentString() + node);
246       ++indent;
247       data = node.childrenAccept(this, data);
248       --indent;
249       return data;
250    }
251
252    public Object JavaDoc visit(ASTCompositeCFlow node, Object JavaDoc data)
253    {
254       System.out.println(indentString() + node);
255       ++indent;
256       data = node.childrenAccept(this, data);
257       --indent;
258       return data;
259    }
260
261    public Object JavaDoc visit(ASTOrCFlow node, Object JavaDoc data)
262    {
263       System.out.println(indentString() + node);
264       ++indent;
265       data = node.childrenAccept(this, data);
266       --indent;
267       return data;
268    }
269
270    public Object JavaDoc visit(ASTAndCFlow node, Object JavaDoc data)
271    {
272       System.out.println(indentString() + node);
273       ++indent;
274       data = node.childrenAccept(this, data);
275       --indent;
276       return data;
277    }
278
279    public Object JavaDoc visit(ASTSubCFlow node, Object JavaDoc data)
280    {
281       System.out.println(indentString() + node);
282       ++indent;
283       data = node.childrenAccept(this, data);
284       --indent;
285       return data;
286    }
287
288    public Object JavaDoc visit(ASTAll node, Object JavaDoc data)
289    {
290       System.out.println(indentString() + node);
291       ++indent;
292       System.out.println(indentString() + node.getClasseExpression());
293       --indent;
294       return data;
295    }
296
297    public Object JavaDoc visit(ASTFieldExecution node, Object JavaDoc data)
298    {
299       System.out.println(indentString() + node);
300       ++indent;
301       data = node.childrenAccept(this, data);
302       --indent;
303       return data;
304    }
305
306    public Object JavaDoc visit(ASTCall node, Object JavaDoc data)
307    {
308       System.out.println(indentString() + node);
309       ++indent;
310       data = node.getBehavior().jjtAccept(this, data);
311       --indent;
312       return data;
313    }
314
315    public Object JavaDoc visit(ASTExecution node, Object JavaDoc data)
316    {
317       System.out.println(indentString() + node);
318       ++indent;
319       data = node.childrenAccept(this, data);
320       --indent;
321       return data;
322    }
323
324    public Object JavaDoc visit(ASTConstruction node, Object JavaDoc data)
325    {
326       System.out.println(indentString() + node);
327       ++indent;
328       data = node.childrenAccept(this, data);
329       --indent;
330       return data;
331    }
332
333    public Object JavaDoc visit(ASTGet node, Object JavaDoc data)
334    {
335       System.out.println(indentString() + node);
336       ++indent;
337       data = node.childrenAccept(this, data);
338       --indent;
339       return data;
340    }
341
342    public Object JavaDoc visit(ASTSet node, Object JavaDoc data)
343    {
344       System.out.println(indentString() + node);
345       ++indent;
346       data = node.childrenAccept(this, data);
347       --indent;
348       return data;
349    }
350
351    public Object JavaDoc visit(ASTPointcut node, Object JavaDoc data)
352    {
353       System.out.println(indentString() + node);
354       ++indent;
355       data = node.childrenAccept(this, data);
356       --indent;
357       return data;
358    }
359
360    public Object JavaDoc visit(ASTWithin node, Object JavaDoc data)
361    {
362       System.out.println(indentString() + node);
363       ++indent;
364       data = node.childrenAccept(this, data);
365       --indent;
366       return data;
367    }
368
369    public Object JavaDoc visit(ASTWithincode node, Object JavaDoc data)
370    {
371       System.out.println(indentString() + node);
372       ++indent;
373       data = node.childrenAccept(this, data);
374       --indent;
375       return data;
376    }
377    public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data)
378    {
379       return null;
380    }
381
382    public Object JavaDoc visit(ASTException node, Object JavaDoc data)
383    {
384       return null;
385    }
386
387    public Object JavaDoc visit(ASTAllParameter node, Object JavaDoc data)
388    {
389       return null;
390    }
391
392    public static void main(String JavaDoc args[])
393    {
394       System.out.println("----" + args[0]);
395       StringReader JavaDoc reader = new StringReader JavaDoc(args[0]);
396       PointcutExpressionParser t = new PointcutExpressionParser(reader);
397       //System.out.println("Reading from stdin");
398
//PointcutExpressionParser t = new PointcutExpressionParser(System.in);
399
try
400       {
401          ASTStart n = t.Start();
402          PointcutExpressionParserVisitor v = new PointcutParserTester();
403          n.jjtAccept(v, null);
404       }
405       catch (Exception JavaDoc e)
406       {
407          System.out.println("Oops.");
408          System.out.println(e.getMessage());
409          e.printStackTrace();
410       }
411    }
412 }
413
414 /*end*/
415
Popular Tags