author | pgovereau |
Tue, 22 Apr 2014 17:07:54 -0400 | |
changeset 24069 | dfb8f11542fc |
parent 17578 | 46ac954e4a84 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.tree; |
|
27 |
||
28 |
import com.sun.tools.javac.util.*; |
|
29 |
import com.sun.tools.javac.tree.JCTree.*; |
|
30 |
||
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 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
40 |
* If you write code that depends on this, you do so at your own risk. |
10 | 41 |
* This code and its internal interfaces are subject to change or |
42 |
* deletion without notice.</b> |
|
43 |
*/ |
|
44 |
public class TreeScanner extends Visitor { |
|
45 |
||
46 |
/** Visitor method: Scan a single node. |
|
47 |
*/ |
|
48 |
public void scan(JCTree tree) { |
|
49 |
if(tree!=null) tree.accept(this); |
|
50 |
} |
|
51 |
||
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 |
} |
|
59 |
||
60 |
||
61 |
/* *************************************************************************** |
|
62 |
* Visitor methods |
|
63 |
****************************************************************************/ |
|
64 |
||
65 |
public void visitTopLevel(JCCompilationUnit tree) { |
|
24069 | 66 |
scan(tree.defs); |
67 |
} |
|
68 |
||
69 |
public void visitPackageDef(JCPackageDecl tree) { |
|
70 |
scan(tree.annotations); |
|
10 | 71 |
scan(tree.pid); |
72 |
} |
|
73 |
||
74 |
public void visitImport(JCImport tree) { |
|
75 |
scan(tree.qualid); |
|
76 |
} |
|
77 |
||
78 |
public void visitClassDef(JCClassDecl tree) { |
|
79 |
scan(tree.mods); |
|
80 |
scan(tree.typarams); |
|
81 |
scan(tree.extending); |
|
82 |
scan(tree.implementing); |
|
83 |
scan(tree.defs); |
|
84 |
} |
|
85 |
||
86 |
public void visitMethodDef(JCMethodDecl tree) { |
|
87 |
scan(tree.mods); |
|
88 |
scan(tree.restype); |
|
89 |
scan(tree.typarams); |
|
15385 | 90 |
scan(tree.recvparam); |
10 | 91 |
scan(tree.params); |
92 |
scan(tree.thrown); |
|
1786
88f03aba5cf9
6512707: "incompatible types" after (unrelated) annotation processing
jjg
parents:
10
diff
changeset
|
93 |
scan(tree.defaultValue); |
10 | 94 |
scan(tree.body); |
95 |
} |
|
96 |
||
97 |
public void visitVarDef(JCVariableDecl tree) { |
|
98 |
scan(tree.mods); |
|
99 |
scan(tree.vartype); |
|
17578 | 100 |
scan(tree.nameexpr); |
10 | 101 |
scan(tree.init); |
102 |
} |
|
103 |
||
104 |
public void visitSkip(JCSkip tree) { |
|
105 |
} |
|
106 |
||
107 |
public void visitBlock(JCBlock tree) { |
|
108 |
scan(tree.stats); |
|
109 |
} |
|
110 |
||
111 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
112 |
scan(tree.body); |
|
113 |
scan(tree.cond); |
|
114 |
} |
|
115 |
||
116 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
117 |
scan(tree.cond); |
|
118 |
scan(tree.body); |
|
119 |
} |
|
120 |
||
121 |
public void visitForLoop(JCForLoop tree) { |
|
122 |
scan(tree.init); |
|
123 |
scan(tree.cond); |
|
124 |
scan(tree.step); |
|
125 |
scan(tree.body); |
|
126 |
} |
|
127 |
||
128 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
129 |
scan(tree.var); |
|
130 |
scan(tree.expr); |
|
131 |
scan(tree.body); |
|
132 |
} |
|
133 |
||
134 |
public void visitLabelled(JCLabeledStatement tree) { |
|
135 |
scan(tree.body); |
|
136 |
} |
|
137 |
||
138 |
public void visitSwitch(JCSwitch tree) { |
|
139 |
scan(tree.selector); |
|
140 |
scan(tree.cases); |
|
141 |
} |
|
142 |
||
143 |
public void visitCase(JCCase tree) { |
|
144 |
scan(tree.pat); |
|
145 |
scan(tree.stats); |
|
146 |
} |
|
147 |
||
148 |
public void visitSynchronized(JCSynchronized tree) { |
|
149 |
scan(tree.lock); |
|
150 |
scan(tree.body); |
|
151 |
} |
|
152 |
||
153 |
public void visitTry(JCTry tree) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
154 |
scan(tree.resources); |
10 | 155 |
scan(tree.body); |
156 |
scan(tree.catchers); |
|
157 |
scan(tree.finalizer); |
|
158 |
} |
|
159 |
||
160 |
public void visitCatch(JCCatch tree) { |
|
161 |
scan(tree.param); |
|
162 |
scan(tree.body); |
|
163 |
} |
|
164 |
||
165 |
public void visitConditional(JCConditional tree) { |
|
166 |
scan(tree.cond); |
|
167 |
scan(tree.truepart); |
|
168 |
scan(tree.falsepart); |
|
169 |
} |
|
170 |
||
171 |
public void visitIf(JCIf tree) { |
|
172 |
scan(tree.cond); |
|
173 |
scan(tree.thenpart); |
|
174 |
scan(tree.elsepart); |
|
175 |
} |
|
176 |
||
177 |
public void visitExec(JCExpressionStatement tree) { |
|
178 |
scan(tree.expr); |
|
179 |
} |
|
180 |
||
181 |
public void visitBreak(JCBreak tree) { |
|
182 |
} |
|
183 |
||
184 |
public void visitContinue(JCContinue tree) { |
|
185 |
} |
|
186 |
||
187 |
public void visitReturn(JCReturn tree) { |
|
188 |
scan(tree.expr); |
|
189 |
} |
|
190 |
||
191 |
public void visitThrow(JCThrow tree) { |
|
192 |
scan(tree.expr); |
|
193 |
} |
|
194 |
||
195 |
public void visitAssert(JCAssert tree) { |
|
196 |
scan(tree.cond); |
|
197 |
scan(tree.detail); |
|
198 |
} |
|
199 |
||
200 |
public void visitApply(JCMethodInvocation tree) { |
|
4877
b642d21c9f74
6923080: TreeScanner.visitNewClass should scan tree.typeargs
jjg
parents:
3149
diff
changeset
|
201 |
scan(tree.typeargs); |
10 | 202 |
scan(tree.meth); |
203 |
scan(tree.args); |
|
204 |
} |
|
205 |
||
206 |
public void visitNewClass(JCNewClass tree) { |
|
207 |
scan(tree.encl); |
|
15385 | 208 |
scan(tree.typeargs); |
10 | 209 |
scan(tree.clazz); |
210 |
scan(tree.args); |
|
211 |
scan(tree.def); |
|
212 |
} |
|
213 |
||
214 |
public void visitNewArray(JCNewArray tree) { |
|
15385 | 215 |
scan(tree.annotations); |
10 | 216 |
scan(tree.elemtype); |
217 |
scan(tree.dims); |
|
15385 | 218 |
for (List<JCAnnotation> annos : tree.dimAnnotations) |
219 |
scan(annos); |
|
10 | 220 |
scan(tree.elems); |
221 |
} |
|
222 |
||
11141 | 223 |
public void visitLambda(JCLambda tree) { |
224 |
scan(tree.body); |
|
225 |
scan(tree.params); |
|
226 |
} |
|
227 |
||
10 | 228 |
public void visitParens(JCParens tree) { |
229 |
scan(tree.expr); |
|
230 |
} |
|
231 |
||
232 |
public void visitAssign(JCAssign tree) { |
|
233 |
scan(tree.lhs); |
|
234 |
scan(tree.rhs); |
|
235 |
} |
|
236 |
||
237 |
public void visitAssignop(JCAssignOp tree) { |
|
238 |
scan(tree.lhs); |
|
239 |
scan(tree.rhs); |
|
240 |
} |
|
241 |
||
242 |
public void visitUnary(JCUnary tree) { |
|
243 |
scan(tree.arg); |
|
244 |
} |
|
245 |
||
246 |
public void visitBinary(JCBinary tree) { |
|
247 |
scan(tree.lhs); |
|
248 |
scan(tree.rhs); |
|
249 |
} |
|
250 |
||
251 |
public void visitTypeCast(JCTypeCast tree) { |
|
252 |
scan(tree.clazz); |
|
253 |
scan(tree.expr); |
|
254 |
} |
|
255 |
||
256 |
public void visitTypeTest(JCInstanceOf tree) { |
|
257 |
scan(tree.expr); |
|
258 |
scan(tree.clazz); |
|
259 |
} |
|
260 |
||
261 |
public void visitIndexed(JCArrayAccess tree) { |
|
262 |
scan(tree.indexed); |
|
263 |
scan(tree.index); |
|
264 |
} |
|
265 |
||
266 |
public void visitSelect(JCFieldAccess tree) { |
|
267 |
scan(tree.selected); |
|
268 |
} |
|
269 |
||
11142 | 270 |
public void visitReference(JCMemberReference tree) { |
271 |
scan(tree.expr); |
|
272 |
scan(tree.typeargs); |
|
273 |
} |
|
274 |
||
10 | 275 |
public void visitIdent(JCIdent tree) { |
276 |
} |
|
277 |
||
278 |
public void visitLiteral(JCLiteral tree) { |
|
279 |
} |
|
280 |
||
281 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
282 |
} |
|
283 |
||
284 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
285 |
scan(tree.elemtype); |
|
286 |
} |
|
287 |
||
288 |
public void visitTypeApply(JCTypeApply tree) { |
|
289 |
scan(tree.clazz); |
|
290 |
scan(tree.arguments); |
|
291 |
} |
|
292 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8032
diff
changeset
|
293 |
public void visitTypeUnion(JCTypeUnion tree) { |
7074 | 294 |
scan(tree.alternatives); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4877
diff
changeset
|
295 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4877
diff
changeset
|
296 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
297 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
298 |
scan(tree.bounds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
299 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
300 |
|
10 | 301 |
public void visitTypeParameter(JCTypeParameter tree) { |
15385 | 302 |
scan(tree.annotations); |
10 | 303 |
scan(tree.bounds); |
304 |
} |
|
305 |
||
306 |
@Override |
|
307 |
public void visitWildcard(JCWildcard tree) { |
|
308 |
scan(tree.kind); |
|
309 |
if (tree.inner != null) |
|
310 |
scan(tree.inner); |
|
311 |
} |
|
312 |
||
313 |
@Override |
|
314 |
public void visitTypeBoundKind(TypeBoundKind that) { |
|
315 |
} |
|
316 |
||
317 |
public void visitModifiers(JCModifiers tree) { |
|
318 |
scan(tree.annotations); |
|
319 |
} |
|
320 |
||
321 |
public void visitAnnotation(JCAnnotation tree) { |
|
322 |
scan(tree.annotationType); |
|
323 |
scan(tree.args); |
|
324 |
} |
|
325 |
||
15385 | 326 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
327 |
scan(tree.annotations); |
|
328 |
scan(tree.underlyingType); |
|
329 |
} |
|
330 |
||
10 | 331 |
public void visitErroneous(JCErroneous tree) { |
332 |
} |
|
333 |
||
334 |
public void visitLetExpr(LetExpr tree) { |
|
335 |
scan(tree.defs); |
|
336 |
scan(tree.expr); |
|
337 |
} |
|
338 |
||
339 |
public void visitTree(JCTree tree) { |
|
8032 | 340 |
Assert.error(); |
10 | 341 |
} |
342 |
} |