1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler;
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.internal.compiler.ast.AND_AND_Expression;
15 import net.sourceforge.phpdt.internal.compiler.ast.AllocationExpression;
16 import net.sourceforge.phpdt.internal.compiler.ast.Argument;
17 import net.sourceforge.phpdt.internal.compiler.ast.ArrayAllocationExpression;
18 import net.sourceforge.phpdt.internal.compiler.ast.ArrayInitializer;
19 import net.sourceforge.phpdt.internal.compiler.ast.ArrayQualifiedTypeReference;
20 import net.sourceforge.phpdt.internal.compiler.ast.ArrayReference;
21 import net.sourceforge.phpdt.internal.compiler.ast.ArrayTypeReference;
22 import net.sourceforge.phpdt.internal.compiler.ast.AssertStatement;
23 import net.sourceforge.phpdt.internal.compiler.ast.Assignment;
24 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
25 import net.sourceforge.phpdt.internal.compiler.ast.Block;
26 import net.sourceforge.phpdt.internal.compiler.ast.BreakStatement;
27 import net.sourceforge.phpdt.internal.compiler.ast.CaseStatement;
28 import net.sourceforge.phpdt.internal.compiler.ast.CastExpression;
29 import net.sourceforge.phpdt.internal.compiler.ast.Clinit;
30 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
31 import net.sourceforge.phpdt.internal.compiler.ast.CompoundAssignment;
32 import net.sourceforge.phpdt.internal.compiler.ast.ConditionalExpression;
33 import net.sourceforge.phpdt.internal.compiler.ast.ConstructorDeclaration;
34 import net.sourceforge.phpdt.internal.compiler.ast.ContinueStatement;
35 import net.sourceforge.phpdt.internal.compiler.ast.DoStatement;
36 import net.sourceforge.phpdt.internal.compiler.ast.DoubleLiteral;
37 import net.sourceforge.phpdt.internal.compiler.ast.EmptyStatement;
38 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
39 import net.sourceforge.phpdt.internal.compiler.ast.ExplicitConstructorCall;
40 import net.sourceforge.phpdt.internal.compiler.ast.ExtendedStringLiteral;
41 import net.sourceforge.phpdt.internal.compiler.ast.FalseLiteral;
42 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
43 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
44 import net.sourceforge.phpdt.internal.compiler.ast.FloatLiteral;
45 import net.sourceforge.phpdt.internal.compiler.ast.ForStatement;
46 import net.sourceforge.phpdt.internal.compiler.ast.IfStatement;
47 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
48 import net.sourceforge.phpdt.internal.compiler.ast.Initializer;
49 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
50 import net.sourceforge.phpdt.internal.compiler.ast.IntLiteral;
51 import net.sourceforge.phpdt.internal.compiler.ast.LabeledStatement;
52 import net.sourceforge.phpdt.internal.compiler.ast.LocalDeclaration;
53 import net.sourceforge.phpdt.internal.compiler.ast.LongLiteral;
54 import net.sourceforge.phpdt.internal.compiler.ast.MessageSend;
55 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
56 import net.sourceforge.phpdt.internal.compiler.ast.NullLiteral;
57 import net.sourceforge.phpdt.internal.compiler.ast.OR_OR_Expression;
58 import net.sourceforge.phpdt.internal.compiler.ast.PostfixExpression;
59 import net.sourceforge.phpdt.internal.compiler.ast.PrefixExpression;
60 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedAllocationExpression;
61 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedNameReference;
62 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedSuperReference;
63 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedThisReference;
64 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedTypeReference;
65 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
66 import net.sourceforge.phpdt.internal.compiler.ast.SingleNameReference;
67 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
68 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
69 import net.sourceforge.phpdt.internal.compiler.ast.SuperReference;
70 import net.sourceforge.phpdt.internal.compiler.ast.SwitchStatement;
71 import net.sourceforge.phpdt.internal.compiler.ast.ThisReference;
72 import net.sourceforge.phpdt.internal.compiler.ast.ThrowStatement;
73 import net.sourceforge.phpdt.internal.compiler.ast.TrueLiteral;
74 import net.sourceforge.phpdt.internal.compiler.ast.TryStatement;
75 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
76 import net.sourceforge.phpdt.internal.compiler.ast.UnaryExpression;
77 import net.sourceforge.phpdt.internal.compiler.ast.WhileStatement;
78 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
79 import net.sourceforge.phpdt.internal.compiler.lookup.ClassScope;
80 import net.sourceforge.phpdt.internal.compiler.lookup.CompilationUnitScope;
81 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
84 * A visitor for iterating through the parse tree.
86 public abstract class ASTVisitor {
88 public void acceptProblem(IProblem problem) {
89 // do nothing by default
92 public void endVisit(AllocationExpression allocationExpression,
94 // do nothing by default
97 public void endVisit(AND_AND_Expression and_and_Expression, BlockScope scope) {
98 // do nothing by default
101 // public void endVisit(JavadocArrayQualifiedTypeReference typeRef,
102 // BlockScope scope) {
103 // // do nothing by default
105 // public void endVisit(JavadocArraySingleTypeReference typeRef, BlockScope
107 // // do nothing by default
109 // public void endVisit(JavadocArgumentExpression expression, BlockScope
111 // // do nothing by default
113 // public void endVisit(JavadocFieldReference fieldRef, BlockScope scope) {
114 // // do nothing by default
116 // public void endVisit(JavadocMessageSend messageSend, BlockScope scope) {
117 // // do nothing by default
119 // public void endVisit(JavadocQualifiedTypeReference typeRef, BlockScope
121 // // do nothing by default
123 // public void endVisit(JavadocReturnStatement statement, BlockScope scope)
125 // // do nothing by default
127 // public void endVisit(JavadocSingleNameReference argument, BlockScope
129 // // do nothing by default
131 // public void endVisit(JavadocSingleTypeReference typeRef, BlockScope
133 // // do nothing by default
135 public void endVisit(Argument argument, BlockScope scope) {
136 // do nothing by default
139 public void endVisit(ArrayAllocationExpression arrayAllocationExpression,
141 // do nothing by default
144 public void endVisit(ArrayInitializer arrayInitializer, BlockScope scope) {
145 // do nothing by default
148 public void endVisit(
149 ArrayQualifiedTypeReference arrayQualifiedTypeReference,
151 // do nothing by default
154 public void endVisit(
155 ArrayQualifiedTypeReference arrayQualifiedTypeReference,
157 // do nothing by default
160 public void endVisit(ArrayReference arrayReference, BlockScope scope) {
161 // do nothing by default
164 public void endVisit(ArrayTypeReference arrayTypeReference, BlockScope scope) {
165 // do nothing by default
168 public void endVisit(ArrayTypeReference arrayTypeReference, ClassScope scope) {
169 // do nothing by default
172 public void endVisit(Assignment assignment, BlockScope scope) {
173 // do nothing by default
176 public void endVisit(AssertStatement assertStatement, BlockScope scope) {
177 // do nothing by default
180 public void endVisit(BinaryExpression binaryExpression, BlockScope scope) {
181 // do nothing by default
184 public void endVisit(Block block, BlockScope scope) {
185 // do nothing by default
188 public void endVisit(BreakStatement breakStatement, BlockScope scope) {
189 // do nothing by default
192 public void endVisit(CaseStatement caseStatement, BlockScope scope) {
193 // do nothing by default
196 public void endVisit(CastExpression castExpression, BlockScope scope) {
197 // do nothing by default
200 public void endVisit(Clinit clinit, ClassScope scope) {
201 // do nothing by default
204 public void endVisit(CompilationUnitDeclaration compilationUnitDeclaration,
205 CompilationUnitScope scope) {
206 // do nothing by default
209 public void endVisit(CompoundAssignment compoundAssignment, BlockScope scope) {
210 // do nothing by default
213 public void endVisit(ConditionalExpression conditionalExpression,
215 // do nothing by default
218 public void endVisit(ConstructorDeclaration constructorDeclaration,
220 // do nothing by default
223 public void endVisit(ContinueStatement continueStatement, BlockScope scope) {
224 // do nothing by default
227 public void endVisit(DoStatement doStatement, BlockScope scope) {
228 // do nothing by default
231 public void endVisit(DoubleLiteral doubleLiteral, BlockScope scope) {
232 // do nothing by default
235 public void endVisit(EqualExpression equalExpression, BlockScope scope) {
236 // do nothing by default
239 public void endVisit(ExplicitConstructorCall explicitConstructor,
241 // do nothing by default
244 public void endVisit(ExtendedStringLiteral extendedStringLiteral,
246 // do nothing by default
249 public void endVisit(FalseLiteral falseLiteral, BlockScope scope) {
250 // do nothing by default
253 public void endVisit(FieldDeclaration fieldDeclaration, MethodScope scope) {
254 // do nothing by default
257 public void endVisit(FieldReference fieldReference, BlockScope scope) {
258 // do nothing by default
261 public void endVisit(FloatLiteral floatLiteral, BlockScope scope) {
262 // do nothing by default
265 public void endVisit(EmptyStatement emptyStatement, BlockScope scope) {
266 // do nothing by default
269 public void endVisit(ForStatement forStatement, BlockScope scope) {
270 // do nothing by default
273 public void endVisit(IfStatement ifStatement, BlockScope scope) {
274 // do nothing by default
277 public void endVisit(ImportReference importRef, CompilationUnitScope scope) {
278 // do nothing by default
281 public void endVisit(Initializer initializer, MethodScope scope) {
282 // do nothing by default
285 public void endVisit(InstanceOfExpression instanceOfExpression,
287 // do nothing by default
290 public void endVisit(IntLiteral intLiteral, BlockScope scope) {
291 // do nothing by default
294 public void endVisit(LabeledStatement labeledStatement, BlockScope scope) {
295 // do nothing by default
298 public void endVisit(LocalDeclaration localDeclaration, BlockScope scope) {
299 // do nothing by default
302 public void endVisit(LongLiteral longLiteral, BlockScope scope) {
303 // do nothing by default
306 public void endVisit(MessageSend messageSend, BlockScope scope) {
307 // do nothing by default
310 public void endVisit(MethodDeclaration methodDeclaration, ClassScope scope) {
311 // do nothing by default
314 // public void endVisit(StringLiteralConcatenation literal, BlockScope
316 // // do nothing by default
318 public void endVisit(NullLiteral nullLiteral, BlockScope scope) {
319 // do nothing by default
322 public void endVisit(OR_OR_Expression or_or_Expression, BlockScope scope) {
323 // do nothing by default
326 public void endVisit(PostfixExpression postfixExpression, BlockScope scope) {
327 // do nothing by default
330 public void endVisit(PrefixExpression prefixExpression, BlockScope scope) {
331 // do nothing by default
334 public void endVisit(
335 QualifiedAllocationExpression qualifiedAllocationExpression,
337 // do nothing by default
340 public void endVisit(QualifiedNameReference qualifiedNameReference,
342 // do nothing by default
345 public void endVisit(QualifiedSuperReference qualifiedSuperReference,
347 // do nothing by default
350 public void endVisit(QualifiedThisReference qualifiedThisReference,
352 // do nothing by default
355 public void endVisit(QualifiedTypeReference qualifiedTypeReference,
357 // do nothing by default
360 public void endVisit(QualifiedTypeReference qualifiedTypeReference,
362 // do nothing by default
365 public void endVisit(ReturnStatement returnStatement, BlockScope scope) {
366 // do nothing by default
369 public void endVisit(SingleNameReference singleNameReference,
371 // do nothing by default
374 public void endVisit(SingleTypeReference singleTypeReference,
376 // do nothing by default
379 public void endVisit(SingleTypeReference singleTypeReference,
381 // do nothing by default
384 public void endVisit(StringLiteral stringLiteral, BlockScope scope) {
385 // do nothing by default
388 public void endVisit(SuperReference superReference, BlockScope scope) {
389 // do nothing by default
392 public void endVisit(SwitchStatement switchStatement, BlockScope scope) {
393 // do nothing by default
396 public void endVisit(ThisReference thisReference, BlockScope scope) {
397 // do nothing by default
400 public void endVisit(ThrowStatement throwStatement, BlockScope scope) {
401 // do nothing by default
404 public void endVisit(TrueLiteral trueLiteral, BlockScope scope) {
405 // do nothing by default
408 public void endVisit(TryStatement tryStatement, BlockScope scope) {
409 // do nothing by default
412 public void endVisit(TypeDeclaration localTypeDeclaration, BlockScope scope) {
413 // do nothing by default
416 public void endVisit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
417 // do nothing by default
420 public void endVisit(TypeDeclaration typeDeclaration,
421 CompilationUnitScope scope) {
422 // do nothing by default
425 public void endVisit(UnaryExpression unaryExpression, BlockScope scope) {
426 // do nothing by default
429 public void endVisit(WhileStatement whileStatement, BlockScope scope) {
430 // do nothing by default
433 public boolean visit(AllocationExpression allocationExpression,
435 return true; // do nothing by default, keep traversing
436 // do nothing by default
439 public boolean visit(AND_AND_Expression and_and_Expression, BlockScope scope) {
440 return true; // do nothing by default, keep traversing
443 // public boolean visit(JavadocArrayQualifiedTypeReference typeRef,
444 // BlockScope scope) {
445 // return true; // do nothing by default, keep traversing
447 // public boolean visit(JavadocArraySingleTypeReference typeRef, BlockScope
449 // return true; // do nothing by default, keep traversing
451 // public boolean visit(JavadocArgumentExpression expression, BlockScope
453 // return true; // do nothing by default, keep traversing
455 // public boolean visit(JavadocFieldReference fieldRef, BlockScope scope) {
456 // return true; // do nothing by default, keep traversing
458 // public boolean visit(JavadocMessageSend messageSend, BlockScope scope) {
459 // return true; // do nothing by default, keep traversing
461 // public boolean visit(JavadocQualifiedTypeReference typeRef, BlockScope
463 // return true; // do nothing by default, keep traversing
465 // public boolean visit(JavadocReturnStatement statement, BlockScope scope)
467 // return true; // do nothing by default, keep traversing
469 // public boolean visit(JavadocSingleNameReference argument, BlockScope
471 // return true; // do nothing by default, keep traversing
473 // public boolean visit(JavadocSingleTypeReference typeRef, BlockScope
475 // return true; // do nothing by default, keep traversing
477 public boolean visit(Argument argument, BlockScope scope) {
478 return true; // do nothing by default, keep traversing
481 public boolean visit(ArrayAllocationExpression arrayAllocationExpression,
483 return true; // do nothing by default, keep traversing
486 public boolean visit(ArrayInitializer arrayInitializer, BlockScope scope) {
487 return true; // do nothing by default, keep traversing
490 public boolean visit(
491 ArrayQualifiedTypeReference arrayQualifiedTypeReference,
493 return true; // do nothing by default, keep traversing
496 public boolean visit(
497 ArrayQualifiedTypeReference arrayQualifiedTypeReference,
499 return true; // do nothing by default, keep traversing
502 public boolean visit(ArrayReference arrayReference, BlockScope scope) {
503 return true; // do nothing by default, keep traversing
506 public boolean visit(ArrayTypeReference arrayTypeReference, BlockScope scope) {
507 return true; // do nothing by default, keep traversing
510 public boolean visit(ArrayTypeReference arrayTypeReference, ClassScope scope) {
511 return true; // do nothing by default, keep traversing
514 public boolean visit(Assignment assignment, BlockScope scope) {
515 return true; // do nothing by default, keep traversing
518 public boolean visit(AssertStatement assertStatement, BlockScope scope) {
519 return true; // do nothing by default, keep traversing
522 public boolean visit(BinaryExpression binaryExpression, BlockScope scope) {
523 return true; // do nothing by default, keep traversing
526 public boolean visit(Block block, BlockScope scope) {
527 return true; // do nothing by default, keep traversing
530 public boolean visit(BreakStatement breakStatement, BlockScope scope) {
531 return true; // do nothing by default, keep traversing
534 public boolean visit(CaseStatement caseStatement, BlockScope scope) {
535 return true; // do nothing by default, keep traversing
538 public boolean visit(CastExpression castExpression, BlockScope scope) {
539 return true; // do nothing by default, keep traversing
542 public boolean visit(Clinit clinit, ClassScope scope) {
543 return true; // do nothing by default, keep traversing
546 public boolean visit(CompilationUnitDeclaration compilationUnitDeclaration,
547 CompilationUnitScope scope) {
548 return true; // do nothing by default, keep traversing
551 public boolean visit(CompoundAssignment compoundAssignment, BlockScope scope) {
552 return true; // do nothing by default, keep traversing
555 public boolean visit(ConditionalExpression conditionalExpression,
557 return true; // do nothing by default, keep traversing
560 public boolean visit(ConstructorDeclaration constructorDeclaration,
562 return true; // do nothing by default, keep traversing
565 public boolean visit(ContinueStatement continueStatement, BlockScope scope) {
566 return true; // do nothing by default, keep traversing
569 public boolean visit(DoStatement doStatement, BlockScope scope) {
570 return true; // do nothing by default, keep traversing
573 public boolean visit(DoubleLiteral doubleLiteral, BlockScope scope) {
574 return true; // do nothing by default, keep traversing
577 public boolean visit(EqualExpression equalExpression, BlockScope scope) {
578 return true; // do nothing by default, keep traversing
581 public boolean visit(EmptyStatement emptyStatement, BlockScope scope) {
582 return true; // do nothing by default, keep traversing
585 public boolean visit(ExplicitConstructorCall explicitConstructor,
587 return true; // do nothing by default, keep traversing
590 public boolean visit(ExtendedStringLiteral extendedStringLiteral,
592 return true; // do nothing by default, keep traversing
595 public boolean visit(FalseLiteral falseLiteral, BlockScope scope) {
596 return true; // do nothing by default, keep traversing
599 public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
600 return true; // do nothing by default, keep traversing
603 public boolean visit(FieldReference fieldReference, BlockScope scope) {
604 return true; // do nothing by default, keep traversing
607 public boolean visit(FloatLiteral floatLiteral, BlockScope scope) {
608 return true; // do nothing by default, keep traversing
611 public boolean visit(ForStatement forStatement, BlockScope scope) {
612 return true; // do nothing by default, keep traversing
615 public boolean visit(IfStatement ifStatement, BlockScope scope) {
616 return true; // do nothing by default, keep traversing
619 public boolean visit(ImportReference importRef, CompilationUnitScope scope) {
620 return true; // do nothing by default, keep traversing
623 public boolean visit(Initializer initializer, MethodScope scope) {
624 return true; // do nothing by default, keep traversing
627 public boolean visit(InstanceOfExpression instanceOfExpression,
629 return true; // do nothing by default, keep traversing
632 public boolean visit(IntLiteral intLiteral, BlockScope scope) {
633 return true; // do nothing by default, keep traversing
636 public boolean visit(LabeledStatement labeledStatement, BlockScope scope) {
637 return true; // do nothing by default, keep traversing
640 public boolean visit(LocalDeclaration localDeclaration, BlockScope scope) {
641 return true; // do nothing by default, keep traversing
644 public boolean visit(LongLiteral longLiteral, BlockScope scope) {
645 return true; // do nothing by default, keep traversing
648 public boolean visit(MessageSend messageSend, BlockScope scope) {
649 return true; // do nothing by default, keep traversing
652 public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
653 return true; // do nothing by default, keep traversing
656 // public boolean visit(
657 // StringLiteralConcatenation literal,
658 // BlockScope scope) {
659 // return true; // do nothing by default, keep traversing
661 public boolean visit(NullLiteral nullLiteral, BlockScope scope) {
662 return true; // do nothing by default, keep traversing
665 public boolean visit(OR_OR_Expression or_or_Expression, BlockScope scope) {
666 return true; // do nothing by default, keep traversing
669 public boolean visit(PostfixExpression postfixExpression, BlockScope scope) {
670 return true; // do nothing by default, keep traversing
673 public boolean visit(PrefixExpression prefixExpression, BlockScope scope) {
674 return true; // do nothing by default, keep traversing
677 public boolean visit(
678 QualifiedAllocationExpression qualifiedAllocationExpression,
680 return true; // do nothing by default, keep traversing
683 public boolean visit(QualifiedNameReference qualifiedNameReference,
685 return true; // do nothing by default, keep traversing
688 public boolean visit(QualifiedSuperReference qualifiedSuperReference,
690 return true; // do nothing by default, keep traversing
693 public boolean visit(QualifiedThisReference qualifiedThisReference,
695 return true; // do nothing by default, keep traversing
698 public boolean visit(QualifiedTypeReference qualifiedTypeReference,
700 return true; // do nothing by default, keep traversing
703 public boolean visit(QualifiedTypeReference qualifiedTypeReference,
705 return true; // do nothing by default, keep traversing
708 public boolean visit(ReturnStatement returnStatement, BlockScope scope) {
709 return true; // do nothing by default, keep traversing
712 public boolean visit(SingleNameReference singleNameReference,
714 return true; // do nothing by default, keep traversing
717 public boolean visit(SingleTypeReference singleTypeReference,
719 return true; // do nothing by default, keep traversing
722 public boolean visit(SingleTypeReference singleTypeReference,
724 return true; // do nothing by default, keep traversing
727 public boolean visit(StringLiteral stringLiteral, BlockScope scope) {
728 return true; // do nothing by default, keep traversing
731 public boolean visit(SuperReference superReference, BlockScope scope) {
732 return true; // do nothing by default, keep traversing
735 public boolean visit(SwitchStatement switchStatement, BlockScope scope) {
736 return true; // do nothing by default, keep traversing
739 public boolean visit(ThisReference thisReference, BlockScope scope) {
740 return true; // do nothing by default, keep traversing
743 public boolean visit(ThrowStatement throwStatement, BlockScope scope) {
744 return true; // do nothing by default, keep traversing
747 public boolean visit(TrueLiteral trueLiteral, BlockScope scope) {
748 return true; // do nothing by default, keep traversing
751 public boolean visit(TryStatement tryStatement, BlockScope scope) {
752 return true; // do nothing by default, keep traversing
755 public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) {
756 return true; // do nothing by default, keep traversing
759 public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
760 return true; // do nothing by default, keep traversing
763 public boolean visit(TypeDeclaration typeDeclaration,
764 CompilationUnitScope scope) {
765 return true; // do nothing by default, keep traversing
768 public boolean visit(UnaryExpression unaryExpression, BlockScope scope) {
769 return true; // do nothing by default, keep traversing
772 public boolean visit(WhileStatement whileStatement, BlockScope scope) {
773 return true; // do nothing by default, keep traversing