KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > cflow > CflowAspectExpressionVisitor


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.cflow;
5
6
7 import com.tc.aspectwerkz.expression.ast.*;
8 import com.tc.aspectwerkz.expression.ExpressionInfo;
9 import com.tc.aspectwerkz.expression.ExpressionNamespace;
10
11 import java.util.List JavaDoc;
12
13 /**
14  * A visitor to create the bindings between cflow aspect and cflow subexpression.
15  * For each visited cflow / cflowbelow node, one CflowBinding is created
16  * with the cflow(below) subexpression as expressionInfo.
17  *
18  * @author <a HREF="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
19  */

20 public class CflowAspectExpressionVisitor implements ExpressionParserVisitor {
21
22   private ExpressionInfo m_expressionInfo;
23   private Node m_root;
24   private String JavaDoc m_namespace;
25
26   public CflowAspectExpressionVisitor(ExpressionInfo expressionInfo, Node root, String JavaDoc namespace) {
27     m_expressionInfo = expressionInfo;
28     m_root = root;
29     m_namespace = namespace;
30   }
31
32   /**
33    * Visit the expression and populate the list with CflowBinding for each cflow() or cflowbelow()
34    * subexpression encountered (including thru pointcut references)
35    *
36    * @param bindings
37    * @return the list of bindings
38    */

39   public List JavaDoc populateCflowAspectBindings(List JavaDoc bindings) {
40     visit(m_root, bindings);
41     return bindings;
42   }
43
44   public Object JavaDoc visit(Node node, Object JavaDoc data) {
45     return node.jjtGetChild(0).jjtAccept(this, data);
46   }
47
48   public Object JavaDoc visit(SimpleNode node, Object JavaDoc data) {
49     return node.jjtGetChild(0).jjtAccept(this, data);
50   }
51
52   public Object JavaDoc visit(ASTRoot node, Object JavaDoc data) {
53     return node.jjtGetChild(0).jjtAccept(this, data);
54   }
55
56   public Object JavaDoc visit(ASTExpression node, Object JavaDoc data) {
57     return node.jjtGetChild(0).jjtAccept(this, data);
58   }
59
60   public Object JavaDoc visit(ASTAnd node, Object JavaDoc data) {
61     // the AND and OR can have more than 2 nodes [see jjt grammar]
62
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
63       node.jjtGetChild(i).jjtAccept(this, data);
64     }
65     return data;
66   }
67
68   public Object JavaDoc visit(ASTOr node, Object JavaDoc data) {
69     // the AND and OR can have more than 2 nodes [see jjt grammar]
70
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
71       node.jjtGetChild(i).jjtAccept(this, data);
72     }
73     return data;
74   }
75
76   public Object JavaDoc visit(ASTNot node, Object JavaDoc data) {
77     return node.jjtGetChild(0).jjtAccept(this, data);
78   }
79
80   /**
81    * Resolve pointcut references
82    *
83    * @param node
84    * @param data
85    * @return
86    */

87   public Object JavaDoc visit(ASTPointcutReference node, Object JavaDoc data) {
88     ExpressionNamespace namespace = ExpressionNamespace.getNamespace(m_namespace);
89     CflowAspectExpressionVisitor expression = namespace.getExpressionInfo(node.getName()).getCflowAspectExpression();
90     return expression.populateCflowAspectBindings((List JavaDoc) data);
91   }
92
93   public Object JavaDoc visit(ASTExecution node, Object JavaDoc data) {
94     return data;
95   }
96
97   public Object JavaDoc visit(ASTCall node, Object JavaDoc data) {
98     return data;
99   }
100
101   public Object JavaDoc visit(ASTSet node, Object JavaDoc data) {
102     return data;
103   }
104
105   public Object JavaDoc visit(ASTGet node, Object JavaDoc data) {
106     return data;
107   }
108
109   public Object JavaDoc visit(ASTHandler node, Object JavaDoc data) {
110     return data;
111   }
112
113   public Object JavaDoc visit(ASTWithin node, Object JavaDoc data) {
114     return data;
115   }
116
117   public Object JavaDoc visit(ASTWithinCode node, Object JavaDoc data) {
118     return data;
119   }
120
121   public Object JavaDoc visit(ASTStaticInitialization node, Object JavaDoc data) {
122     return data;
123   }
124
125   public Object JavaDoc visit(ASTIf node, Object JavaDoc data) {
126     return data;
127   }
128
129   /**
130    * build a cflow binding with the cflow sub expression
131    *
132    * @param node
133    * @param data
134    * @return
135    */

136   public Object JavaDoc visit(ASTCflow node, Object JavaDoc data) {
137     int cflowID = node.hashCode();
138     Node subNode = node.jjtGetChild(0);
139     ExpressionInfo subExpression = new ExpressionInfo(subNode, m_namespace);
140     subExpression.inheritPossibleArgumentFrom(m_expressionInfo);
141     ((List JavaDoc) data).add(new CflowBinding(cflowID, subExpression, m_expressionInfo, false));
142     return data;
143   }
144
145   /**
146    * build a cflowbelow binding with the cflowbelow sub expression
147    *
148    * @param node
149    * @param data
150    * @return
151    */

152   public Object JavaDoc visit(ASTCflowBelow node, Object JavaDoc data) {
153     int cflowID = node.hashCode();
154     Node subNode = node.jjtGetChild(0);
155     ExpressionInfo subExpression = new ExpressionInfo(subNode, m_namespace);
156     subExpression.inheritPossibleArgumentFrom(m_expressionInfo);
157     ((List JavaDoc) data).add(new CflowBinding(cflowID, subExpression, m_expressionInfo, true));
158     return data;
159   }
160
161   public Object JavaDoc visit(ASTArgs node, Object JavaDoc data) {
162     return data;
163   }
164
165   public Object JavaDoc visit(ASTHasMethod node, Object JavaDoc data) {
166     return data;
167   }
168
169   public Object JavaDoc visit(ASTHasField node, Object JavaDoc data) {
170     return data;
171   }
172
173   public Object JavaDoc visit(ASTTarget node, Object JavaDoc data) {
174     return data;
175   }
176
177   public Object JavaDoc visit(ASTThis node, Object JavaDoc data) {
178     return data;
179   }
180
181   public Object JavaDoc visit(ASTClassPattern node, Object JavaDoc data) {
182     throw new UnsupportedOperationException JavaDoc("Should not be reached");
183   }
184
185   public Object JavaDoc visit(ASTMethodPattern node, Object JavaDoc data) {
186     throw new UnsupportedOperationException JavaDoc("Should not be reached");
187   }
188
189   public Object JavaDoc visit(ASTConstructorPattern node, Object JavaDoc data) {
190     throw new UnsupportedOperationException JavaDoc("Should not be reached");
191   }
192
193   public Object JavaDoc visit(ASTFieldPattern node, Object JavaDoc data) {
194     throw new UnsupportedOperationException JavaDoc("Should not be reached");
195   }
196
197   public Object JavaDoc visit(ASTParameter node, Object JavaDoc data) {
198     throw new UnsupportedOperationException JavaDoc("Should not be reached");
199   }
200
201   public Object JavaDoc visit(ASTArgParameter node, Object JavaDoc data) {
202     throw new UnsupportedOperationException JavaDoc("Should not be reached");
203   }
204
205   public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data) {
206     throw new UnsupportedOperationException JavaDoc("Should not be reached");
207   }
208
209   public Object JavaDoc visit(ASTModifier node, Object JavaDoc data) {
210     throw new UnsupportedOperationException JavaDoc("Should not be reached");
211   }
212 }
213
Popular Tags