KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > expression > ExpressionValidateVisitor


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.expression;
9
10 import org.codehaus.aspectwerkz.annotation.AnnotationInfo;
11 import org.codehaus.aspectwerkz.expression.ast.ASTAnd;
12 import org.codehaus.aspectwerkz.expression.ast.ASTAttribute;
13 import org.codehaus.aspectwerkz.expression.ast.ASTCall;
14 import org.codehaus.aspectwerkz.expression.ast.ASTCflow;
15 import org.codehaus.aspectwerkz.expression.ast.ASTCflowBelow;
16 import org.codehaus.aspectwerkz.expression.ast.ASTClassPattern;
17 import org.codehaus.aspectwerkz.expression.ast.ASTConstructorPattern;
18 import org.codehaus.aspectwerkz.expression.ast.ASTExecution;
19 import org.codehaus.aspectwerkz.expression.ast.ASTExpression;
20 import org.codehaus.aspectwerkz.expression.ast.ASTFieldPattern;
21 import org.codehaus.aspectwerkz.expression.ast.ASTGet;
22 import org.codehaus.aspectwerkz.expression.ast.ASTHandler;
23 import org.codehaus.aspectwerkz.expression.ast.ASTMethodPattern;
24 import org.codehaus.aspectwerkz.expression.ast.ASTModifier;
25 import org.codehaus.aspectwerkz.expression.ast.ASTNot;
26 import org.codehaus.aspectwerkz.expression.ast.ASTOr;
27 import org.codehaus.aspectwerkz.expression.ast.ASTParameter;
28 import org.codehaus.aspectwerkz.expression.ast.ASTPointcutReference;
29 import org.codehaus.aspectwerkz.expression.ast.ASTRoot;
30 import org.codehaus.aspectwerkz.expression.ast.ASTSet;
31 import org.codehaus.aspectwerkz.expression.ast.ASTStaticInitialization;
32 import org.codehaus.aspectwerkz.expression.ast.ASTWithin;
33 import org.codehaus.aspectwerkz.expression.ast.ASTWithinCode;
34 import org.codehaus.aspectwerkz.expression.ast.ExpressionParserVisitor;
35 import org.codehaus.aspectwerkz.expression.ast.Node;
36 import org.codehaus.aspectwerkz.expression.ast.SimpleNode;
37 import org.codehaus.aspectwerkz.expression.ast.ASTArgs;
38 import org.codehaus.aspectwerkz.expression.ast.ASTArgParameter;
39 import org.codehaus.aspectwerkz.expression.regexp.TypePattern;
40 import org.codehaus.aspectwerkz.reflect.ClassInfo;
41 import org.codehaus.aspectwerkz.reflect.ConstructorInfo;
42 import org.codehaus.aspectwerkz.reflect.FieldInfo;
43 import org.codehaus.aspectwerkz.reflect.MemberInfo;
44 import org.codehaus.aspectwerkz.reflect.MethodInfo;
45 import org.codehaus.aspectwerkz.reflect.ReflectionInfo;
46
47 import java.lang.reflect.Modifier JavaDoc;
48 import java.util.ArrayList JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.List JavaDoc;
51
52 import org.codehaus.aspectwerkz.expression.ast.ASTHasField;
53 import org.codehaus.aspectwerkz.expression.ast.ASTHasMethod;
54 import org.codehaus.aspectwerkz.expression.ast.ASTTarget;
55 import org.codehaus.aspectwerkz.expression.ast.ASTThis;
56 import org.codehaus.aspectwerkz.util.Strings;
57
58 /**
59  * The visitor that extract all possible arguments referenced by the expression.
60  * <p/>
61  * TODO handle pointcut reference and handle parameter transition
62  * + checks as done in the ArgIndexVisitor for this / target compliance.
63  *
64  * @author <a HREF="mailto:alex AT gnilux DOT com">Alexandre Vasseur </a>
65  */

66 public class ExpressionValidateVisitor implements ExpressionParserVisitor {
67
68     protected Node m_root;
69     protected String JavaDoc m_expression;
70     protected String JavaDoc m_namespace;
71
72     /**
73      * Creates a new expression.
74      *
75      * @param expression the expression as a string
76      * @param namespace the namespace
77      * @param root the AST root
78      */

79     public ExpressionValidateVisitor(final String JavaDoc expression,
80                                      final String JavaDoc namespace,
81                                      final Node root) {
82         m_expression = expression;
83         m_namespace = namespace;
84         m_root = root;
85     }
86
87     /**
88      * Populate data with the possible arguments
89      *
90      * @param data a list to feed with Strings
91      */

92     public void populate(List JavaDoc data) {
93         visit(m_root, data);
94     }
95
96     // ============ Boot strap =============
97
public Object JavaDoc visit(Node node, Object JavaDoc data) {
98         return node.jjtGetChild(0).jjtAccept(this, data);
99     }
100
101     public Object JavaDoc visit(SimpleNode node, Object JavaDoc data) {
102         return node.jjtGetChild(0).jjtAccept(this, data);
103     }
104
105     public Object JavaDoc visit(ASTRoot node, Object JavaDoc data) {
106         return node.jjtGetChild(0).jjtAccept(this, data);
107     }
108
109     public Object JavaDoc visit(ASTExpression node, Object JavaDoc data) {
110         return node.jjtGetChild(0).jjtAccept(this, data);
111     }
112
113     // ============ Logical operators =============
114
public Object JavaDoc visit(ASTOr node, Object JavaDoc data) {
115         for (int i = 0; i < node.jjtGetNumChildren(); i++) {
116             List JavaDoc args = (List JavaDoc) node.jjtGetChild(i).jjtAccept(this, data);
117             //((List) data).addAll(args);
118
}
119         return data;
120     }
121
122     public Object JavaDoc visit(ASTAnd node, Object JavaDoc data) {
123         for (int i = 0; i < node.jjtGetNumChildren(); i++) {
124             node.jjtGetChild(i).jjtAccept(this, data);
125         }
126         return data;
127     }
128
129     public Object JavaDoc visit(ASTNot node, Object JavaDoc data) {
130         for (int i = 0; i < node.jjtGetNumChildren(); i++) {
131             node.jjtGetChild(i).jjtAccept(this, data);
132         }
133         return data;
134     }
135
136     // ============ Pointcut types =============
137
public Object JavaDoc visit(ASTPointcutReference node, Object JavaDoc data) {
138         // visit the args - if any
139
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
140             node.jjtGetChild(i).jjtAccept(this, data);
141         }
142         return data;
143     }
144
145     public Object JavaDoc visit(ASTExecution node, Object JavaDoc data) {
146         return data;
147     }
148
149     public Object JavaDoc visit(ASTCall node, Object JavaDoc data) {
150         return data;
151     }
152
153     public Object JavaDoc visit(ASTSet node, Object JavaDoc data) {
154         return data;
155     }
156
157     public Object JavaDoc visit(ASTGet node, Object JavaDoc data) {
158         return data;
159     }
160
161     public Object JavaDoc visit(ASTHandler node, Object JavaDoc data) {
162         return data;
163     }
164
165     public Object JavaDoc visit(ASTStaticInitialization node, Object JavaDoc data) {
166         return data;
167     }
168
169     public Object JavaDoc visit(ASTWithin node, Object JavaDoc data) {
170         return data;
171     }
172
173     public Object JavaDoc visit(ASTWithinCode node, Object JavaDoc data) {
174         return data;
175     }
176
177
178     public Object JavaDoc visit(ASTHasMethod node, Object JavaDoc data) {
179         return data;
180     }
181
182     public Object JavaDoc visit(ASTHasField node, Object JavaDoc data) {
183         return data;
184     }
185
186     public Object JavaDoc visit(ASTCflow node, Object JavaDoc data) {
187         // visit the sub expression
188
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
189             node.jjtGetChild(i).jjtAccept(this, data);
190         }
191         return data;
192     }
193
194     public Object JavaDoc visit(ASTCflowBelow node, Object JavaDoc data) {
195         // visit the sub expression
196
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
197             node.jjtGetChild(i).jjtAccept(this, data);
198         }
199         return data;
200     }
201
202     public Object JavaDoc visit(ASTTarget node, Object JavaDoc data) {
203         ((List JavaDoc) data).add(node.getIdentifier());
204         return data;
205     }
206
207     public Object JavaDoc visit(ASTThis node, Object JavaDoc data) {
208         ((List JavaDoc) data).add(node.getIdentifier());
209         return data;
210     }
211
212     // ============ Patterns =============
213
public Object JavaDoc visit(ASTClassPattern node, Object JavaDoc data) {
214         return data;
215     }
216
217     public Object JavaDoc visit(ASTMethodPattern node, Object JavaDoc data) {
218         return data;
219     }
220
221     public Object JavaDoc visit(ASTConstructorPattern node, Object JavaDoc data) {
222         return data;
223     }
224
225     public Object JavaDoc visit(ASTFieldPattern node, Object JavaDoc data) {
226         return data;
227     }
228
229     public Object JavaDoc visit(ASTParameter node, Object JavaDoc data) {
230         return data;
231     }
232
233     public Object JavaDoc visit(ASTArgs node, Object JavaDoc data) {
234         for (int i = 0; i < node.jjtGetNumChildren(); i++) {
235             List JavaDoc args = (List JavaDoc) node.jjtGetChild(i).jjtAccept(this, data);
236             ((List JavaDoc) data).addAll(args);
237         }
238         return data;
239     }
240
241     public Object JavaDoc visit(ASTArgParameter node, Object JavaDoc data) {
242         TypePattern typePattern = node.getTypePattern();
243         ((List JavaDoc) data).add(typePattern.getPattern());
244         return data;
245     }
246
247     public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data) {
248         return data;
249     }
250
251     public Object JavaDoc visit(ASTModifier node, Object JavaDoc data) {
252         return data;
253     }
254
255     /**
256      * Returns the string representation of the expression.
257      *
258      * @return
259      */

260     public String JavaDoc toString() {
261         return m_expression;
262     }
263
264 }
Popular Tags