KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > expression > ExpressionValidateVisitor


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.expression;
5
6 import java.util.List JavaDoc;
7
8 import com.tc.aspectwerkz.expression.ast.*;
9 import com.tc.aspectwerkz.expression.regexp.TypePattern;
10
11 /**
12  * The visitor that extract all possible arguments referenced by the expression.
13  * <p/>
14  * TODO handle pointcut reference and handle parameter transition
15  * + checks as done in the ArgIndexVisitor for this / target compliance.
16  *
17  * @author <a HREF="mailto:alex AT gnilux DOT com">Alexandre Vasseur </a>
18  */

19 public class ExpressionValidateVisitor implements ExpressionParserVisitor {
20
21   protected Node m_root;
22   protected String JavaDoc m_expression;
23   protected String JavaDoc m_namespace;
24
25   /**
26    * Creates a new expression.
27    *
28    * @param expression the expression as a string
29    * @param namespace the namespace
30    * @param root the AST root
31    */

32   public ExpressionValidateVisitor(final String JavaDoc expression,
33                                    final String JavaDoc namespace,
34                                    final Node root) {
35     m_expression = expression;
36     m_namespace = namespace;
37     m_root = root;
38   }
39
40   /**
41    * Populate data with the possible arguments
42    *
43    * @param data a list to feed with Strings
44    */

45   public void populate(List JavaDoc data) {
46     visit(m_root, data);
47   }
48
49   // ============ Boot strap =============
50
public Object JavaDoc visit(Node node, Object JavaDoc data) {
51     return node.jjtGetChild(0).jjtAccept(this, data);
52   }
53
54   public Object JavaDoc visit(SimpleNode node, Object JavaDoc data) {
55     return node.jjtGetChild(0).jjtAccept(this, data);
56   }
57
58   public Object JavaDoc visit(ASTRoot node, Object JavaDoc data) {
59     return node.jjtGetChild(0).jjtAccept(this, data);
60   }
61
62   public Object JavaDoc visit(ASTExpression node, Object JavaDoc data) {
63     return node.jjtGetChild(0).jjtAccept(this, data);
64   }
65
66   // ============ Logical operators =============
67
public Object JavaDoc visit(ASTOr node, Object JavaDoc data) {
68     for (int i = 0; i < node.jjtGetNumChildren(); i++) {
69       List JavaDoc args = (List JavaDoc) node.jjtGetChild(i).jjtAccept(this, data);
70       //((List) data).addAll(args);
71
}
72     return data;
73   }
74
75   public Object JavaDoc visit(ASTAnd node, Object JavaDoc data) {
76     for (int i = 0; i < node.jjtGetNumChildren(); i++) {
77       node.jjtGetChild(i).jjtAccept(this, data);
78     }
79     return data;
80   }
81
82   public Object JavaDoc visit(ASTNot node, Object JavaDoc data) {
83     for (int i = 0; i < node.jjtGetNumChildren(); i++) {
84       node.jjtGetChild(i).jjtAccept(this, data);
85     }
86     return data;
87   }
88
89   // ============ Pointcut types =============
90
public Object JavaDoc visit(ASTPointcutReference node, Object JavaDoc data) {
91     // visit the args - if any
92
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
93       node.jjtGetChild(i).jjtAccept(this, data);
94     }
95     return data;
96   }
97
98   public Object JavaDoc visit(ASTExecution node, Object JavaDoc data) {
99     return data;
100   }
101
102   public Object JavaDoc visit(ASTCall node, Object JavaDoc data) {
103     return data;
104   }
105
106   public Object JavaDoc visit(ASTSet node, Object JavaDoc data) {
107     return data;
108   }
109
110   public Object JavaDoc visit(ASTGet node, Object JavaDoc data) {
111     return data;
112   }
113
114   public Object JavaDoc visit(ASTHandler node, Object JavaDoc data) {
115     return data;
116   }
117
118   public Object JavaDoc visit(ASTStaticInitialization node, Object JavaDoc data) {
119     return data;
120   }
121
122   public Object JavaDoc visit(ASTIf node, Object JavaDoc data) {
123     return data;
124   }
125
126   public Object JavaDoc visit(ASTWithin node, Object JavaDoc data) {
127     return data;
128   }
129
130   public Object JavaDoc visit(ASTWithinCode node, Object JavaDoc data) {
131     return data;
132   }
133
134
135   public Object JavaDoc visit(ASTHasMethod node, Object JavaDoc data) {
136     return data;
137   }
138
139   public Object JavaDoc visit(ASTHasField node, Object JavaDoc data) {
140     return data;
141   }
142
143   public Object JavaDoc visit(ASTCflow node, Object JavaDoc data) {
144     // visit the sub expression
145
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
146       node.jjtGetChild(i).jjtAccept(this, data);
147     }
148     return data;
149   }
150
151   public Object JavaDoc visit(ASTCflowBelow node, Object JavaDoc data) {
152     // visit the sub expression
153
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
154       node.jjtGetChild(i).jjtAccept(this, data);
155     }
156     return data;
157   }
158
159   public Object JavaDoc visit(ASTTarget node, Object JavaDoc data) {
160     ((List JavaDoc) data).add(node.getIdentifier());
161     return data;
162   }
163
164   public Object JavaDoc visit(ASTThis node, Object JavaDoc data) {
165     ((List JavaDoc) data).add(node.getIdentifier());
166     return data;
167   }
168
169   // ============ Patterns =============
170
public Object JavaDoc visit(ASTClassPattern node, Object JavaDoc data) {
171     return data;
172   }
173
174   public Object JavaDoc visit(ASTMethodPattern node, Object JavaDoc data) {
175     return data;
176   }
177
178   public Object JavaDoc visit(ASTConstructorPattern node, Object JavaDoc data) {
179     return data;
180   }
181
182   public Object JavaDoc visit(ASTFieldPattern node, Object JavaDoc data) {
183     return data;
184   }
185
186   public Object JavaDoc visit(ASTParameter node, Object JavaDoc data) {
187     return data;
188   }
189
190   public Object JavaDoc visit(ASTArgs node, Object JavaDoc data) {
191     for (int i = 0; i < node.jjtGetNumChildren(); i++) {
192       List JavaDoc args = (List JavaDoc) node.jjtGetChild(i).jjtAccept(this, data);
193       ((List JavaDoc) data).addAll(args);
194     }
195     return data;
196   }
197
198   public Object JavaDoc visit(ASTArgParameter node, Object JavaDoc data) {
199     TypePattern typePattern = node.getTypePattern();
200     ((List JavaDoc) data).add(typePattern.getPattern());
201     return data;
202   }
203
204   public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data) {
205     return data;
206   }
207
208   public Object JavaDoc visit(ASTModifier node, Object JavaDoc data) {
209     return data;
210   }
211
212   /**
213    * Returns the string representation of the expression.
214    *
215    * @return
216    */

217   public String JavaDoc toString() {
218     return m_expression;
219   }
220
221 }
Popular Tags