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.annotation.AnnotationInfo;
010: import org.codehaus.aspectwerkz.expression.ast.ASTAnd;
011: import org.codehaus.aspectwerkz.expression.ast.ASTAttribute;
012: import org.codehaus.aspectwerkz.expression.ast.ASTCall;
013: import org.codehaus.aspectwerkz.expression.ast.ASTCflow;
014: import org.codehaus.aspectwerkz.expression.ast.ASTCflowBelow;
015: import org.codehaus.aspectwerkz.expression.ast.ASTClassPattern;
016: import org.codehaus.aspectwerkz.expression.ast.ASTConstructorPattern;
017: import org.codehaus.aspectwerkz.expression.ast.ASTExecution;
018: import org.codehaus.aspectwerkz.expression.ast.ASTExpression;
019: import org.codehaus.aspectwerkz.expression.ast.ASTFieldPattern;
020: import org.codehaus.aspectwerkz.expression.ast.ASTGet;
021: import org.codehaus.aspectwerkz.expression.ast.ASTHandler;
022: import org.codehaus.aspectwerkz.expression.ast.ASTMethodPattern;
023: import org.codehaus.aspectwerkz.expression.ast.ASTModifier;
024: import org.codehaus.aspectwerkz.expression.ast.ASTNot;
025: import org.codehaus.aspectwerkz.expression.ast.ASTOr;
026: import org.codehaus.aspectwerkz.expression.ast.ASTParameter;
027: import org.codehaus.aspectwerkz.expression.ast.ASTPointcutReference;
028: import org.codehaus.aspectwerkz.expression.ast.ASTRoot;
029: import org.codehaus.aspectwerkz.expression.ast.ASTSet;
030: import org.codehaus.aspectwerkz.expression.ast.ASTStaticInitialization;
031: import org.codehaus.aspectwerkz.expression.ast.ASTWithin;
032: import org.codehaus.aspectwerkz.expression.ast.ASTWithinCode;
033: import org.codehaus.aspectwerkz.expression.ast.ExpressionParserVisitor;
034: import org.codehaus.aspectwerkz.expression.ast.Node;
035: import org.codehaus.aspectwerkz.expression.ast.SimpleNode;
036: import org.codehaus.aspectwerkz.expression.ast.ASTArgs;
037: import org.codehaus.aspectwerkz.expression.ast.ASTArgParameter;
038: import org.codehaus.aspectwerkz.expression.regexp.TypePattern;
039: import org.codehaus.aspectwerkz.reflect.ClassInfo;
040: import org.codehaus.aspectwerkz.reflect.ConstructorInfo;
041: import org.codehaus.aspectwerkz.reflect.FieldInfo;
042: import org.codehaus.aspectwerkz.reflect.MemberInfo;
043: import org.codehaus.aspectwerkz.reflect.MethodInfo;
044: import org.codehaus.aspectwerkz.reflect.ReflectionInfo;
045:
046: import java.lang.reflect.Modifier;
047: import java.util.ArrayList;
048: import java.util.Iterator;
049: import java.util.List;
050:
051: import org.codehaus.aspectwerkz.expression.ast.ASTHasField;
052: import org.codehaus.aspectwerkz.expression.ast.ASTHasMethod;
053: import org.codehaus.aspectwerkz.expression.ast.ASTTarget;
054: import org.codehaus.aspectwerkz.expression.ast.ASTThis;
055: import org.codehaus.aspectwerkz.util.Strings;
056:
057: /**
058: * The visitor that extract all possible arguments referenced by the expression.
059: * <p/>
060: * TODO handle pointcut reference and handle parameter transition
061: * + checks as done in the ArgIndexVisitor for this / target compliance.
062: *
063: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur </a>
064: */
065: public class ExpressionValidateVisitor implements
066: ExpressionParserVisitor {
067:
068: protected Node m_root;
069: protected String m_expression;
070: protected String m_namespace;
071:
072: /**
073: * Creates a new expression.
074: *
075: * @param expression the expression as a string
076: * @param namespace the namespace
077: * @param root the AST root
078: */
079: public ExpressionValidateVisitor(final String expression,
080: final String namespace, final Node root) {
081: m_expression = expression;
082: m_namespace = namespace;
083: m_root = root;
084: }
085:
086: /**
087: * Populate data with the possible arguments
088: *
089: * @param data a list to feed with Strings
090: */
091: public void populate(List data) {
092: visit(m_root, data);
093: }
094:
095: // ============ Boot strap =============
096: public Object visit(Node node, Object data) {
097: return node.jjtGetChild(0).jjtAccept(this , data);
098: }
099:
100: public Object visit(SimpleNode node, Object data) {
101: return node.jjtGetChild(0).jjtAccept(this , data);
102: }
103:
104: public Object visit(ASTRoot node, Object data) {
105: return node.jjtGetChild(0).jjtAccept(this , data);
106: }
107:
108: public Object visit(ASTExpression node, Object data) {
109: return node.jjtGetChild(0).jjtAccept(this , data);
110: }
111:
112: // ============ Logical operators =============
113: public Object visit(ASTOr node, Object data) {
114: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
115: List args = (List) node.jjtGetChild(i)
116: .jjtAccept(this , data);
117: //((List) data).addAll(args);
118: }
119: return data;
120: }
121:
122: public Object visit(ASTAnd node, Object 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 visit(ASTNot node, Object 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 visit(ASTPointcutReference node, Object 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 visit(ASTExecution node, Object data) {
146: return data;
147: }
148:
149: public Object visit(ASTCall node, Object data) {
150: return data;
151: }
152:
153: public Object visit(ASTSet node, Object data) {
154: return data;
155: }
156:
157: public Object visit(ASTGet node, Object data) {
158: return data;
159: }
160:
161: public Object visit(ASTHandler node, Object data) {
162: return data;
163: }
164:
165: public Object visit(ASTStaticInitialization node, Object data) {
166: return data;
167: }
168:
169: public Object visit(ASTWithin node, Object data) {
170: return data;
171: }
172:
173: public Object visit(ASTWithinCode node, Object data) {
174: return data;
175: }
176:
177: public Object visit(ASTHasMethod node, Object data) {
178: return data;
179: }
180:
181: public Object visit(ASTHasField node, Object data) {
182: return data;
183: }
184:
185: public Object visit(ASTCflow node, Object data) {
186: // visit the sub expression
187: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
188: node.jjtGetChild(i).jjtAccept(this , data);
189: }
190: return data;
191: }
192:
193: public Object visit(ASTCflowBelow node, Object data) {
194: // visit the sub expression
195: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
196: node.jjtGetChild(i).jjtAccept(this , data);
197: }
198: return data;
199: }
200:
201: public Object visit(ASTTarget node, Object data) {
202: ((List) data).add(node.getIdentifier());
203: return data;
204: }
205:
206: public Object visit(ASTThis node, Object data) {
207: ((List) data).add(node.getIdentifier());
208: return data;
209: }
210:
211: // ============ Patterns =============
212: public Object visit(ASTClassPattern node, Object data) {
213: return data;
214: }
215:
216: public Object visit(ASTMethodPattern node, Object data) {
217: return data;
218: }
219:
220: public Object visit(ASTConstructorPattern node, Object data) {
221: return data;
222: }
223:
224: public Object visit(ASTFieldPattern node, Object data) {
225: return data;
226: }
227:
228: public Object visit(ASTParameter node, Object data) {
229: return data;
230: }
231:
232: public Object visit(ASTArgs node, Object data) {
233: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
234: List args = (List) node.jjtGetChild(i)
235: .jjtAccept(this , data);
236: ((List) data).addAll(args);
237: }
238: return data;
239: }
240:
241: public Object visit(ASTArgParameter node, Object data) {
242: TypePattern typePattern = node.getTypePattern();
243: ((List) data).add(typePattern.getPattern());
244: return data;
245: }
246:
247: public Object visit(ASTAttribute node, Object data) {
248: return data;
249: }
250:
251: public Object visit(ASTModifier node, Object data) {
252: return data;
253: }
254:
255: /**
256: * Returns the string representation of the expression.
257: *
258: * @return
259: */
260: public String toString() {
261: return m_expression;
262: }
263:
264: }
|