1 /*
   2  * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package com.sun.source.util;
  27 
  28 import com.sun.source.tree.*;
  29 
  30 /**
  31  * A simple visitor for tree nodes.
  32  *
  33  * @author Peter von der Ahé
  34  * @since 1.6
  35  */
  36 public class SimpleTreeVisitor <R,P> implements TreeVisitor<R,P> {
  37     protected final R DEFAULT_VALUE;
  38 
  39     protected SimpleTreeVisitor() {
  40         DEFAULT_VALUE = null;
  41     }
  42 
  43     protected SimpleTreeVisitor(R defaultValue) {
  44         DEFAULT_VALUE = defaultValue;
  45     }
  46 
  47     protected R defaultAction(Tree node, P p) {
  48         return DEFAULT_VALUE;
  49     }
  50 
  51     public final R visit(Tree node, P p) {
  52         return (node == null) ? null : node.accept(this, p);
  53     }
  54 
  55     public final R visit(Iterable<? extends Tree> nodes, P p) {
  56         R r = null;
  57         if (nodes != null)
  58             for (Tree node : nodes)
  59                 r = visit(node, p);
  60         return r;
  61     }
  62 
  63     public R visitCompilationUnit(CompilationUnitTree node, P p) {
  64         return defaultAction(node, p);
  65     }
  66 
  67     public R visitImport(ImportTree node, P p) {
  68         return defaultAction(node, p);
  69     }
  70 
  71     public R visitClass(ClassTree node, P p) {
  72         return defaultAction(node, p);
  73     }
  74 
  75     public R visitMethod(MethodTree node, P p) {
  76         return defaultAction(node, p);
  77     }
  78 
  79     public R visitVariable(VariableTree node, P p) {
  80         return defaultAction(node, p);
  81     }
  82 
  83     public R visitEmptyStatement(EmptyStatementTree node, P p) {
  84         return defaultAction(node, p);
  85     }
  86 
  87     public R visitBlock(BlockTree node, P p) {
  88         return defaultAction(node, p);
  89     }
  90 
  91     public R visitDoWhileLoop(DoWhileLoopTree node, P p) {
  92         return defaultAction(node, p);
  93     }
  94 
  95     public R visitWhileLoop(WhileLoopTree node, P p) {
  96         return defaultAction(node, p);
  97     }
  98 
  99     public R visitForLoop(ForLoopTree node, P p) {
 100         return defaultAction(node, p);
 101     }
 102 
 103     public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) {
 104         return defaultAction(node, p);
 105     }
 106 
 107     public R visitLabeledStatement(LabeledStatementTree node, P p) {
 108         return defaultAction(node, p);
 109     }
 110 
 111     public R visitSwitch(SwitchTree node, P p) {
 112         return defaultAction(node, p);
 113     }
 114 
 115     public R visitCase(CaseTree node, P p) {
 116         return defaultAction(node, p);
 117     }
 118 
 119     public R visitSynchronized(SynchronizedTree node, P p) {
 120         return defaultAction(node, p);
 121     }
 122 
 123     public R visitTry(TryTree node, P p) {
 124         return defaultAction(node, p);
 125     }
 126 
 127     public R visitCatch(CatchTree node, P p) {
 128         return defaultAction(node, p);
 129     }
 130 
 131     public R visitConditionalExpression(ConditionalExpressionTree node, P p) {
 132         return defaultAction(node, p);
 133     }
 134 
 135     public R visitIf(IfTree node, P p) {
 136         return defaultAction(node, p);
 137     }
 138 
 139     public R visitExpressionStatement(ExpressionStatementTree node, P p) {
 140         return defaultAction(node, p);
 141     }
 142 
 143     public R visitBreak(BreakTree node, P p) {
 144         return defaultAction(node, p);
 145     }
 146 
 147     public R visitContinue(ContinueTree node, P p) {
 148         return defaultAction(node, p);
 149     }
 150 
 151     public R visitReturn(ReturnTree node, P p) {
 152         return defaultAction(node, p);
 153     }
 154 
 155     public R visitThrow(ThrowTree node, P p) {
 156         return defaultAction(node, p);
 157     }
 158 
 159     public R visitAssert(AssertTree node, P p) {
 160         return defaultAction(node, p);
 161     }
 162 
 163     public R visitMethodInvocation(MethodInvocationTree node, P p) {
 164         return defaultAction(node, p);
 165     }
 166 
 167     public R visitNewClass(NewClassTree node, P p) {
 168         return defaultAction(node, p);
 169     }
 170 
 171     public R visitNewArray(NewArrayTree node, P p) {
 172         return defaultAction(node, p);
 173     }
 174 
 175     public R visitParenthesized(ParenthesizedTree node, P p) {
 176         return defaultAction(node, p);
 177     }
 178 
 179     public R visitAssignment(AssignmentTree node, P p) {
 180         return defaultAction(node, p);
 181     }
 182 
 183     public R visitCompoundAssignment(CompoundAssignmentTree node, P p) {
 184         return defaultAction(node, p);
 185     }
 186 
 187     public R visitUnary(UnaryTree node, P p) {
 188         return defaultAction(node, p);
 189     }
 190 
 191     public R visitBinary(BinaryTree node, P p) {
 192         return defaultAction(node, p);
 193     }
 194 
 195     public R visitTypeCast(TypeCastTree node, P p) {
 196         return defaultAction(node, p);
 197     }
 198 
 199     public R visitInstanceOf(InstanceOfTree node, P p) {
 200         return defaultAction(node, p);
 201     }
 202 
 203     public R visitArrayAccess(ArrayAccessTree node, P p) {
 204         return defaultAction(node, p);
 205     }
 206 
 207     public R visitMemberSelect(MemberSelectTree node, P p) {
 208         return defaultAction(node, p);
 209     }
 210 
 211     public R visitIdentifier(IdentifierTree node, P p) {
 212         return defaultAction(node, p);
 213     }
 214 
 215     public R visitLiteral(LiteralTree node, P p) {
 216         return defaultAction(node, p);
 217     }
 218 
 219     public R visitPrimitiveType(PrimitiveTypeTree node, P p) {
 220         return defaultAction(node, p);
 221     }
 222 
 223     public R visitArrayType(ArrayTypeTree node, P p) {
 224         return defaultAction(node, p);
 225     }
 226 
 227     public R visitParameterizedType(ParameterizedTypeTree node, P p) {
 228         return defaultAction(node, p);
 229     }
 230 
 231     public R visitTypeParameter(TypeParameterTree node, P p) {
 232         return defaultAction(node, p);
 233     }
 234 
 235     public R visitWildcard(WildcardTree node, P p) {
 236         return defaultAction(node, p);
 237     }
 238 
 239     public R visitModifiers(ModifiersTree node, P p) {
 240         return defaultAction(node, p);
 241     }
 242 
 243     public R visitAnnotation(AnnotationTree node, P p) {
 244         return defaultAction(node, p);
 245     }
 246 
 247     public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
 248         return defaultAction(node, p);
 249     }
 250 
 251     public R visitErroneous(ErroneousTree node, P p) {
 252         return defaultAction(node, p);
 253     }
 254 
 255     public R visitOther(Tree node, P p) {
 256         return defaultAction(node, p);
 257     }
 258 }