src/share/classes/com/sun/tools/javac/tree/TreeScanner.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,339 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 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.tools.javac.tree;
    1.30 +
    1.31 +import com.sun.tools.javac.util.*;
    1.32 +import com.sun.tools.javac.tree.JCTree.*;
    1.33 +
    1.34 +/** A subclass of Tree.Visitor, this class defines
    1.35 + *  a general tree scanner pattern. Translation proceeds recursively in
    1.36 + *  left-to-right order down a tree. There is one visitor method in this class
    1.37 + *  for every possible kind of tree node.  To obtain a specific
    1.38 + *  scanner, it suffices to override those visitor methods which
    1.39 + *  do some interesting work. The scanner class itself takes care of all
    1.40 + *  navigational aspects.
    1.41 + *
    1.42 + *  <p><b>This is NOT part of any supported API.
    1.43 + *  If you write code that depends on this, you do so at your own risk.
    1.44 + *  This code and its internal interfaces are subject to change or
    1.45 + *  deletion without notice.</b>
    1.46 + */
    1.47 +public class TreeScanner extends Visitor {
    1.48 +
    1.49 +    /** Visitor method: Scan a single node.
    1.50 +     */
    1.51 +    public void scan(JCTree tree) {
    1.52 +        if(tree!=null) tree.accept(this);
    1.53 +    }
    1.54 +
    1.55 +    /** Visitor method: scan a list of nodes.
    1.56 +     */
    1.57 +    public void scan(List<? extends JCTree> trees) {
    1.58 +        if (trees != null)
    1.59 +        for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
    1.60 +            scan(l.head);
    1.61 +    }
    1.62 +
    1.63 +
    1.64 +/* ***************************************************************************
    1.65 + * Visitor methods
    1.66 + ****************************************************************************/
    1.67 +
    1.68 +    public void visitTopLevel(JCCompilationUnit tree) {
    1.69 +        scan(tree.packageAnnotations);
    1.70 +        scan(tree.pid);
    1.71 +        scan(tree.defs);
    1.72 +    }
    1.73 +
    1.74 +    public void visitImport(JCImport tree) {
    1.75 +        scan(tree.qualid);
    1.76 +    }
    1.77 +
    1.78 +    public void visitClassDef(JCClassDecl tree) {
    1.79 +        scan(tree.mods);
    1.80 +        scan(tree.typarams);
    1.81 +        scan(tree.extending);
    1.82 +        scan(tree.implementing);
    1.83 +        scan(tree.defs);
    1.84 +    }
    1.85 +
    1.86 +    public void visitMethodDef(JCMethodDecl tree) {
    1.87 +        scan(tree.mods);
    1.88 +        scan(tree.restype);
    1.89 +        scan(tree.typarams);
    1.90 +        scan(tree.recvparam);
    1.91 +        scan(tree.params);
    1.92 +        scan(tree.thrown);
    1.93 +        scan(tree.defaultValue);
    1.94 +        scan(tree.body);
    1.95 +    }
    1.96 +
    1.97 +    public void visitVarDef(JCVariableDecl tree) {
    1.98 +        scan(tree.mods);
    1.99 +        scan(tree.vartype);
   1.100 +        scan(tree.nameexpr);
   1.101 +        scan(tree.init);
   1.102 +    }
   1.103 +
   1.104 +    public void visitSkip(JCSkip tree) {
   1.105 +    }
   1.106 +
   1.107 +    public void visitBlock(JCBlock tree) {
   1.108 +        scan(tree.stats);
   1.109 +    }
   1.110 +
   1.111 +    public void visitDoLoop(JCDoWhileLoop tree) {
   1.112 +        scan(tree.body);
   1.113 +        scan(tree.cond);
   1.114 +    }
   1.115 +
   1.116 +    public void visitWhileLoop(JCWhileLoop tree) {
   1.117 +        scan(tree.cond);
   1.118 +        scan(tree.body);
   1.119 +    }
   1.120 +
   1.121 +    public void visitForLoop(JCForLoop tree) {
   1.122 +        scan(tree.init);
   1.123 +        scan(tree.cond);
   1.124 +        scan(tree.step);
   1.125 +        scan(tree.body);
   1.126 +    }
   1.127 +
   1.128 +    public void visitForeachLoop(JCEnhancedForLoop tree) {
   1.129 +        scan(tree.var);
   1.130 +        scan(tree.expr);
   1.131 +        scan(tree.body);
   1.132 +    }
   1.133 +
   1.134 +    public void visitLabelled(JCLabeledStatement tree) {
   1.135 +        scan(tree.body);
   1.136 +    }
   1.137 +
   1.138 +    public void visitSwitch(JCSwitch tree) {
   1.139 +        scan(tree.selector);
   1.140 +        scan(tree.cases);
   1.141 +    }
   1.142 +
   1.143 +    public void visitCase(JCCase tree) {
   1.144 +        scan(tree.pat);
   1.145 +        scan(tree.stats);
   1.146 +    }
   1.147 +
   1.148 +    public void visitSynchronized(JCSynchronized tree) {
   1.149 +        scan(tree.lock);
   1.150 +        scan(tree.body);
   1.151 +    }
   1.152 +
   1.153 +    public void visitTry(JCTry tree) {
   1.154 +        scan(tree.resources);
   1.155 +        scan(tree.body);
   1.156 +        scan(tree.catchers);
   1.157 +        scan(tree.finalizer);
   1.158 +    }
   1.159 +
   1.160 +    public void visitCatch(JCCatch tree) {
   1.161 +        scan(tree.param);
   1.162 +        scan(tree.body);
   1.163 +    }
   1.164 +
   1.165 +    public void visitConditional(JCConditional tree) {
   1.166 +        scan(tree.cond);
   1.167 +        scan(tree.truepart);
   1.168 +        scan(tree.falsepart);
   1.169 +    }
   1.170 +
   1.171 +    public void visitIf(JCIf tree) {
   1.172 +        scan(tree.cond);
   1.173 +        scan(tree.thenpart);
   1.174 +        scan(tree.elsepart);
   1.175 +    }
   1.176 +
   1.177 +    public void visitExec(JCExpressionStatement tree) {
   1.178 +        scan(tree.expr);
   1.179 +    }
   1.180 +
   1.181 +    public void visitBreak(JCBreak tree) {
   1.182 +    }
   1.183 +
   1.184 +    public void visitContinue(JCContinue tree) {
   1.185 +    }
   1.186 +
   1.187 +    public void visitReturn(JCReturn tree) {
   1.188 +        scan(tree.expr);
   1.189 +    }
   1.190 +
   1.191 +    public void visitThrow(JCThrow tree) {
   1.192 +        scan(tree.expr);
   1.193 +    }
   1.194 +
   1.195 +    public void visitAssert(JCAssert tree) {
   1.196 +        scan(tree.cond);
   1.197 +        scan(tree.detail);
   1.198 +    }
   1.199 +
   1.200 +    public void visitApply(JCMethodInvocation tree) {
   1.201 +        scan(tree.typeargs);
   1.202 +        scan(tree.meth);
   1.203 +        scan(tree.args);
   1.204 +    }
   1.205 +
   1.206 +    public void visitNewClass(JCNewClass tree) {
   1.207 +        scan(tree.encl);
   1.208 +        scan(tree.typeargs);
   1.209 +        scan(tree.clazz);
   1.210 +        scan(tree.args);
   1.211 +        scan(tree.def);
   1.212 +    }
   1.213 +
   1.214 +    public void visitNewArray(JCNewArray tree) {
   1.215 +        scan(tree.annotations);
   1.216 +        scan(tree.elemtype);
   1.217 +        scan(tree.dims);
   1.218 +        for (List<JCAnnotation> annos : tree.dimAnnotations)
   1.219 +            scan(annos);
   1.220 +        scan(tree.elems);
   1.221 +    }
   1.222 +
   1.223 +    public void visitLambda(JCLambda tree) {
   1.224 +        scan(tree.body);
   1.225 +        scan(tree.params);
   1.226 +    }
   1.227 +
   1.228 +    public void visitParens(JCParens tree) {
   1.229 +        scan(tree.expr);
   1.230 +    }
   1.231 +
   1.232 +    public void visitAssign(JCAssign tree) {
   1.233 +        scan(tree.lhs);
   1.234 +        scan(tree.rhs);
   1.235 +    }
   1.236 +
   1.237 +    public void visitAssignop(JCAssignOp tree) {
   1.238 +        scan(tree.lhs);
   1.239 +        scan(tree.rhs);
   1.240 +    }
   1.241 +
   1.242 +    public void visitUnary(JCUnary tree) {
   1.243 +        scan(tree.arg);
   1.244 +    }
   1.245 +
   1.246 +    public void visitBinary(JCBinary tree) {
   1.247 +        scan(tree.lhs);
   1.248 +        scan(tree.rhs);
   1.249 +    }
   1.250 +
   1.251 +    public void visitTypeCast(JCTypeCast tree) {
   1.252 +        scan(tree.clazz);
   1.253 +        scan(tree.expr);
   1.254 +    }
   1.255 +
   1.256 +    public void visitTypeTest(JCInstanceOf tree) {
   1.257 +        scan(tree.expr);
   1.258 +        scan(tree.clazz);
   1.259 +    }
   1.260 +
   1.261 +    public void visitIndexed(JCArrayAccess tree) {
   1.262 +        scan(tree.indexed);
   1.263 +        scan(tree.index);
   1.264 +    }
   1.265 +
   1.266 +    public void visitSelect(JCFieldAccess tree) {
   1.267 +        scan(tree.selected);
   1.268 +    }
   1.269 +
   1.270 +    public void visitReference(JCMemberReference tree) {
   1.271 +        scan(tree.expr);
   1.272 +        scan(tree.typeargs);
   1.273 +    }
   1.274 +
   1.275 +    public void visitIdent(JCIdent tree) {
   1.276 +    }
   1.277 +
   1.278 +    public void visitLiteral(JCLiteral tree) {
   1.279 +    }
   1.280 +
   1.281 +    public void visitTypeIdent(JCPrimitiveTypeTree tree) {
   1.282 +    }
   1.283 +
   1.284 +    public void visitTypeArray(JCArrayTypeTree tree) {
   1.285 +        scan(tree.elemtype);
   1.286 +    }
   1.287 +
   1.288 +    public void visitTypeApply(JCTypeApply tree) {
   1.289 +        scan(tree.clazz);
   1.290 +        scan(tree.arguments);
   1.291 +    }
   1.292 +
   1.293 +    public void visitTypeUnion(JCTypeUnion tree) {
   1.294 +        scan(tree.alternatives);
   1.295 +    }
   1.296 +
   1.297 +    public void visitTypeIntersection(JCTypeIntersection tree) {
   1.298 +        scan(tree.bounds);
   1.299 +    }
   1.300 +
   1.301 +    public void visitTypeParameter(JCTypeParameter tree) {
   1.302 +        scan(tree.annotations);
   1.303 +        scan(tree.bounds);
   1.304 +    }
   1.305 +
   1.306 +    @Override
   1.307 +    public void visitWildcard(JCWildcard tree) {
   1.308 +        scan(tree.kind);
   1.309 +        if (tree.inner != null)
   1.310 +            scan(tree.inner);
   1.311 +    }
   1.312 +
   1.313 +    @Override
   1.314 +    public void visitTypeBoundKind(TypeBoundKind that) {
   1.315 +    }
   1.316 +
   1.317 +    public void visitModifiers(JCModifiers tree) {
   1.318 +        scan(tree.annotations);
   1.319 +    }
   1.320 +
   1.321 +    public void visitAnnotation(JCAnnotation tree) {
   1.322 +        scan(tree.annotationType);
   1.323 +        scan(tree.args);
   1.324 +    }
   1.325 +
   1.326 +    public void visitAnnotatedType(JCAnnotatedType tree) {
   1.327 +        scan(tree.annotations);
   1.328 +        scan(tree.underlyingType);
   1.329 +    }
   1.330 +
   1.331 +    public void visitErroneous(JCErroneous tree) {
   1.332 +    }
   1.333 +
   1.334 +    public void visitLetExpr(LetExpr tree) {
   1.335 +        scan(tree.defs);
   1.336 +        scan(tree.expr);
   1.337 +    }
   1.338 +
   1.339 +    public void visitTree(JCTree tree) {
   1.340 +        Assert.error();
   1.341 +    }
   1.342 +}

mercurial