001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.corext.dom;
011:
012: import org.eclipse.jdt.core.dom.*;
013:
014: /**
015: * <p>This class provides a convenient behaviour-only
016: * extension mechanism for the ASTNode hierarchy.
017: * If you feel like you would like to add a method to
018: * the ASTNode hierarchy (or a subtree of the hierarchy),
019: * and you want to have different implementations
020: * of it at different points in the hierarchy,
021: * simply create a HierarchicalASTVisitor representing
022: * the new method and all its implementations,
023: * locating each implementation within the right
024: * visit(XX) method. If you wanted to add a method implementation to abstract
025: * class Foo, an ASTNode descendant, put your implementation in visit(Foo).
026: * This class will provide appropriate dispatch, just as if the method
027: * implementations had been added to the ASTNode hierarchy.
028: * </p>
029: *
030: * <p><b>Details:<b></p>
031: *
032: * <p>This class has a visit(XX node) method for every for every
033: * class (concrete or abstract) XX in the ASTNode hierarchy. In this class'
034: * default implementations of these methods, the method corresponding to a given
035: * ASTNode descendant class will call (and return the return value of) the
036: * visit(YY) method for it's superclass YY, with the exception of the
037: * visit(ASTNode) method which simply returns true, since ASTNode doesn't have a
038: * superclass that is within the ASTNode hierarchy.
039: * </p>
040: *
041: * <p>Because of this organization, when visit(XX) methods are overridden in a
042: * subclass, and the visitor is applied to a node, only the most specialized
043: * overridden method implementation for the node's type will be called, unless
044: * this most specialized method calls other visit methods (this is discouraged)
045: * or, (preferably) calls super.visit(XX node), (the reference type of the
046: * parameter must be XX) which will invoke this class' implementation of the
047: * method, which will, in turn, invoke the visit(YY) method corresponding to the
048: * superclass, YY.
049: * </p>
050: *
051: * <p>Thus, the dispatching behaviour achieved when
052: * HierarchicalASTVisitors' visit(XX) methods, corresponding to a particular
053: * concrete or abstract ASTNode descendant class, are overridden is exactly
054: * analogous to the dispatching behaviour obtained when method implementations
055: * are added to the same ASTNode descendant classes.
056: * </p>
057: */
058: /*
059: * IMPORTANT NOTE:
060: *
061: * The structure and behaviour of this class is
062: * verified reflectively by
063: * org.eclipse.jdt.ui.tests.core.HierarchicalASTVisitorTest
064: *
065: */
066: public abstract class HierarchicalASTVisitor extends ASTVisitor {
067: //TODO: check callers for handling of comments
068:
069: //---- Begin ASTNode Hierarchy -------------------------------------
070: public boolean visit(ASTNode node) {
071: return true;
072: }
073:
074: public void endVisit(ASTNode node) {
075: // do nothing
076: }
077:
078: public boolean visit(AnonymousClassDeclaration node) {
079: return visit((ASTNode) node);
080: }
081:
082: public void endVisit(AnonymousClassDeclaration node) {
083: endVisit((ASTNode) node);
084: }
085:
086: //---- Begin BodyDeclaration Hierarchy ---------------------------
087: public boolean visit(BodyDeclaration node) {
088: return visit((ASTNode) node);
089: }
090:
091: public void endVisit(BodyDeclaration node) {
092: endVisit((ASTNode) node);
093: }
094:
095: //---- Begin AbstractTypeDeclaration Hierarchy ---------------------------
096: public boolean visit(AbstractTypeDeclaration node) {
097: return visit((BodyDeclaration) node);
098: }
099:
100: public void endVisit(AbstractTypeDeclaration node) {
101: endVisit((BodyDeclaration) node);
102: }
103:
104: public boolean visit(AnnotationTypeDeclaration node) {
105: return visit((AbstractTypeDeclaration) node);
106: }
107:
108: public void endVisit(AnnotationTypeDeclaration node) {
109: endVisit((AbstractTypeDeclaration) node);
110: }
111:
112: public boolean visit(EnumDeclaration node) {
113: return visit((AbstractTypeDeclaration) node);
114: }
115:
116: public void endVisit(EnumDeclaration node) {
117: endVisit((AbstractTypeDeclaration) node);
118: }
119:
120: public boolean visit(TypeDeclaration node) {
121: return visit((AbstractTypeDeclaration) node);
122: }
123:
124: public void endVisit(TypeDeclaration node) {
125: endVisit((AbstractTypeDeclaration) node);
126: }
127:
128: //---- End AbstractTypeDeclaration Hierarchy ---------------------------
129:
130: public boolean visit(AnnotationTypeMemberDeclaration node) {
131: return visit((BodyDeclaration) node);
132: }
133:
134: public void endVisit(AnnotationTypeMemberDeclaration node) {
135: endVisit((BodyDeclaration) node);
136: }
137:
138: public boolean visit(EnumConstantDeclaration node) {
139: return visit((BodyDeclaration) node);
140: }
141:
142: public void endVisit(EnumConstantDeclaration node) {
143: endVisit((BodyDeclaration) node);
144: }
145:
146: public boolean visit(FieldDeclaration node) {
147: return visit((BodyDeclaration) node);
148: }
149:
150: public void endVisit(FieldDeclaration node) {
151: endVisit((BodyDeclaration) node);
152: }
153:
154: public boolean visit(Initializer node) {
155: return visit((BodyDeclaration) node);
156: }
157:
158: public void endVisit(Initializer node) {
159: endVisit((BodyDeclaration) node);
160: }
161:
162: public boolean visit(MethodDeclaration node) {
163: return visit((BodyDeclaration) node);
164: }
165:
166: public void endVisit(MethodDeclaration node) {
167: endVisit((BodyDeclaration) node);
168: }
169:
170: //---- End BodyDeclaration Hierarchy -----------------------------
171:
172: public boolean visit(CatchClause node) {
173: return visit((ASTNode) node);
174: }
175:
176: public void endVisit(CatchClause node) {
177: endVisit((ASTNode) node);
178: }
179:
180: //---- Begin Comment Hierarchy ----------------------------------
181: public boolean visit(Comment node) {
182: return visit((ASTNode) node);
183: }
184:
185: public void endVisit(Comment node) {
186: endVisit((ASTNode) node);
187: }
188:
189: public boolean visit(BlockComment node) {
190: return visit((Comment) node);
191: }
192:
193: public void endVisit(BlockComment node) {
194: endVisit((Comment) node);
195: }
196:
197: public boolean visit(Javadoc node) {
198: return visit((Comment) node);
199: }
200:
201: public void endVisit(Javadoc node) {
202: endVisit((Comment) node);
203: }
204:
205: public boolean visit(LineComment node) {
206: return visit((Comment) node);
207: }
208:
209: public void endVisit(LineComment node) {
210: endVisit((Comment) node);
211: }
212:
213: //---- End Comment Hierarchy -----------------------------
214:
215: public boolean visit(CompilationUnit node) {
216: return visit((ASTNode) node);
217: }
218:
219: public void endVisit(CompilationUnit node) {
220: endVisit((ASTNode) node);
221: }
222:
223: //---- Begin Expression Hierarchy ----------------------------------
224: public boolean visit(Expression node) {
225: return visit((ASTNode) node);
226: }
227:
228: public void endVisit(Expression node) {
229: endVisit((ASTNode) node);
230: }
231:
232: //---- Begin Annotation Hierarchy ----------------------------------
233: public boolean visit(Annotation node) {
234: return visit((Expression) node);
235: }
236:
237: public void endVisit(Annotation node) {
238: endVisit((Expression) node);
239: }
240:
241: public boolean visit(MarkerAnnotation node) {
242: return visit((Annotation) node);
243: }
244:
245: public void endVisit(MarkerAnnotation node) {
246: endVisit((Annotation) node);
247: }
248:
249: public boolean visit(NormalAnnotation node) {
250: return visit((Annotation) node);
251: }
252:
253: public void endVisit(NormalAnnotation node) {
254: endVisit((Annotation) node);
255: }
256:
257: public boolean visit(SingleMemberAnnotation node) {
258: return visit((Annotation) node);
259: }
260:
261: public void endVisit(SingleMemberAnnotation node) {
262: endVisit((Annotation) node);
263: }
264:
265: //---- End Annotation Hierarchy -----------------------------
266:
267: public boolean visit(ArrayAccess node) {
268: return visit((Expression) node);
269: }
270:
271: public void endVisit(ArrayAccess node) {
272: endVisit((Expression) node);
273: }
274:
275: public boolean visit(ArrayCreation node) {
276: return visit((Expression) node);
277: }
278:
279: public void endVisit(ArrayCreation node) {
280: endVisit((Expression) node);
281: }
282:
283: public boolean visit(ArrayInitializer node) {
284: return visit((Expression) node);
285: }
286:
287: public void endVisit(ArrayInitializer node) {
288: endVisit((Expression) node);
289: }
290:
291: public boolean visit(Assignment node) {
292: return visit((Expression) node);
293: }
294:
295: public void endVisit(Assignment node) {
296: endVisit((Expression) node);
297: }
298:
299: public boolean visit(BooleanLiteral node) {
300: return visit((Expression) node);
301: }
302:
303: public void endVisit(BooleanLiteral node) {
304: endVisit((Expression) node);
305: }
306:
307: public boolean visit(CastExpression node) {
308: return visit((Expression) node);
309: }
310:
311: public void endVisit(CastExpression node) {
312: endVisit((Expression) node);
313: }
314:
315: public boolean visit(CharacterLiteral node) {
316: return visit((Expression) node);
317: }
318:
319: public void endVisit(CharacterLiteral node) {
320: endVisit((Expression) node);
321: }
322:
323: public boolean visit(ClassInstanceCreation node) {
324: return visit((Expression) node);
325: }
326:
327: public void endVisit(ClassInstanceCreation node) {
328: endVisit((Expression) node);
329: }
330:
331: public boolean visit(ConditionalExpression node) {
332: return visit((Expression) node);
333: }
334:
335: public void endVisit(ConditionalExpression node) {
336: endVisit((Expression) node);
337: }
338:
339: public boolean visit(FieldAccess node) {
340: return visit((Expression) node);
341: }
342:
343: public void endVisit(FieldAccess node) {
344: endVisit((Expression) node);
345: }
346:
347: public boolean visit(InfixExpression node) {
348: return visit((Expression) node);
349: }
350:
351: public void endVisit(InfixExpression node) {
352: endVisit((Expression) node);
353: }
354:
355: public boolean visit(InstanceofExpression node) {
356: return visit((Expression) node);
357: }
358:
359: public void endVisit(InstanceofExpression node) {
360: endVisit((Expression) node);
361: }
362:
363: public boolean visit(MethodInvocation node) {
364: return visit((Expression) node);
365: }
366:
367: public void endVisit(MethodInvocation node) {
368: endVisit((Expression) node);
369: }
370:
371: //---- Begin Name Hierarchy ----------------------------------
372: public boolean visit(Name node) {
373: return visit((Expression) node);
374: }
375:
376: public void endVisit(Name node) {
377: endVisit((Expression) node);
378: }
379:
380: public boolean visit(QualifiedName node) {
381: return visit((Name) node);
382: }
383:
384: public void endVisit(QualifiedName node) {
385: endVisit((Name) node);
386: }
387:
388: public boolean visit(SimpleName node) {
389: return visit((Name) node);
390: }
391:
392: public void endVisit(SimpleName node) {
393: endVisit((Name) node);
394: }
395:
396: //---- End Name Hierarchy ------------------------------------
397:
398: public boolean visit(NullLiteral node) {
399: return visit((Expression) node);
400: }
401:
402: public void endVisit(NullLiteral node) {
403: endVisit((Expression) node);
404: }
405:
406: public boolean visit(NumberLiteral node) {
407: return visit((Expression) node);
408: }
409:
410: public void endVisit(NumberLiteral node) {
411: endVisit((Expression) node);
412: }
413:
414: public boolean visit(ParenthesizedExpression node) {
415: return visit((Expression) node);
416: }
417:
418: public void endVisit(ParenthesizedExpression node) {
419: endVisit((Expression) node);
420: }
421:
422: public boolean visit(PostfixExpression node) {
423: return visit((Expression) node);
424: }
425:
426: public void endVisit(PostfixExpression node) {
427: endVisit((Expression) node);
428: }
429:
430: public boolean visit(PrefixExpression node) {
431: return visit((Expression) node);
432: }
433:
434: public void endVisit(PrefixExpression node) {
435: endVisit((Expression) node);
436: }
437:
438: public boolean visit(StringLiteral node) {
439: return visit((Expression) node);
440: }
441:
442: public void endVisit(StringLiteral node) {
443: endVisit((Expression) node);
444: }
445:
446: public boolean visit(SuperFieldAccess node) {
447: return visit((Expression) node);
448: }
449:
450: public void endVisit(SuperFieldAccess node) {
451: endVisit((Expression) node);
452: }
453:
454: public boolean visit(SuperMethodInvocation node) {
455: return visit((Expression) node);
456: }
457:
458: public void endVisit(SuperMethodInvocation node) {
459: endVisit((Expression) node);
460: }
461:
462: public boolean visit(ThisExpression node) {
463: return visit((Expression) node);
464: }
465:
466: public void endVisit(ThisExpression node) {
467: endVisit((Expression) node);
468: }
469:
470: public boolean visit(TypeLiteral node) {
471: return visit((Expression) node);
472: }
473:
474: public void endVisit(TypeLiteral node) {
475: endVisit((Expression) node);
476: }
477:
478: public boolean visit(VariableDeclarationExpression node) {
479: return visit((Expression) node);
480: }
481:
482: public void endVisit(VariableDeclarationExpression node) {
483: endVisit((Expression) node);
484: }
485:
486: //---- End Expression Hierarchy ----------------------------------
487:
488: public boolean visit(ImportDeclaration node) {
489: return visit((ASTNode) node);
490: }
491:
492: public void endVisit(ImportDeclaration node) {
493: endVisit((ASTNode) node);
494: }
495:
496: public boolean visit(MemberRef node) {
497: return visit((ASTNode) node);
498: }
499:
500: public void endVisit(MemberRef node) {
501: endVisit((ASTNode) node);
502: }
503:
504: public boolean visit(MemberValuePair node) {
505: return visit((ASTNode) node);
506: }
507:
508: public void endVisit(MemberValuePair node) {
509: endVisit((ASTNode) node);
510: }
511:
512: public boolean visit(MethodRef node) {
513: return visit((ASTNode) node);
514: }
515:
516: public void endVisit(MethodRef node) {
517: endVisit((ASTNode) node);
518: }
519:
520: public boolean visit(MethodRefParameter node) {
521: return visit((ASTNode) node);
522: }
523:
524: public void endVisit(MethodRefParameter node) {
525: endVisit((ASTNode) node);
526: }
527:
528: public boolean visit(Modifier node) {
529: return visit((ASTNode) node);
530: }
531:
532: public void endVisit(Modifier node) {
533: endVisit((ASTNode) node);
534: }
535:
536: public boolean visit(PackageDeclaration node) {
537: return visit((ASTNode) node);
538: }
539:
540: public void endVisit(PackageDeclaration node) {
541: endVisit((ASTNode) node);
542: }
543:
544: //---- Begin Statement Hierarchy ---------------------------------
545: public boolean visit(Statement node) {
546: return visit((ASTNode) node);
547: }
548:
549: public void endVisit(Statement node) {
550: endVisit((ASTNode) node);
551: }
552:
553: public boolean visit(AssertStatement node) {
554: return visit((Statement) node);
555: }
556:
557: public void endVisit(AssertStatement node) {
558: endVisit((Statement) node);
559: }
560:
561: public boolean visit(Block node) {
562: return visit((Statement) node);
563: }
564:
565: public void endVisit(Block node) {
566: endVisit((Statement) node);
567: }
568:
569: public boolean visit(BreakStatement node) {
570: return visit((Statement) node);
571: }
572:
573: public void endVisit(BreakStatement node) {
574: endVisit((Statement) node);
575: }
576:
577: public boolean visit(ConstructorInvocation node) {
578: return visit((Statement) node);
579: }
580:
581: public void endVisit(ConstructorInvocation node) {
582: endVisit((Statement) node);
583: }
584:
585: public boolean visit(ContinueStatement node) {
586: return visit((Statement) node);
587: }
588:
589: public void endVisit(ContinueStatement node) {
590: endVisit((Statement) node);
591: }
592:
593: public boolean visit(DoStatement node) {
594: return visit((Statement) node);
595: }
596:
597: public void endVisit(DoStatement node) {
598: endVisit((Statement) node);
599: }
600:
601: public boolean visit(EmptyStatement node) {
602: return visit((Statement) node);
603: }
604:
605: public void endVisit(EmptyStatement node) {
606: endVisit((Statement) node);
607: }
608:
609: public boolean visit(EnhancedForStatement node) {
610: return visit((Statement) node);
611: }
612:
613: public void endVisit(EnhancedForStatement node) {
614: endVisit((Statement) node);
615: }
616:
617: public boolean visit(ExpressionStatement node) {
618: return visit((Statement) node);
619: }
620:
621: public void endVisit(ExpressionStatement node) {
622: endVisit((Statement) node);
623: }
624:
625: public boolean visit(ForStatement node) {
626: return visit((Statement) node);
627: }
628:
629: public void endVisit(ForStatement node) {
630: endVisit((Statement) node);
631: }
632:
633: public boolean visit(IfStatement node) {
634: return visit((Statement) node);
635: }
636:
637: public void endVisit(IfStatement node) {
638: endVisit((Statement) node);
639: }
640:
641: public boolean visit(LabeledStatement node) {
642: return visit((Statement) node);
643: }
644:
645: public void endVisit(LabeledStatement node) {
646: endVisit((Statement) node);
647: }
648:
649: public boolean visit(ReturnStatement node) {
650: return visit((Statement) node);
651: }
652:
653: public void endVisit(ReturnStatement node) {
654: endVisit((Statement) node);
655: }
656:
657: public boolean visit(SuperConstructorInvocation node) {
658: return visit((Statement) node);
659: }
660:
661: public void endVisit(SuperConstructorInvocation node) {
662: endVisit((Statement) node);
663: }
664:
665: public boolean visit(SwitchCase node) {
666: return visit((Statement) node);
667: }
668:
669: public void endVisit(SwitchCase node) {
670: endVisit((Statement) node);
671: }
672:
673: public boolean visit(SwitchStatement node) {
674: return visit((Statement) node);
675: }
676:
677: public void endVisit(SwitchStatement node) {
678: endVisit((Statement) node);
679: }
680:
681: public boolean visit(SynchronizedStatement node) {
682: return visit((Statement) node);
683: }
684:
685: public void endVisit(SynchronizedStatement node) {
686: endVisit((Statement) node);
687: }
688:
689: public boolean visit(ThrowStatement node) {
690: return visit((Statement) node);
691: }
692:
693: public void endVisit(ThrowStatement node) {
694: endVisit((Statement) node);
695: }
696:
697: public boolean visit(TryStatement node) {
698: return visit((Statement) node);
699: }
700:
701: public void endVisit(TryStatement node) {
702: endVisit((Statement) node);
703: }
704:
705: public boolean visit(TypeDeclarationStatement node) {
706: return visit((Statement) node);
707: }
708:
709: public void endVisit(TypeDeclarationStatement node) {
710: endVisit((Statement) node);
711: }
712:
713: public boolean visit(VariableDeclarationStatement node) {
714: return visit((Statement) node);
715: }
716:
717: public void endVisit(VariableDeclarationStatement node) {
718: endVisit((Statement) node);
719: }
720:
721: public boolean visit(WhileStatement node) {
722: return visit((Statement) node);
723: }
724:
725: public void endVisit(WhileStatement node) {
726: endVisit((Statement) node);
727: }
728:
729: //---- End Statement Hierarchy ----------------------------------
730:
731: public boolean visit(TagElement node) {
732: return visit((ASTNode) node);
733: }
734:
735: public void endVisit(TagElement node) {
736: endVisit((ASTNode) node);
737: }
738:
739: public boolean visit(TextElement node) {
740: return visit((ASTNode) node);
741: }
742:
743: public void endVisit(TextElement node) {
744: endVisit((ASTNode) node);
745: }
746:
747: //---- Begin Type Hierarchy --------------------------------------
748: public boolean visit(Type node) {
749: return visit((ASTNode) node);
750: }
751:
752: public void endVisit(Type node) {
753: endVisit((ASTNode) node);
754: }
755:
756: public boolean visit(ArrayType node) {
757: return visit((Type) node);
758: }
759:
760: public void endVisit(ArrayType node) {
761: endVisit((Type) node);
762: }
763:
764: public boolean visit(ParameterizedType node) {
765: return visit((Type) node);
766: }
767:
768: public void endVisit(ParameterizedType node) {
769: endVisit((Type) node);
770: }
771:
772: public boolean visit(PrimitiveType node) {
773: return visit((Type) node);
774: }
775:
776: public void endVisit(PrimitiveType node) {
777: endVisit((Type) node);
778: }
779:
780: public boolean visit(QualifiedType node) {
781: return visit((Type) node);
782: }
783:
784: public void endVisit(QualifiedType node) {
785: endVisit((Type) node);
786: }
787:
788: public boolean visit(SimpleType node) {
789: return visit((Type) node);
790: }
791:
792: public void endVisit(SimpleType node) {
793: endVisit((Type) node);
794: }
795:
796: public boolean visit(WildcardType node) {
797: return visit((Type) node);
798: }
799:
800: public void endVisit(WildcardType node) {
801: endVisit((Type) node);
802: }
803:
804: //---- End Type Hierarchy ----------------------------------------
805:
806: public boolean visit(TypeParameter node) {
807: return visit((ASTNode) node);
808: }
809:
810: public void endVisit(TypeParameter node) {
811: endVisit((ASTNode) node);
812: }
813:
814: //---- Begin VariableDeclaration Hierarchy ---------------------------
815: public boolean visit(VariableDeclaration node) {
816: return visit((ASTNode) node);
817: }
818:
819: public void endVisit(VariableDeclaration node) {
820: endVisit((ASTNode) node);
821: }
822:
823: public boolean visit(SingleVariableDeclaration node) {
824: return visit((VariableDeclaration) node);
825: }
826:
827: public void endVisit(SingleVariableDeclaration node) {
828: endVisit((VariableDeclaration) node);
829: }
830:
831: public boolean visit(VariableDeclarationFragment node) {
832: return visit((VariableDeclaration) node);
833: }
834:
835: public void endVisit(VariableDeclarationFragment node) {
836: endVisit((VariableDeclaration) node);
837: }
838:
839: //---- End VariableDeclaration Hierarchy -----------------------------
840: //---- End ASTNode Hierarchy -----------------------------------------
841: }
|