Tue, 25 Sep 2012 13:11:05 -0700
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
Reviewed-by: mcimadamore
1 /*
2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javac.tree;
28 import com.sun.tools.javac.util.*;
29 import com.sun.tools.javac.tree.JCTree.*;
31 /** A subclass of Tree.Visitor, this class defines
32 * a general tree scanner pattern. Translation proceeds recursively in
33 * left-to-right order down a tree. There is one visitor method in this class
34 * for every possible kind of tree node. To obtain a specific
35 * scanner, it suffices to override those visitor methods which
36 * do some interesting work. The scanner class itself takes care of all
37 * navigational aspects.
38 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 */
44 public class TreeScanner extends Visitor {
46 /** Visitor method: Scan a single node.
47 */
48 public void scan(JCTree tree) {
49 if(tree!=null) tree.accept(this);
50 }
52 /** Visitor method: scan a list of nodes.
53 */
54 public void scan(List<? extends JCTree> trees) {
55 if (trees != null)
56 for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
57 scan(l.head);
58 }
61 /* ***************************************************************************
62 * Visitor methods
63 ****************************************************************************/
65 public void visitTopLevel(JCCompilationUnit tree) {
66 scan(tree.packageAnnotations);
67 scan(tree.pid);
68 scan(tree.defs);
69 }
71 public void visitImport(JCImport tree) {
72 scan(tree.qualid);
73 }
75 public void visitClassDef(JCClassDecl tree) {
76 scan(tree.mods);
77 scan(tree.typarams);
78 scan(tree.extending);
79 scan(tree.implementing);
80 scan(tree.defs);
81 }
83 public void visitMethodDef(JCMethodDecl tree) {
84 scan(tree.mods);
85 scan(tree.restype);
86 scan(tree.typarams);
87 scan(tree.params);
88 scan(tree.thrown);
89 scan(tree.defaultValue);
90 scan(tree.body);
91 }
93 public void visitVarDef(JCVariableDecl tree) {
94 scan(tree.mods);
95 scan(tree.vartype);
96 scan(tree.init);
97 }
99 public void visitSkip(JCSkip tree) {
100 }
102 public void visitBlock(JCBlock tree) {
103 scan(tree.stats);
104 }
106 public void visitDoLoop(JCDoWhileLoop tree) {
107 scan(tree.body);
108 scan(tree.cond);
109 }
111 public void visitWhileLoop(JCWhileLoop tree) {
112 scan(tree.cond);
113 scan(tree.body);
114 }
116 public void visitForLoop(JCForLoop tree) {
117 scan(tree.init);
118 scan(tree.cond);
119 scan(tree.step);
120 scan(tree.body);
121 }
123 public void visitForeachLoop(JCEnhancedForLoop tree) {
124 scan(tree.var);
125 scan(tree.expr);
126 scan(tree.body);
127 }
129 public void visitLabelled(JCLabeledStatement tree) {
130 scan(tree.body);
131 }
133 public void visitSwitch(JCSwitch tree) {
134 scan(tree.selector);
135 scan(tree.cases);
136 }
138 public void visitCase(JCCase tree) {
139 scan(tree.pat);
140 scan(tree.stats);
141 }
143 public void visitSynchronized(JCSynchronized tree) {
144 scan(tree.lock);
145 scan(tree.body);
146 }
148 public void visitTry(JCTry tree) {
149 scan(tree.resources);
150 scan(tree.body);
151 scan(tree.catchers);
152 scan(tree.finalizer);
153 }
155 public void visitCatch(JCCatch tree) {
156 scan(tree.param);
157 scan(tree.body);
158 }
160 public void visitConditional(JCConditional tree) {
161 scan(tree.cond);
162 scan(tree.truepart);
163 scan(tree.falsepart);
164 }
166 public void visitIf(JCIf tree) {
167 scan(tree.cond);
168 scan(tree.thenpart);
169 scan(tree.elsepart);
170 }
172 public void visitExec(JCExpressionStatement tree) {
173 scan(tree.expr);
174 }
176 public void visitBreak(JCBreak tree) {
177 }
179 public void visitContinue(JCContinue tree) {
180 }
182 public void visitReturn(JCReturn tree) {
183 scan(tree.expr);
184 }
186 public void visitThrow(JCThrow tree) {
187 scan(tree.expr);
188 }
190 public void visitAssert(JCAssert tree) {
191 scan(tree.cond);
192 scan(tree.detail);
193 }
195 public void visitApply(JCMethodInvocation tree) {
196 scan(tree.typeargs);
197 scan(tree.meth);
198 scan(tree.args);
199 }
201 public void visitNewClass(JCNewClass tree) {
202 scan(tree.encl);
203 scan(tree.clazz);
204 scan(tree.typeargs);
205 scan(tree.args);
206 scan(tree.def);
207 }
209 public void visitNewArray(JCNewArray tree) {
210 scan(tree.elemtype);
211 scan(tree.dims);
212 scan(tree.elems);
213 }
215 public void visitLambda(JCLambda tree) {
216 scan(tree.body);
217 scan(tree.params);
218 }
220 public void visitParens(JCParens tree) {
221 scan(tree.expr);
222 }
224 public void visitAssign(JCAssign tree) {
225 scan(tree.lhs);
226 scan(tree.rhs);
227 }
229 public void visitAssignop(JCAssignOp tree) {
230 scan(tree.lhs);
231 scan(tree.rhs);
232 }
234 public void visitUnary(JCUnary tree) {
235 scan(tree.arg);
236 }
238 public void visitBinary(JCBinary tree) {
239 scan(tree.lhs);
240 scan(tree.rhs);
241 }
243 public void visitTypeCast(JCTypeCast tree) {
244 scan(tree.clazz);
245 scan(tree.expr);
246 }
248 public void visitTypeTest(JCInstanceOf tree) {
249 scan(tree.expr);
250 scan(tree.clazz);
251 }
253 public void visitIndexed(JCArrayAccess tree) {
254 scan(tree.indexed);
255 scan(tree.index);
256 }
258 public void visitSelect(JCFieldAccess tree) {
259 scan(tree.selected);
260 }
262 public void visitReference(JCMemberReference tree) {
263 scan(tree.expr);
264 scan(tree.typeargs);
265 }
267 public void visitIdent(JCIdent tree) {
268 }
270 public void visitLiteral(JCLiteral tree) {
271 }
273 public void visitTypeIdent(JCPrimitiveTypeTree tree) {
274 }
276 public void visitTypeArray(JCArrayTypeTree tree) {
277 scan(tree.elemtype);
278 }
280 public void visitTypeApply(JCTypeApply tree) {
281 scan(tree.clazz);
282 scan(tree.arguments);
283 }
285 public void visitTypeUnion(JCTypeUnion tree) {
286 scan(tree.alternatives);
287 }
289 public void visitTypeParameter(JCTypeParameter tree) {
290 scan(tree.bounds);
291 }
293 @Override
294 public void visitWildcard(JCWildcard tree) {
295 scan(tree.kind);
296 if (tree.inner != null)
297 scan(tree.inner);
298 }
300 @Override
301 public void visitTypeBoundKind(TypeBoundKind that) {
302 }
304 public void visitModifiers(JCModifiers tree) {
305 scan(tree.annotations);
306 }
308 public void visitAnnotation(JCAnnotation tree) {
309 scan(tree.annotationType);
310 scan(tree.args);
311 }
313 public void visitErroneous(JCErroneous tree) {
314 }
316 public void visitLetExpr(LetExpr tree) {
317 scan(tree.defs);
318 scan(tree.expr);
319 }
321 public void visitTree(JCTree tree) {
322 Assert.error();
323 }
324 }