1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,275 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * 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 +@jdk.Exported 1.40 +public class SimpleTreeVisitor <R,P> implements TreeVisitor<R,P> { 1.41 + protected final R DEFAULT_VALUE; 1.42 + 1.43 + protected SimpleTreeVisitor() { 1.44 + DEFAULT_VALUE = null; 1.45 + } 1.46 + 1.47 + protected SimpleTreeVisitor(R defaultValue) { 1.48 + DEFAULT_VALUE = defaultValue; 1.49 + } 1.50 + 1.51 + protected R defaultAction(Tree node, P p) { 1.52 + return DEFAULT_VALUE; 1.53 + } 1.54 + 1.55 + public final R visit(Tree node, P p) { 1.56 + return (node == null) ? null : node.accept(this, p); 1.57 + } 1.58 + 1.59 + public final R visit(Iterable<? extends Tree> nodes, P p) { 1.60 + R r = null; 1.61 + if (nodes != null) 1.62 + for (Tree node : nodes) 1.63 + r = visit(node, p); 1.64 + return r; 1.65 + } 1.66 + 1.67 + public R visitCompilationUnit(CompilationUnitTree node, P p) { 1.68 + return defaultAction(node, p); 1.69 + } 1.70 + 1.71 + public R visitImport(ImportTree node, P p) { 1.72 + return defaultAction(node, p); 1.73 + } 1.74 + 1.75 + public R visitClass(ClassTree node, P p) { 1.76 + return defaultAction(node, p); 1.77 + } 1.78 + 1.79 + public R visitMethod(MethodTree node, P p) { 1.80 + return defaultAction(node, p); 1.81 + } 1.82 + 1.83 + public R visitVariable(VariableTree node, P p) { 1.84 + return defaultAction(node, p); 1.85 + } 1.86 + 1.87 + public R visitEmptyStatement(EmptyStatementTree node, P p) { 1.88 + return defaultAction(node, p); 1.89 + } 1.90 + 1.91 + public R visitBlock(BlockTree node, P p) { 1.92 + return defaultAction(node, p); 1.93 + } 1.94 + 1.95 + public R visitDoWhileLoop(DoWhileLoopTree node, P p) { 1.96 + return defaultAction(node, p); 1.97 + } 1.98 + 1.99 + public R visitWhileLoop(WhileLoopTree node, P p) { 1.100 + return defaultAction(node, p); 1.101 + } 1.102 + 1.103 + public R visitForLoop(ForLoopTree node, P p) { 1.104 + return defaultAction(node, p); 1.105 + } 1.106 + 1.107 + public R visitEnhancedForLoop(EnhancedForLoopTree node, P p) { 1.108 + return defaultAction(node, p); 1.109 + } 1.110 + 1.111 + public R visitLabeledStatement(LabeledStatementTree node, P p) { 1.112 + return defaultAction(node, p); 1.113 + } 1.114 + 1.115 + public R visitSwitch(SwitchTree node, P p) { 1.116 + return defaultAction(node, p); 1.117 + } 1.118 + 1.119 + public R visitCase(CaseTree node, P p) { 1.120 + return defaultAction(node, p); 1.121 + } 1.122 + 1.123 + public R visitSynchronized(SynchronizedTree node, P p) { 1.124 + return defaultAction(node, p); 1.125 + } 1.126 + 1.127 + public R visitTry(TryTree node, P p) { 1.128 + return defaultAction(node, p); 1.129 + } 1.130 + 1.131 + public R visitCatch(CatchTree node, P p) { 1.132 + return defaultAction(node, p); 1.133 + } 1.134 + 1.135 + public R visitConditionalExpression(ConditionalExpressionTree node, P p) { 1.136 + return defaultAction(node, p); 1.137 + } 1.138 + 1.139 + public R visitIf(IfTree node, P p) { 1.140 + return defaultAction(node, p); 1.141 + } 1.142 + 1.143 + public R visitExpressionStatement(ExpressionStatementTree node, P p) { 1.144 + return defaultAction(node, p); 1.145 + } 1.146 + 1.147 + public R visitBreak(BreakTree node, P p) { 1.148 + return defaultAction(node, p); 1.149 + } 1.150 + 1.151 + public R visitContinue(ContinueTree node, P p) { 1.152 + return defaultAction(node, p); 1.153 + } 1.154 + 1.155 + public R visitReturn(ReturnTree node, P p) { 1.156 + return defaultAction(node, p); 1.157 + } 1.158 + 1.159 + public R visitThrow(ThrowTree node, P p) { 1.160 + return defaultAction(node, p); 1.161 + } 1.162 + 1.163 + public R visitAssert(AssertTree node, P p) { 1.164 + return defaultAction(node, p); 1.165 + } 1.166 + 1.167 + public R visitMethodInvocation(MethodInvocationTree node, P p) { 1.168 + return defaultAction(node, p); 1.169 + } 1.170 + 1.171 + public R visitNewClass(NewClassTree node, P p) { 1.172 + return defaultAction(node, p); 1.173 + } 1.174 + 1.175 + public R visitNewArray(NewArrayTree node, P p) { 1.176 + return defaultAction(node, p); 1.177 + } 1.178 + 1.179 + public R visitLambdaExpression(LambdaExpressionTree node, P p) { 1.180 + return defaultAction(node, p); 1.181 + } 1.182 + 1.183 + public R visitParenthesized(ParenthesizedTree node, P p) { 1.184 + return defaultAction(node, p); 1.185 + } 1.186 + 1.187 + public R visitAssignment(AssignmentTree node, P p) { 1.188 + return defaultAction(node, p); 1.189 + } 1.190 + 1.191 + public R visitCompoundAssignment(CompoundAssignmentTree node, P p) { 1.192 + return defaultAction(node, p); 1.193 + } 1.194 + 1.195 + public R visitUnary(UnaryTree node, P p) { 1.196 + return defaultAction(node, p); 1.197 + } 1.198 + 1.199 + public R visitBinary(BinaryTree node, P p) { 1.200 + return defaultAction(node, p); 1.201 + } 1.202 + 1.203 + public R visitTypeCast(TypeCastTree node, P p) { 1.204 + return defaultAction(node, p); 1.205 + } 1.206 + 1.207 + public R visitInstanceOf(InstanceOfTree node, P p) { 1.208 + return defaultAction(node, p); 1.209 + } 1.210 + 1.211 + public R visitArrayAccess(ArrayAccessTree node, P p) { 1.212 + return defaultAction(node, p); 1.213 + } 1.214 + 1.215 + public R visitMemberSelect(MemberSelectTree node, P p) { 1.216 + return defaultAction(node, p); 1.217 + } 1.218 + 1.219 + public R visitMemberReference(MemberReferenceTree node, P p) { 1.220 + return defaultAction(node, p); 1.221 + } 1.222 + 1.223 + public R visitIdentifier(IdentifierTree node, P p) { 1.224 + return defaultAction(node, p); 1.225 + } 1.226 + 1.227 + public R visitLiteral(LiteralTree node, P p) { 1.228 + return defaultAction(node, p); 1.229 + } 1.230 + 1.231 + public R visitPrimitiveType(PrimitiveTypeTree node, P p) { 1.232 + return defaultAction(node, p); 1.233 + } 1.234 + 1.235 + public R visitArrayType(ArrayTypeTree node, P p) { 1.236 + return defaultAction(node, p); 1.237 + } 1.238 + 1.239 + public R visitParameterizedType(ParameterizedTypeTree node, P p) { 1.240 + return defaultAction(node, p); 1.241 + } 1.242 + 1.243 + public R visitUnionType(UnionTypeTree node, P p) { 1.244 + return defaultAction(node, p); 1.245 + } 1.246 + 1.247 + public R visitIntersectionType(IntersectionTypeTree node, P p) { 1.248 + return defaultAction(node, p); 1.249 + } 1.250 + 1.251 + public R visitTypeParameter(TypeParameterTree node, P p) { 1.252 + return defaultAction(node, p); 1.253 + } 1.254 + 1.255 + public R visitWildcard(WildcardTree node, P p) { 1.256 + return defaultAction(node, p); 1.257 + } 1.258 + 1.259 + public R visitModifiers(ModifiersTree node, P p) { 1.260 + return defaultAction(node, p); 1.261 + } 1.262 + 1.263 + public R visitAnnotation(AnnotationTree node, P p) { 1.264 + return defaultAction(node, p); 1.265 + } 1.266 + 1.267 + public R visitAnnotatedType(AnnotatedTypeTree node, P p) { 1.268 + return defaultAction(node, p); 1.269 + } 1.270 + 1.271 + public R visitErroneous(ErroneousTree node, P p) { 1.272 + return defaultAction(node, p); 1.273 + } 1.274 + 1.275 + public R visitOther(Tree node, P p) { 1.276 + return defaultAction(node, p); 1.277 + } 1.278 +}