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