001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.expression;
005:
006: import java.util.List;
007:
008: import com.tc.aspectwerkz.expression.ast.*;
009: import com.tc.aspectwerkz.expression.regexp.TypePattern;
010:
011: /**
012: * The visitor that extract all possible arguments referenced by the expression.
013: * <p/>
014: * TODO handle pointcut reference and handle parameter transition
015: * + checks as done in the ArgIndexVisitor for this / target compliance.
016: *
017: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur </a>
018: */
019: public class ExpressionValidateVisitor implements
020: ExpressionParserVisitor {
021:
022: protected Node m_root;
023: protected String m_expression;
024: protected String m_namespace;
025:
026: /**
027: * Creates a new expression.
028: *
029: * @param expression the expression as a string
030: * @param namespace the namespace
031: * @param root the AST root
032: */
033: public ExpressionValidateVisitor(final String expression,
034: final String namespace, final Node root) {
035: m_expression = expression;
036: m_namespace = namespace;
037: m_root = root;
038: }
039:
040: /**
041: * Populate data with the possible arguments
042: *
043: * @param data a list to feed with Strings
044: */
045: public void populate(List data) {
046: visit(m_root, data);
047: }
048:
049: // ============ Boot strap =============
050: public Object visit(Node node, Object data) {
051: return node.jjtGetChild(0).jjtAccept(this , data);
052: }
053:
054: public Object visit(SimpleNode node, Object data) {
055: return node.jjtGetChild(0).jjtAccept(this , data);
056: }
057:
058: public Object visit(ASTRoot node, Object data) {
059: return node.jjtGetChild(0).jjtAccept(this , data);
060: }
061:
062: public Object visit(ASTExpression node, Object data) {
063: return node.jjtGetChild(0).jjtAccept(this , data);
064: }
065:
066: // ============ Logical operators =============
067: public Object visit(ASTOr node, Object data) {
068: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
069: List args = (List) node.jjtGetChild(i)
070: .jjtAccept(this , data);
071: //((List) data).addAll(args);
072: }
073: return data;
074: }
075:
076: public Object visit(ASTAnd node, Object data) {
077: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
078: node.jjtGetChild(i).jjtAccept(this , data);
079: }
080: return data;
081: }
082:
083: public Object visit(ASTNot node, Object data) {
084: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
085: node.jjtGetChild(i).jjtAccept(this , data);
086: }
087: return data;
088: }
089:
090: // ============ Pointcut types =============
091: public Object visit(ASTPointcutReference node, Object data) {
092: // visit the args - if any
093: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
094: node.jjtGetChild(i).jjtAccept(this , data);
095: }
096: return data;
097: }
098:
099: public Object visit(ASTExecution node, Object data) {
100: return data;
101: }
102:
103: public Object visit(ASTCall node, Object data) {
104: return data;
105: }
106:
107: public Object visit(ASTSet node, Object data) {
108: return data;
109: }
110:
111: public Object visit(ASTGet node, Object data) {
112: return data;
113: }
114:
115: public Object visit(ASTHandler node, Object data) {
116: return data;
117: }
118:
119: public Object visit(ASTStaticInitialization node, Object data) {
120: return data;
121: }
122:
123: public Object visit(ASTIf node, Object data) {
124: return data;
125: }
126:
127: public Object visit(ASTWithin node, Object data) {
128: return data;
129: }
130:
131: public Object visit(ASTWithinCode node, Object data) {
132: return data;
133: }
134:
135: public Object visit(ASTHasMethod node, Object data) {
136: return data;
137: }
138:
139: public Object visit(ASTHasField node, Object data) {
140: return data;
141: }
142:
143: public Object visit(ASTCflow node, Object 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 visit(ASTCflowBelow node, Object 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 visit(ASTTarget node, Object data) {
160: ((List) data).add(node.getIdentifier());
161: return data;
162: }
163:
164: public Object visit(ASTThis node, Object data) {
165: ((List) data).add(node.getIdentifier());
166: return data;
167: }
168:
169: // ============ Patterns =============
170: public Object visit(ASTClassPattern node, Object data) {
171: return data;
172: }
173:
174: public Object visit(ASTMethodPattern node, Object data) {
175: return data;
176: }
177:
178: public Object visit(ASTConstructorPattern node, Object data) {
179: return data;
180: }
181:
182: public Object visit(ASTFieldPattern node, Object data) {
183: return data;
184: }
185:
186: public Object visit(ASTParameter node, Object data) {
187: return data;
188: }
189:
190: public Object visit(ASTArgs node, Object data) {
191: for (int i = 0; i < node.jjtGetNumChildren(); i++) {
192: List args = (List) node.jjtGetChild(i)
193: .jjtAccept(this , data);
194: ((List) data).addAll(args);
195: }
196: return data;
197: }
198:
199: public Object visit(ASTArgParameter node, Object data) {
200: TypePattern typePattern = node.getTypePattern();
201: ((List) data).add(typePattern.getPattern());
202: return data;
203: }
204:
205: public Object visit(ASTAttribute node, Object data) {
206: return data;
207: }
208:
209: public Object visit(ASTModifier node, Object data) {
210: return data;
211: }
212:
213: /**
214: * Returns the string representation of the expression.
215: *
216: * @return
217: */
218: public String toString() {
219: return m_expression;
220: }
221:
222: }
|