PageRenderTime 68ms CodeModel.GetById 36ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/sidekick/ecmascript/parser/EcmaScriptVisitorAdapter.java

#
Java | 351 lines | 262 code | 68 blank | 21 comment | 10 complexity | c9e36859605cc654264c67ee15eabb87 MD5 | raw file
  1/*
  2 Copyright (c) 2004-2005, The Dojo Foundation
  3 All Rights Reserved.
  4
  5 Licensed under the Academic Free License version 2.1 or above OR the
  6 modified BSD license. For more information on Dojo licensing, see:
  7
  8 http://dojotoolkit.org/community/licensing.shtml <http://dojotoolkit.org/community/licensing.shtml>
  9
 10 Code donated to the Dojo Foundation by AOL LLC under the terms of
 11 the Dojo CCLA (http://dojotoolkit.org/ccla.txt).
 12
 13 */
 14package sidekick.ecmascript.parser;
 15
 16import java.util.*;
 17
 18import sidekick.ecmascript.parser.ASTAllocationExpression;
 19import sidekick.ecmascript.parser.ASTAndExpressionSequence;
 20import sidekick.ecmascript.parser.ASTArrayLiteral;
 21import sidekick.ecmascript.parser.ASTAssignmentExpression;
 22import sidekick.ecmascript.parser.ASTBinaryExpressionSequence;
 23import sidekick.ecmascript.parser.ASTBreakStatement;
 24import sidekick.ecmascript.parser.ASTCaseGroup;
 25import sidekick.ecmascript.parser.ASTCaseGroups;
 26import sidekick.ecmascript.parser.ASTCaseGuard;
 27import sidekick.ecmascript.parser.ASTCatchClause;
 28import sidekick.ecmascript.parser.ASTConditionalExpression;
 29import sidekick.ecmascript.parser.ASTContinueStatement;
 30import sidekick.ecmascript.parser.ASTDoStatement;
 31import sidekick.ecmascript.parser.ASTEmptyExpression;
 32import sidekick.ecmascript.parser.ASTEmptyStatement;
 33import sidekick.ecmascript.parser.ASTExpressionList;
 34import sidekick.ecmascript.parser.ASTExpressionStatement;
 35import sidekick.ecmascript.parser.ASTFinallyClause;
 36import sidekick.ecmascript.parser.ASTForInStatement;
 37import sidekick.ecmascript.parser.ASTForStatement;
 38import sidekick.ecmascript.parser.ASTForVarInStatement;
 39import sidekick.ecmascript.parser.ASTForVarStatement;
 40import sidekick.ecmascript.parser.ASTFormalParameterList;
 41import sidekick.ecmascript.parser.ASTFunctionCallParameters;
 42import sidekick.ecmascript.parser.ASTFunctionExpression;
 43import sidekick.ecmascript.parser.ASTIfStatement;
 44import sidekick.ecmascript.parser.ASTLiteralField;
 45import sidekick.ecmascript.parser.ASTObjectLiteral;
 46import sidekick.ecmascript.parser.ASTOrExpressionSequence;
 47import sidekick.ecmascript.parser.ASTParenExpression;
 48import sidekick.ecmascript.parser.ASTPostfixExpression;
 49import sidekick.ecmascript.parser.ASTPropertyIdentifierReference;
 50import sidekick.ecmascript.parser.ASTPropertyValueReference;
 51import sidekick.ecmascript.parser.ASTReturnStatement;
 52import sidekick.ecmascript.parser.ASTStatementList;
 53import sidekick.ecmascript.parser.ASTSwitchStatement;
 54import sidekick.ecmascript.parser.ASTThisReference;
 55import sidekick.ecmascript.parser.ASTThrowStatement;
 56import sidekick.ecmascript.parser.ASTTryStatement;
 57import sidekick.ecmascript.parser.ASTUnaryExpression;
 58import sidekick.ecmascript.parser.ASTVariableDeclaration;
 59import sidekick.ecmascript.parser.ASTVariableDeclarationList;
 60import sidekick.ecmascript.parser.ASTVariableStatement;
 61import sidekick.ecmascript.parser.ASTWhileStatement;
 62import sidekick.ecmascript.parser.ASTWithStatement;
 63import sidekick.ecmascript.parser.EcmaScriptVisitor;
 64
 65public class EcmaScriptVisitorAdapter extends Object implements
 66        EcmaScriptVisitor {
 67
 68    protected LinkedList scopes;
 69
 70    protected ASTFunctionDeclaration enteringFunction;
 71
 72    protected EcmaScriptVisitorDelegate delegate;
 73
 74    protected EcmaScriptVisitorAdapter() {
 75        this(null);
 76    }
 77
 78    public EcmaScriptVisitorAdapter(EcmaScriptVisitorDelegate delegate) {
 79        super();
 80        this.delegate = delegate;
 81        scopes = new LinkedList();
 82    }
 83
 84    public SimpleNode getScope() {
 85        return scopes.size() == 0 ? null : (SimpleNode) scopes.getLast();
 86    }
 87
 88    protected void pre(SimpleNode node, Object data) {
 89        if (delegate != null) {
 90            delegate.willVisit(node, data);
 91        }
 92    }
 93
 94    protected void post(SimpleNode node, Object data) {
 95        if (delegate != null) {
 96            delegate.didVisit(node, data);
 97        }
 98    }
 99
100    protected Object visitImpl(SimpleNode node, Object data) {
101        pre(node, data);
102        data = node.childrenAccept(this, data);
103        post(node, data);
104        return data;
105    }
106
107    public Object visit(SimpleNode node, Object data) {
108        return visitImpl(node, data);
109    }
110
111    public Object visit(ASTLiteral node, Object data) {
112        return visitImpl(node, data);
113    }
114
115    public Object visit(ASTIdentifier node, Object data) {
116        return visitImpl(node, data);
117    }
118
119    public Object visit(ASTObjectLiteral node, Object data) {
120        return visitImpl(node, data);
121    }
122
123    public Object visit(ASTLiteralField node, Object data) {
124        return visitImpl(node, data);
125    }
126
127    public Object visit(ASTArrayLiteral node, Object data) {
128        return visitImpl(node, data);
129    }
130
131    public Object visit(ASTThisReference node, Object data) {
132        return visitImpl(node, data);
133    }
134
135    public Object visit(ASTCompositeReference node, Object data) {
136        return visitImpl(node, data);
137    }
138
139    public Object visit(ASTFunctionCallParameters node, Object data) {
140        return visitImpl(node, data);
141    }
142
143    public Object visit(ASTFunctionExpression node, Object data) {
144        return visitImpl(node, data);
145    }
146
147    public Object visit(ASTPropertyValueReference node, Object data) {
148        return visitImpl(node, data);
149    }
150
151    public Object visit(ASTPropertyIdentifierReference node, Object data) {
152        return visitImpl(node, data);
153    }
154
155    public Object visit(ASTAllocationExpression node, Object data) {
156        return visitImpl(node, data);
157    }
158
159    public Object visit(ASTParenExpression node, Object data) {
160        return visitImpl(node, data);
161    }
162
163    public Object visit(ASTOperator node, Object data) {
164        return visitImpl(node, data);
165    }
166
167    public Object visit(ASTPostfixExpression node, Object data) {
168        return visitImpl(node, data);
169    }
170
171    public Object visit(ASTUnaryExpression node, Object data) {
172        return visitImpl(node, data);
173    }
174
175    public Object visit(ASTBinaryExpressionSequence node, Object data) {
176        return visitImpl(node, data);
177    }
178
179    public Object visit(ASTAndExpressionSequence node, Object data) {
180        return visitImpl(node, data);
181    }
182
183    public Object visit(ASTOrExpressionSequence node, Object data) {
184        return visitImpl(node, data);
185    }
186
187    public Object visit(ASTConditionalExpression node, Object data) {
188        return visitImpl(node, data);
189    }
190
191    public Object visit(ASTAssignmentExpression node, Object data) {
192        return visitImpl(node, data);
193    }
194
195    public Object visit(ASTExpressionList node, Object data) {
196        return visitImpl(node, data);
197    }
198
199    public Object visit(ASTStatementList node, Object data) {
200        return visitImpl(node, data);
201    }
202
203    public Object visit(ASTVariableDeclaration node, Object data) {
204        return visitImpl(node, data);
205    }
206
207    public Object visit(ASTExpressionStatement node, Object data) {
208        return visitImpl(node, data);
209    }
210
211    public Object visit(ASTIfStatement node, Object data) {
212        return visitImpl(node, data);
213    }
214
215    public Object visit(ASTWhileStatement node, Object data) {
216        return visitImpl(node, data);
217    }
218
219    public Object visit(ASTForStatement node, Object data) {
220        return visitImpl(node, data);
221    }
222
223    public Object visit(ASTEmptyExpression node, Object data) {
224        return visitImpl(node, data);
225    }
226
227    public Object visit(ASTForVarStatement node, Object data) {
228        return visitImpl(node, data);
229    }
230
231    public Object visit(ASTForInStatement node, Object data) {
232        return visitImpl(node, data);
233    }
234
235    public Object visit(ASTForVarInStatement node, Object data) {
236        return visitImpl(node, data);
237    }
238
239    public Object visit(ASTContinueStatement node, Object data) {
240        return visitImpl(node, data);
241    }
242
243    /*
244     * public Object visit(ASTDebuggerStatement node, Object data) { return
245     * visitImpl(node, data); }
246     */
247
248    public Object visit(ASTBreakStatement node, Object data) {
249        return visitImpl(node, data);
250    }
251
252    public Object visit(ASTReturnStatement node, Object data) {
253        return visitImpl(node, data);
254    }
255
256    public Object visit(ASTWithStatement node, Object data) {
257        return visitImpl(node, data);
258    }
259
260    public Object visit(ASTFunctionDeclaration node, Object data) {
261        pre(node, data);
262        enteringFunction = node;
263        data = node.childrenAccept(this, data);
264        post(node, data);
265        return data;
266    }
267
268    public Object visit(ASTFormalParameterList node, Object data) {
269        return visitImpl(node, data);
270    }
271
272    /*
273     * public Object visit(ASTActiveXReference node, Object data) { return
274     * visitImpl(node, data); }
275     */
276
277    public Object visit(ASTBlock node, Object data) {
278        boolean addedScope = false;
279        if ((enteringFunction != null)
280                && (node.jjtGetParent() == enteringFunction)) {
281            scopes.add(node);
282            addedScope = true;
283            enteringFunction = null;
284        }
285        pre(node, data);
286        data = node.childrenAccept(this, data);
287        post(node, data);
288        if (addedScope) {
289            scopes.removeLast();
290        }
291        return data;
292    }
293
294    public Object visit(ASTSwitchStatement node, Object data) {
295        return visitImpl(node, data);
296    }
297
298    public Object visit(ASTCaseGroups node, Object data) {
299        return visitImpl(node, data);
300    }
301
302    public Object visit(ASTCaseGroup node, Object data) {
303        return visitImpl(node, data);
304    }
305
306    public Object visit(ASTCaseGuard node, Object data) {
307        return visitImpl(node, data);
308    }
309
310    public Object visit(ASTTryStatement node, Object data) {
311        return visitImpl(node, data);
312    }
313
314    public Object visit(ASTCatchClause node, Object data) {
315        return visitImpl(node, data);
316    }
317
318    public Object visit(ASTFinallyClause node, Object data) {
319        return visitImpl(node, data);
320    }
321
322    public Object visit(ASTThrowStatement node, Object data) {
323        return visitImpl(node, data);
324    }
325
326    public Object visit(ASTDoStatement node, Object data) {
327        return visitImpl(node, data);
328    }
329
330    public Object visit(ASTVariableStatement node, Object data) {
331        return visitImpl(node, data);
332    }
333
334    public Object visit(ASTVariableDeclarationList node, Object data) {
335        return visitImpl(node, data);
336    }
337
338    public Object visit(ASTEmptyStatement node, Object data) {
339        return visitImpl(node, data);
340    }
341
342    public Object visit(ASTProgram node, Object data) {
343        scopes.add(node);
344        pre(node, data);
345        data = node.childrenAccept(this, data);
346        post(node, data);
347        scopes.removeLast();
348        return data;
349    }
350
351}