1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,254 @@ 1.4 +/* 1.5 + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.source.util; 1.30 + 1.31 +import com.sun.source.tree.*; 1.32 + 1.33 +/** 1.34 + * A simple visitor for tree nodes. 1.35 + * 1.36 + * @author Peter von der Ahé 1.37 + * @since 1.6 1.38 + */ 1.39 +public class SimpleTreeVisitor <R,P> implements TreeVisitor<R,P> { 1.40 + protected final R DEFAULT_VALUE; 1.41 + 1.42 + protected SimpleTreeVisitor() { 1.43 + DEFAULT_VALUE = null; 1.44 + } 1.45 + 1.46 + protected SimpleTreeVisitor(R defaultValue) { 1.47 + DEFAULT_VALUE = defaultValue; 1.48 + } 1.49 + 1.50 + protected R defaultAction(Tree node, P p) { 1.51 + return DEFAULT_VALUE; 1.52 + } 1.53 + 1.54 + public final R visit(Tree node, P p) { 1.55 + return (node == null) ? null : node.accept(this, p); 1.56 + } 1.57 + 1.58 + public final R visit(Iterable<? extends Tree> nodes, P p) { 1.59 + R r = null; 1.60 + if (nodes != null) 1.61 + for (Tree node : nodes) 1.62 + r = visit(node, p); 1.63 + return r; 1.64 + } 1.65 + 1.66 + public R visitCompilationUnit(CompilationUnitTree node, P p) { 1.67 + return defaultAction(node, p); 1.68 + } 1.69 + 1.70 + public R visitImport(ImportTree node, P p) { 1.71 + return defaultAction(node, p); 1.72 + } 1.73 + 1.74 + public R visitClass(ClassTree node, P p) { 1.75 + return defaultAction(node, p); 1.76 + } 1.77 + 1.78 + public R visitMethod(MethodTree node, P p) { 1.79 + return defaultAction(node, p); 1.80 + } 1.81 + 1.82 + public R visitVariable(VariableTree node, P p) { 1.83 + return defaultAction(node, p); 1.84 + } 1.85 + 1.86 + public R visitEmptyStatement(EmptyStatementTree node, P p) { 1.87 + return defaultAction(node, p); 1.88 + } 1.89 + 1.90 + public R visitBlock(BlockTree node, P p) { 1.91 + return defaultAction(node, p); 1.92 + } 1.93 + 1.94 + public R visitDoWhileLoop(DoWhileLoopTree node, P p) { 1.95 + return defaultAction(node, p); 1.96 + } 1.97 + 1.98 + public R visitWhileLoop(WhileLoopTree node, P p) { 1.99 + return defaultAction(node, p); 1.100 + } 1.101 + 1.102 + public R visitForLoop(ForLoopTree node, P p) { 1.103 + return defaultAction(node, p); 1.104 + } 1.105 + 1.106 + public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) { 1.107 + return defaultAction(node, p); 1.108 + } 1.109 + 1.110 + public R visitLabeledStatement(LabeledStatementTree node, P p) { 1.111 + return defaultAction(node, p); 1.112 + } 1.113 + 1.114 + public R visitSwitch(SwitchTree node, P p) { 1.115 + return defaultAction(node, p); 1.116 + } 1.117 + 1.118 + public R visitCase(CaseTree node, P p) { 1.119 + return defaultAction(node, p); 1.120 + } 1.121 + 1.122 + public R visitSynchronized(SynchronizedTree node, P p) { 1.123 + return defaultAction(node, p); 1.124 + } 1.125 + 1.126 + public R visitTry(TryTree node, P p) { 1.127 + return defaultAction(node, p); 1.128 + } 1.129 + 1.130 + public R visitCatch(CatchTree node, P p) { 1.131 + return defaultAction(node, p); 1.132 + } 1.133 + 1.134 + public R visitConditionalExpression(ConditionalExpressionTree node, P p) { 1.135 + return defaultAction(node, p); 1.136 + } 1.137 + 1.138 + public R visitIf(IfTree node, P p) { 1.139 + return defaultAction(node, p); 1.140 + } 1.141 + 1.142 + public R visitExpressionStatement(ExpressionStatementTree node, P p) { 1.143 + return defaultAction(node, p); 1.144 + } 1.145 + 1.146 + public R visitBreak(BreakTree node, P p) { 1.147 + return defaultAction(node, p); 1.148 + } 1.149 + 1.150 + public R visitContinue(ContinueTree node, P p) { 1.151 + return defaultAction(node, p); 1.152 + } 1.153 + 1.154 + public R visitReturn(ReturnTree node, P p) { 1.155 + return defaultAction(node, p); 1.156 + } 1.157 + 1.158 + public R visitThrow(ThrowTree node, P p) { 1.159 + return defaultAction(node, p); 1.160 + } 1.161 + 1.162 + public R visitAssert(AssertTree node, P p) { 1.163 + return defaultAction(node, p); 1.164 + } 1.165 + 1.166 + public R visitMethodInvocation(MethodInvocationTree node, P p) { 1.167 + return defaultAction(node, p); 1.168 + } 1.169 + 1.170 + public R visitNewClass(NewClassTree node, P p) { 1.171 + return defaultAction(node, p); 1.172 + } 1.173 + 1.174 + public R visitNewArray(NewArrayTree node, P p) { 1.175 + return defaultAction(node, p); 1.176 + } 1.177 + 1.178 + public R visitParenthesized(ParenthesizedTree node, P p) { 1.179 + return defaultAction(node, p); 1.180 + } 1.181 + 1.182 + public R visitAssignment(AssignmentTree node, P p) { 1.183 + return defaultAction(node, p); 1.184 + } 1.185 + 1.186 + public R visitCompoundAssignment(CompoundAssignmentTree node, P p) { 1.187 + return defaultAction(node, p); 1.188 + } 1.189 + 1.190 + public R visitUnary(UnaryTree node, P p) { 1.191 + return defaultAction(node, p); 1.192 + } 1.193 + 1.194 + public R visitBinary(BinaryTree node, P p) { 1.195 + return defaultAction(node, p); 1.196 + } 1.197 + 1.198 + public R visitTypeCast(TypeCastTree node, P p) { 1.199 + return defaultAction(node, p); 1.200 + } 1.201 + 1.202 + public R visitInstanceOf(InstanceOfTree node, P p) { 1.203 + return defaultAction(node, p); 1.204 + } 1.205 + 1.206 + public R visitArrayAccess(ArrayAccessTree node, P p) { 1.207 + return defaultAction(node, p); 1.208 + } 1.209 + 1.210 + public R visitMemberSelect(MemberSelectTree node, P p) { 1.211 + return defaultAction(node, p); 1.212 + } 1.213 + 1.214 + public R visitIdentifier(IdentifierTree node, P p) { 1.215 + return defaultAction(node, p); 1.216 + } 1.217 + 1.218 + public R visitLiteral(LiteralTree node, P p) { 1.219 + return defaultAction(node, p); 1.220 + } 1.221 + 1.222 + public R visitPrimitiveType(PrimitiveTypeTree node, P p) { 1.223 + return defaultAction(node, p); 1.224 + } 1.225 + 1.226 + public R visitArrayType(ArrayTypeTree node, P p) { 1.227 + return defaultAction(node, p); 1.228 + } 1.229 + 1.230 + public R visitParameterizedType(ParameterizedTypeTree node, P p) { 1.231 + return defaultAction(node, p); 1.232 + } 1.233 + 1.234 + public R visitTypeParameter(TypeParameterTree node, P p) { 1.235 + return defaultAction(node, p); 1.236 + } 1.237 + 1.238 + public R visitWildcard(WildcardTree node, P p) { 1.239 + return defaultAction(node, p); 1.240 + } 1.241 + 1.242 + public R visitModifiers(ModifiersTree node, P p) { 1.243 + return defaultAction(node, p); 1.244 + } 1.245 + 1.246 + public R visitAnnotation(AnnotationTree node, P p) { 1.247 + return defaultAction(node, p); 1.248 + } 1.249 + 1.250 + public R visitErroneous(ErroneousTree node, P p) { 1.251 + return defaultAction(node, p); 1.252 + } 1.253 + 1.254 + public R visitOther(Tree node, P p) { 1.255 + return defaultAction(node, p); 1.256 + } 1.257 +}