001: /*
002: * Janino - An embedded Java[TM] compiler
003: *
004: * Copyright (c) 2006, Arno Unkrig
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above
014: * copyright notice, this list of conditions and the following
015: * disclaimer in the documentation and/or other materials
016: * provided with the distribution.
017: * 3. The name of the author may not be used to endorse or promote
018: * products derived from this software without specific prior
019: * written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
022: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
023: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
025: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
026: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
027: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
029: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
030: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
031: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032: */
033:
034: package org.codehaus.janino.util;
035:
036: import org.codehaus.janino.*;
037:
038: import java.util.*;
039:
040: /**
041: * This class traverses the subnodes of an AST. Derived classes may override
042: * individual methods to process specific nodes, e.g.:<pre>
043: * class MethodCounter extends Traverser {
044: * int n = 0;
045: * public void traverseMethodDeclarator(Java.MethodDeclarator md) {
046: * ++this.n;
047: * super.traverseMethodDeclarator(md);
048: * }
049: * }</pre>
050: */
051: public class Traverser {
052: public final Visitor.ComprehensiveVisitor cv = new Visitor.ComprehensiveVisitor() {
053: public final void visitSingleTypeImportDeclaration(
054: Java.CompilationUnit.SingleTypeImportDeclaration stid) {
055: Traverser.this .traverseSingleTypeImportDeclaration(stid);
056: }
057:
058: public final void visitTypeImportOnDemandDeclaration(
059: Java.CompilationUnit.TypeImportOnDemandDeclaration tiodd) {
060: Traverser.this .traverseTypeImportOnDemandDeclaration(tiodd);
061: }
062:
063: public final void visitAnonymousClassDeclaration(
064: Java.AnonymousClassDeclaration acd) {
065: Traverser.this .traverseAnonymousClassDeclaration(acd);
066: }
067:
068: public final void visitLocalClassDeclaration(
069: Java.LocalClassDeclaration lcd) {
070: Traverser.this .traverseLocalClassDeclaration(lcd);
071: }
072:
073: public final void visitPackageMemberClassDeclaration(
074: Java.PackageMemberClassDeclaration pmcd) {
075: Traverser.this .traversePackageMemberClassDeclaration(pmcd);
076: }
077:
078: public final void visitMemberInterfaceDeclaration(
079: Java.MemberInterfaceDeclaration mid) {
080: Traverser.this .traverseMemberInterfaceDeclaration(mid);
081: }
082:
083: public final void visitPackageMemberInterfaceDeclaration(
084: Java.PackageMemberInterfaceDeclaration pmid) {
085: Traverser.this
086: .traversePackageMemberInterfaceDeclaration(pmid);
087: }
088:
089: public final void visitMemberClassDeclaration(
090: Java.MemberClassDeclaration mcd) {
091: Traverser.this .traverseMemberClassDeclaration(mcd);
092: }
093:
094: public final void visitConstructorDeclarator(
095: Java.ConstructorDeclarator cd) {
096: Traverser.this .traverseConstructorDeclarator(cd);
097: }
098:
099: public final void visitInitializer(Java.Initializer i) {
100: Traverser.this .traverseInitializer(i);
101: }
102:
103: public final void visitMethodDeclarator(Java.MethodDeclarator md) {
104: Traverser.this .traverseMethodDeclarator(md);
105: }
106:
107: public final void visitFieldDeclaration(Java.FieldDeclaration fd) {
108: Traverser.this .traverseFieldDeclaration(fd);
109: }
110:
111: public final void visitLabeledStatement(Java.LabeledStatement ls) {
112: Traverser.this .traverseLabeledStatement(ls);
113: }
114:
115: public final void visitBlock(Java.Block b) {
116: Traverser.this .traverseBlock(b);
117: }
118:
119: public final void visitExpressionStatement(
120: Java.ExpressionStatement es) {
121: Traverser.this .traverseExpressionStatement(es);
122: }
123:
124: public final void visitIfStatement(Java.IfStatement is) {
125: Traverser.this .traverseIfStatement(is);
126: }
127:
128: public final void visitForStatement(Java.ForStatement fs) {
129: Traverser.this .traverseForStatement(fs);
130: }
131:
132: public final void visitWhileStatement(Java.WhileStatement ws) {
133: Traverser.this .traverseWhileStatement(ws);
134: }
135:
136: public final void visitTryStatement(Java.TryStatement ts) {
137: Traverser.this .traverseTryStatement(ts);
138: }
139:
140: public final void visitSwitchStatement(Java.SwitchStatement ss) {
141: Traverser.this .traverseSwitchStatement(ss);
142: }
143:
144: public final void visitSynchronizedStatement(
145: Java.SynchronizedStatement ss) {
146: Traverser.this .traverseSynchronizedStatement(ss);
147: }
148:
149: public final void visitDoStatement(Java.DoStatement ds) {
150: Traverser.this .traverseDoStatement(ds);
151: }
152:
153: public final void visitLocalVariableDeclarationStatement(
154: Java.LocalVariableDeclarationStatement lvds) {
155: Traverser.this
156: .traverseLocalVariableDeclarationStatement(lvds);
157: }
158:
159: public final void visitReturnStatement(Java.ReturnStatement rs) {
160: Traverser.this .traverseReturnStatement(rs);
161: }
162:
163: public final void visitThrowStatement(Java.ThrowStatement ts) {
164: Traverser.this .traverseThrowStatement(ts);
165: }
166:
167: public final void visitBreakStatement(Java.BreakStatement bs) {
168: Traverser.this .traverseBreakStatement(bs);
169: }
170:
171: public final void visitContinueStatement(
172: Java.ContinueStatement cs) {
173: Traverser.this .traverseContinueStatement(cs);
174: }
175:
176: public final void visitEmptyStatement(Java.EmptyStatement es) {
177: Traverser.this .traverseEmptyStatement(es);
178: }
179:
180: public final void visitLocalClassDeclarationStatement(
181: Java.LocalClassDeclarationStatement lcds) {
182: Traverser.this .traverseLocalClassDeclarationStatement(lcds);
183: }
184:
185: public final void visitPackage(Java.Package p) {
186: Traverser.this .traversePackage(p);
187: }
188:
189: public final void visitArrayLength(Java.ArrayLength al) {
190: Traverser.this .traverseArrayLength(al);
191: }
192:
193: public final void visitAssignment(Java.Assignment a) {
194: Traverser.this .traverseAssignment(a);
195: }
196:
197: public final void visitUnaryOperation(Java.UnaryOperation uo) {
198: Traverser.this .traverseUnaryOperation(uo);
199: }
200:
201: public final void visitBinaryOperation(Java.BinaryOperation bo) {
202: Traverser.this .traverseBinaryOperation(bo);
203: }
204:
205: public final void visitCast(Java.Cast c) {
206: Traverser.this .traverseCast(c);
207: }
208:
209: public final void visitClassLiteral(Java.ClassLiteral cl) {
210: Traverser.this .traverseClassLiteral(cl);
211: }
212:
213: public final void visitConditionalExpression(
214: Java.ConditionalExpression ce) {
215: Traverser.this .traverseConditionalExpression(ce);
216: }
217:
218: public final void visitConstantValue(Java.ConstantValue cv) {
219: Traverser.this .traverseConstantValue(cv);
220: }
221:
222: public final void visitCrement(Java.Crement c) {
223: Traverser.this .traverseCrement(c);
224: }
225:
226: public final void visitInstanceof(Java.Instanceof io) {
227: Traverser.this .traverseInstanceof(io);
228: }
229:
230: public final void visitMethodInvocation(Java.MethodInvocation mi) {
231: Traverser.this .traverseMethodInvocation(mi);
232: }
233:
234: public final void visitSuperclassMethodInvocation(
235: Java.SuperclassMethodInvocation smi) {
236: Traverser.this .traverseSuperclassMethodInvocation(smi);
237: }
238:
239: public final void visitLiteral(Java.Literal l) {
240: Traverser.this .traverseLiteral(l);
241: }
242:
243: public final void visitNewAnonymousClassInstance(
244: Java.NewAnonymousClassInstance naci) {
245: Traverser.this .traverseNewAnonymousClassInstance(naci);
246: }
247:
248: public final void visitNewArray(Java.NewArray na) {
249: Traverser.this .traverseNewArray(na);
250: }
251:
252: public final void visitNewInitializedArray(
253: Java.NewInitializedArray nia) {
254: Traverser.this .traverseNewInitializedArray(nia);
255: }
256:
257: public final void visitNewClassInstance(
258: Java.NewClassInstance nci) {
259: Traverser.this .traverseNewClassInstance(nci);
260: }
261:
262: public final void visitParameterAccess(Java.ParameterAccess pa) {
263: Traverser.this .traverseParameterAccess(pa);
264: }
265:
266: public final void visitQualifiedThisReference(
267: Java.QualifiedThisReference qtr) {
268: Traverser.this .traverseQualifiedThisReference(qtr);
269: }
270:
271: public final void visitThisReference(Java.ThisReference tr) {
272: Traverser.this .traverseThisReference(tr);
273: }
274:
275: public final void visitArrayType(Java.ArrayType at) {
276: Traverser.this .traverseArrayType(at);
277: }
278:
279: public final void visitBasicType(Java.BasicType bt) {
280: Traverser.this .traverseBasicType(bt);
281: }
282:
283: public final void visitReferenceType(Java.ReferenceType rt) {
284: Traverser.this .traverseReferenceType(rt);
285: }
286:
287: public final void visitRvalueMemberType(
288: Java.RvalueMemberType rmt) {
289: Traverser.this .traverseRvalueMemberType(rmt);
290: }
291:
292: public final void visitSimpleType(Java.SimpleType st) {
293: Traverser.this .traverseSimpleType(st);
294: }
295:
296: public final void visitAlternateConstructorInvocation(
297: Java.AlternateConstructorInvocation aci) {
298: Traverser.this .traverseAlternateConstructorInvocation(aci);
299: }
300:
301: public final void visitSuperConstructorInvocation(
302: Java.SuperConstructorInvocation sci) {
303: Traverser.this .traverseSuperConstructorInvocation(sci);
304: }
305:
306: public final void visitAmbiguousName(Java.AmbiguousName an) {
307: Traverser.this .traverseAmbiguousName(an);
308: }
309:
310: public final void visitArrayAccessExpression(
311: Java.ArrayAccessExpression aae) {
312: Traverser.this .traverseArrayAccessExpression(aae);
313: }
314:
315: public final void visitFieldAccess(Java.FieldAccess fa) {
316: Traverser.this .traverseFieldAccess(fa);
317: }
318:
319: public final void visitFieldAccessExpression(
320: Java.FieldAccessExpression fae) {
321: Traverser.this .traverseFieldAccessExpression(fae);
322: }
323:
324: public final void visitLocalVariableAccess(
325: Java.LocalVariableAccess lva) {
326: Traverser.this .traverseLocalVariableAccess(lva);
327: }
328:
329: public final void visitParenthesizedExpression(
330: Java.ParenthesizedExpression pe) {
331: Traverser.this .traverseParenthesizedExpression(pe);
332: }
333: };
334:
335: // These may be overridden by derived classes.
336:
337: public void traverseCompilationUnit(Java.CompilationUnit cu) {
338:
339: // The optionalPackageDeclaration is considered an integral part of
340: // the compilation unit and is thus not traversed.
341:
342: for (Iterator it = cu.importDeclarations.iterator(); it
343: .hasNext();) {
344: ((Java.CompilationUnit.ImportDeclaration) it.next())
345: .accept(this .cv);
346: }
347: for (Iterator it = cu.packageMemberTypeDeclarations.iterator(); it
348: .hasNext();) {
349: ((Java.PackageMemberTypeDeclaration) it.next())
350: .accept(this .cv);
351: }
352: }
353:
354: public void traverseSingleTypeImportDeclaration(
355: Java.CompilationUnit.SingleTypeImportDeclaration stid) {
356: this .traverseImportDeclaration(stid);
357: }
358:
359: public void traverseTypeImportOnDemandDeclaration(
360: Java.CompilationUnit.TypeImportOnDemandDeclaration tiodd) {
361: this .traverseImportDeclaration(tiodd);
362: }
363:
364: public void traverseImportDeclaration(
365: Java.CompilationUnit.ImportDeclaration id) {
366: this .traverseLocated(id);
367: }
368:
369: public void traverseAnonymousClassDeclaration(
370: Java.AnonymousClassDeclaration acd) {
371: acd.baseType.accept((Visitor.TypeVisitor) this .cv);
372: this .traverseClassDeclaration(acd);
373: }
374:
375: public void traverseLocalClassDeclaration(
376: Java.LocalClassDeclaration lcd) {
377: this .traverseNamedClassDeclaration(lcd);
378: }
379:
380: public void traversePackageMemberClassDeclaration(
381: Java.PackageMemberClassDeclaration pmcd) {
382: this .traverseNamedClassDeclaration(pmcd);
383: }
384:
385: public void traverseMemberInterfaceDeclaration(
386: Java.MemberInterfaceDeclaration mid) {
387: this .traverseInterfaceDeclaration(mid);
388: }
389:
390: public void traversePackageMemberInterfaceDeclaration(
391: Java.PackageMemberInterfaceDeclaration pmid) {
392: this .traverseInterfaceDeclaration(pmid);
393: }
394:
395: public void traverseMemberClassDeclaration(
396: Java.MemberClassDeclaration mcd) {
397: this .traverseNamedClassDeclaration(mcd);
398: }
399:
400: public void traverseConstructorDeclarator(
401: Java.ConstructorDeclarator cd) {
402: if (cd.optionalConstructorInvocation != null)
403: cd.optionalConstructorInvocation
404: .accept((Visitor.BlockStatementVisitor) this .cv);
405: this .traverseFunctionDeclarator(cd);
406: }
407:
408: public void traverseInitializer(Java.Initializer i) {
409: i.block.accept(this .cv);
410: this .traverseAbstractTypeBodyDeclaration(i);
411: }
412:
413: public void traverseMethodDeclarator(Java.MethodDeclarator md) {
414: this .traverseFunctionDeclarator(md);
415: }
416:
417: public void traverseFieldDeclaration(Java.FieldDeclaration fd) {
418: fd.type.accept((Visitor.TypeVisitor) this .cv);
419: for (int i = 0; i < fd.variableDeclarators.length; ++i) {
420: Java.ArrayInitializerOrRvalue optionalInitializer = fd.variableDeclarators[i].optionalInitializer;
421: if (optionalInitializer != null)
422: this
423: .traverseArrayInitializerOrRvalue(optionalInitializer);
424: }
425: this .traverseStatement(fd);
426: }
427:
428: public void traverseLabeledStatement(Java.LabeledStatement ls) {
429: ls.body.accept(this .cv);
430: this .traverseBreakableStatement(ls);
431: }
432:
433: public void traverseBlock(Java.Block b) {
434: for (Iterator it = b.statements.iterator(); it.hasNext();) {
435: ((Java.Statement) it.next()).accept(this .cv);
436: }
437: this .traverseStatement(b);
438: }
439:
440: public void traverseExpressionStatement(Java.ExpressionStatement es) {
441: es.rvalue.accept((Visitor.RvalueVisitor) this .cv);
442: this .traverseStatement(es);
443: }
444:
445: public void traverseIfStatement(Java.IfStatement is) {
446: is.condition.accept((Visitor.RvalueVisitor) this .cv);
447: is.thenStatement.accept(this .cv);
448: if (is.optionalElseStatement != null)
449: is.optionalElseStatement.accept(this .cv);
450: this .traverseStatement(is);
451: }
452:
453: public void traverseForStatement(Java.ForStatement fs) {
454: if (fs.optionalInit != null)
455: fs.optionalInit.accept(this .cv);
456: if (fs.optionalCondition != null)
457: fs.optionalCondition
458: .accept((Visitor.RvalueVisitor) this .cv);
459: if (fs.optionalUpdate != null) {
460: for (int i = 0; i < fs.optionalUpdate.length; ++i)
461: fs.optionalUpdate[i]
462: .accept((Visitor.RvalueVisitor) this .cv);
463: }
464: fs.body.accept(this .cv);
465: this .traverseContinuableStatement(fs);
466: }
467:
468: public void traverseWhileStatement(Java.WhileStatement ws) {
469: ws.condition.accept((Visitor.RvalueVisitor) this .cv);
470: ws.body.accept(this .cv);
471: this .traverseContinuableStatement(ws);
472: }
473:
474: public void traverseTryStatement(Java.TryStatement ts) {
475: ts.body.accept(this .cv);
476: for (Iterator it = ts.catchClauses.iterator(); it.hasNext();) {
477: ((Java.CatchClause) it.next()).body.accept(this .cv);
478: }
479: if (ts.optionalFinally != null)
480: ts.optionalFinally.accept(this .cv);
481: this .traverseStatement(ts);
482: }
483:
484: public void traverseSwitchStatement(Java.SwitchStatement ss) {
485: ss.condition.accept((Visitor.RvalueVisitor) this .cv);
486: for (Iterator it = ss.sbsgs.iterator(); it.hasNext();) {
487: Java.SwitchStatement.SwitchBlockStatementGroup sbsg = (Java.SwitchStatement.SwitchBlockStatementGroup) it
488: .next();
489: for (Iterator it2 = sbsg.caseLabels.iterator(); it2
490: .hasNext();) {
491: ((Java.Rvalue) it2.next())
492: .accept((Visitor.RvalueVisitor) this .cv);
493: }
494: for (Iterator it2 = sbsg.blockStatements.iterator(); it2
495: .hasNext();) {
496: ((Java.BlockStatement) it2.next()).accept(this .cv);
497: }
498: this .traverseLocated(sbsg);
499: }
500: this .traverseBreakableStatement(ss);
501: }
502:
503: public void traverseSynchronizedStatement(
504: Java.SynchronizedStatement ss) {
505: ss.expression.accept((Visitor.RvalueVisitor) this .cv);
506: ss.body.accept(this .cv);
507: this .traverseStatement(ss);
508: }
509:
510: public void traverseDoStatement(Java.DoStatement ds) {
511: ds.body.accept(this .cv);
512: ds.condition.accept((Visitor.RvalueVisitor) this .cv);
513: this .traverseContinuableStatement(ds);
514: }
515:
516: public void traverseLocalVariableDeclarationStatement(
517: Java.LocalVariableDeclarationStatement lvds) {
518: lvds.type.accept((Visitor.TypeVisitor) this .cv);
519: for (int i = 0; i < lvds.variableDeclarators.length; ++i) {
520: Java.ArrayInitializerOrRvalue optionalInitializer = lvds.variableDeclarators[i].optionalInitializer;
521: if (optionalInitializer != null)
522: this
523: .traverseArrayInitializerOrRvalue(optionalInitializer);
524: }
525: this .traverseStatement(lvds);
526: }
527:
528: public void traverseReturnStatement(Java.ReturnStatement rs) {
529: if (rs.optionalReturnValue != null)
530: rs.optionalReturnValue
531: .accept((Visitor.RvalueVisitor) this .cv);
532: this .traverseStatement(rs);
533: }
534:
535: public void traverseThrowStatement(Java.ThrowStatement ts) {
536: ts.expression.accept((Visitor.RvalueVisitor) this .cv);
537: this .traverseStatement(ts);
538: }
539:
540: public void traverseBreakStatement(Java.BreakStatement bs) {
541: this .traverseStatement(bs);
542: }
543:
544: public void traverseContinueStatement(Java.ContinueStatement cs) {
545: this .traverseStatement(cs);
546: }
547:
548: public void traverseEmptyStatement(Java.EmptyStatement es) {
549: this .traverseStatement(es);
550: }
551:
552: public void traverseLocalClassDeclarationStatement(
553: Java.LocalClassDeclarationStatement lcds) {
554: lcds.lcd.accept(this .cv);
555: this .traverseStatement(lcds);
556: }
557:
558: public void traversePackage(Java.Package p) {
559: this .traverseAtom(p);
560: }
561:
562: public void traverseArrayLength(Java.ArrayLength al) {
563: al.lhs.accept((Visitor.RvalueVisitor) this .cv);
564: this .traverseRvalue(al);
565: }
566:
567: public void traverseAssignment(Java.Assignment a) {
568: a.lhs.accept((Visitor.LvalueVisitor) this .cv);
569: a.rhs.accept((Visitor.RvalueVisitor) this .cv);
570: this .traverseRvalue(a);
571: }
572:
573: public void traverseUnaryOperation(Java.UnaryOperation uo) {
574: uo.operand.accept((Visitor.RvalueVisitor) this .cv);
575: this .traverseBooleanRvalue(uo);
576: }
577:
578: public void traverseBinaryOperation(Java.BinaryOperation bo) {
579: bo.lhs.accept((Visitor.RvalueVisitor) this .cv);
580: bo.rhs.accept((Visitor.RvalueVisitor) this .cv);
581: this .traverseBooleanRvalue(bo);
582: }
583:
584: public void traverseCast(Java.Cast c) {
585: c.targetType.accept((Visitor.TypeVisitor) this .cv);
586: c.value.accept((Visitor.RvalueVisitor) this .cv);
587: this .traverseRvalue(c);
588: }
589:
590: public void traverseClassLiteral(Java.ClassLiteral cl) {
591: cl.type.accept((Visitor.TypeVisitor) this .cv);
592: this .traverseRvalue(cl);
593: }
594:
595: public void traverseConditionalExpression(
596: Java.ConditionalExpression ce) {
597: ce.lhs.accept((Visitor.RvalueVisitor) this .cv);
598: ce.mhs.accept((Visitor.RvalueVisitor) this .cv);
599: ce.rhs.accept((Visitor.RvalueVisitor) this .cv);
600: this .traverseRvalue(ce);
601: }
602:
603: public void traverseConstantValue(Java.ConstantValue cv) {
604: this .traverseRvalue(cv);
605: }
606:
607: public void traverseCrement(Java.Crement c) {
608: c.operand.accept((Visitor.LvalueVisitor) this .cv);
609: this .traverseRvalue(c);
610: }
611:
612: public void traverseInstanceof(Java.Instanceof io) {
613: io.lhs.accept((Visitor.RvalueVisitor) this .cv);
614: io.rhs.accept((Visitor.TypeVisitor) this .cv);
615: this .traverseRvalue(io);
616: }
617:
618: public void traverseMethodInvocation(Java.MethodInvocation mi) {
619: if (mi.optionalTarget != null)
620: mi.optionalTarget.accept(this .cv);
621: this .traverseInvocation(mi);
622: }
623:
624: public void traverseSuperclassMethodInvocation(
625: Java.SuperclassMethodInvocation smi) {
626: this .traverseInvocation(smi);
627: }
628:
629: public void traverseLiteral(Java.Literal l) {
630: this .traverseRvalue(l);
631: }
632:
633: public void traverseNewAnonymousClassInstance(
634: Java.NewAnonymousClassInstance naci) {
635: if (naci.optionalQualification != null)
636: naci.optionalQualification
637: .accept((Visitor.RvalueVisitor) this .cv);
638: naci.anonymousClassDeclaration.accept(this .cv);
639: for (int i = 0; i < naci.arguments.length; ++i)
640: naci.arguments[i].accept((Visitor.RvalueVisitor) this .cv);
641: this .traverseRvalue(naci);
642: }
643:
644: public void traverseNewArray(Java.NewArray na) {
645: na.type.accept((Visitor.TypeVisitor) this .cv);
646: for (int i = 0; i < na.dimExprs.length; ++i)
647: na.dimExprs[i].accept((Visitor.RvalueVisitor) this .cv);
648: this .traverseRvalue(na);
649: }
650:
651: public void traverseNewInitializedArray(Java.NewInitializedArray nia) {
652: nia.arrayType.accept((Visitor.TypeVisitor) this .cv);
653: this .traverseArrayInitializerOrRvalue(nia.arrayInitializer);
654: }
655:
656: public void traverseArrayInitializerOrRvalue(
657: Java.ArrayInitializerOrRvalue aiorv) {
658: if (aiorv instanceof Java.Rvalue) {
659: ((Java.Atom) aiorv).accept(this .cv);
660: } else if (aiorv instanceof Java.ArrayInitializer) {
661: Java.ArrayInitializerOrRvalue[] values = ((Java.ArrayInitializer) aiorv).values;
662: for (int i = 0; i < values.length; ++i)
663: this .traverseArrayInitializerOrRvalue(values[i]);
664: } else {
665: throw new RuntimeException(
666: "Unexpected array initializer or rvalue class "
667: + aiorv.getClass().getName());
668: }
669: }
670:
671: public void traverseNewClassInstance(Java.NewClassInstance nci) {
672: if (nci.optionalQualification != null)
673: nci.optionalQualification
674: .accept((Visitor.RvalueVisitor) this .cv);
675: nci.type.accept((Visitor.TypeVisitor) this .cv);
676: for (int i = 0; i < nci.arguments.length; ++i)
677: nci.arguments[i].accept((Visitor.RvalueVisitor) this .cv);
678: this .traverseRvalue(nci);
679: }
680:
681: public void traverseParameterAccess(Java.ParameterAccess pa) {
682: this .traverseRvalue(pa);
683: }
684:
685: public void traverseQualifiedThisReference(
686: Java.QualifiedThisReference qtr) {
687: qtr.qualification.accept((Visitor.TypeVisitor) this .cv);
688: this .traverseRvalue(qtr);
689: }
690:
691: public void traverseThisReference(Java.ThisReference tr) {
692: this .traverseRvalue(tr);
693: }
694:
695: public void traverseArrayType(Java.ArrayType at) {
696: at.componentType.accept((Visitor.TypeVisitor) this .cv);
697: this .traverseType(at);
698: }
699:
700: public void traverseBasicType(Java.BasicType bt) {
701: this .traverseType(bt);
702: }
703:
704: public void traverseReferenceType(Java.ReferenceType rt) {
705: this .traverseType(rt);
706: }
707:
708: public void traverseRvalueMemberType(Java.RvalueMemberType rmt) {
709: rmt.rvalue.accept((Visitor.RvalueVisitor) this .cv);
710: this .traverseType(rmt);
711: }
712:
713: public void traverseSimpleType(Java.SimpleType st) {
714: this .traverseType(st);
715: }
716:
717: public void traverseAlternateConstructorInvocation(
718: Java.AlternateConstructorInvocation aci) {
719: this .traverseConstructorInvocation(aci);
720: }
721:
722: public void traverseSuperConstructorInvocation(
723: Java.SuperConstructorInvocation sci) {
724: if (sci.optionalQualification != null)
725: sci.optionalQualification
726: .accept((Visitor.RvalueVisitor) this .cv);
727: this .traverseConstructorInvocation(sci);
728: }
729:
730: public void traverseAmbiguousName(Java.AmbiguousName an) {
731: this .traverseLvalue(an);
732: }
733:
734: public void traverseArrayAccessExpression(
735: Java.ArrayAccessExpression aae) {
736: aae.lhs.accept((Visitor.RvalueVisitor) this .cv);
737: ((Java.Atom) aae.index).accept(this .cv);
738: this .traverseLvalue(aae);
739: }
740:
741: public void traverseFieldAccess(Java.FieldAccess fa) {
742: fa.lhs.accept(this .cv);
743: this .traverseLvalue(fa);
744: }
745:
746: public void traverseFieldAccessExpression(
747: Java.FieldAccessExpression fae) {
748: fae.lhs.accept(this .cv);
749: this .traverseLvalue(fae);
750: }
751:
752: public void traverseLocalVariableAccess(Java.LocalVariableAccess lva) {
753: this .traverseLvalue(lva);
754: }
755:
756: public void traverseParenthesizedExpression(
757: Java.ParenthesizedExpression pe) {
758: pe.value.accept((Visitor.RvalueVisitor) this .cv);
759: this .traverseLvalue(pe);
760: }
761:
762: public void traverseClassDeclaration(Java.ClassDeclaration cd) {
763: for (Iterator it = cd.constructors.iterator(); it.hasNext();) {
764: ((Java.ConstructorDeclarator) it.next()).accept(this .cv);
765: }
766: for (Iterator it = cd.variableDeclaratorsAndInitializers
767: .iterator(); it.hasNext();) {
768: ((Java.TypeBodyDeclaration) it.next()).accept(this .cv);
769: }
770: this .traverseAbstractTypeDeclaration(cd);
771: }
772:
773: public void traverseAbstractTypeDeclaration(
774: Java.AbstractTypeDeclaration atd) {
775: for (Iterator it = atd.declaredClassesAndInterfaces.iterator(); it
776: .hasNext();) {
777: ((Java.NamedTypeDeclaration) it.next()).accept(this .cv);
778: }
779: for (Iterator it = atd.declaredMethods.iterator(); it.hasNext();) {
780: this .traverseMethodDeclarator((Java.MethodDeclarator) it
781: .next());
782: }
783: }
784:
785: public void traverseNamedClassDeclaration(
786: Java.NamedClassDeclaration ncd) {
787: for (int i = 0; i < ncd.implementedTypes.length; ++i) {
788: ncd.implementedTypes[i]
789: .accept((Visitor.TypeVisitor) this .cv);
790: }
791: if (ncd.optionalExtendedType != null)
792: ncd.optionalExtendedType
793: .accept((Visitor.TypeVisitor) this .cv);
794: this .traverseClassDeclaration(ncd);
795: }
796:
797: public void traverseInterfaceDeclaration(
798: Java.InterfaceDeclaration id) {
799: for (Iterator it = id.constantDeclarations.iterator(); it
800: .hasNext();) {
801: ((Java.TypeBodyDeclaration) it.next()).accept(this .cv);
802: }
803: for (int i = 0; i < id.extendedTypes.length; ++i) {
804: id.extendedTypes[i].accept((Visitor.TypeVisitor) this .cv);
805: }
806: this .traverseAbstractTypeDeclaration(id);
807: }
808:
809: public void traverseFunctionDeclarator(Java.FunctionDeclarator fd) {
810: for (int i = 0; i < fd.formalParameters.length; ++i) {
811: fd.formalParameters[i].type
812: .accept((Visitor.TypeVisitor) this .cv);
813: }
814: if (fd.optionalBody != null)
815: fd.optionalBody.accept(this .cv);
816: }
817:
818: public void traverseAbstractTypeBodyDeclaration(
819: Java.AbstractTypeBodyDeclaration atbd) {
820: this .traverseLocated(atbd);
821: }
822:
823: public void traverseStatement(Java.Statement s) {
824: this .traverseLocated(s);
825: }
826:
827: public void traverseBreakableStatement(Java.BreakableStatement bs) {
828: this .traverseStatement(bs);
829: }
830:
831: public void traverseContinuableStatement(
832: Java.ContinuableStatement cs) {
833: this .traverseBreakableStatement(cs);
834: }
835:
836: public void traverseRvalue(Java.Rvalue rv) {
837: this .traverseAtom(rv);
838: }
839:
840: public void traverseBooleanRvalue(Java.BooleanRvalue brv) {
841: this .traverseRvalue(brv);
842: }
843:
844: public void traverseInvocation(Java.Invocation i) {
845: for (int j = 0; j < i.arguments.length; ++j)
846: i.arguments[j].accept((Visitor.RvalueVisitor) this .cv);
847: this .traverseRvalue(i);
848: }
849:
850: public void traverseConstructorInvocation(
851: Java.ConstructorInvocation ci) {
852: for (int i = 0; i < ci.arguments.length; ++i)
853: ci.arguments[i].accept((Visitor.RvalueVisitor) this .cv);
854: this .traverseAtom(ci);
855: }
856:
857: public void traverseLvalue(Java.Lvalue lv) {
858: this .traverseRvalue(lv);
859: }
860:
861: public void traverseType(Java.Type t) {
862: this .traverseAtom(t);
863: }
864:
865: public void traverseAtom(Java.Atom a) {
866: this .traverseLocated(a);
867: }
868:
869: public void traverseLocated(Java.Located l) {
870: ;
871: }
872: }
|