author | alanb |
Thu, 01 Dec 2016 09:02:42 +0000 | |
changeset 42407 | f3702cff2933 |
parent 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2001, 2016, 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 |
||
36526 | 74 |
@Override |
75 |
public void visitModuleDef(JCModuleDecl tree) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
76 |
scan(tree.mods); |
36526 | 77 |
scan(tree.qualId); |
78 |
scan(tree.directives); |
|
79 |
} |
|
80 |
||
81 |
@Override |
|
82 |
public void visitExports(JCExports tree) { |
|
83 |
scan(tree.qualid); |
|
84 |
scan(tree.moduleNames); |
|
85 |
} |
|
86 |
||
87 |
@Override |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
88 |
public void visitOpens(JCOpens tree) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
89 |
scan(tree.qualid); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
90 |
scan(tree.moduleNames); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
91 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
92 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
93 |
@Override |
36526 | 94 |
public void visitProvides(JCProvides tree) { |
95 |
scan(tree.serviceName); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
96 |
scan(tree.implNames); |
36526 | 97 |
} |
98 |
||
99 |
@Override |
|
100 |
public void visitRequires(JCRequires tree) { |
|
101 |
scan(tree.moduleName); |
|
102 |
} |
|
103 |
||
104 |
@Override |
|
105 |
public void visitUses(JCUses tree) { |
|
106 |
scan(tree.qualid); |
|
107 |
} |
|
108 |
||
10 | 109 |
public void visitImport(JCImport tree) { |
110 |
scan(tree.qualid); |
|
111 |
} |
|
112 |
||
113 |
public void visitClassDef(JCClassDecl tree) { |
|
114 |
scan(tree.mods); |
|
115 |
scan(tree.typarams); |
|
116 |
scan(tree.extending); |
|
117 |
scan(tree.implementing); |
|
118 |
scan(tree.defs); |
|
119 |
} |
|
120 |
||
121 |
public void visitMethodDef(JCMethodDecl tree) { |
|
122 |
scan(tree.mods); |
|
123 |
scan(tree.restype); |
|
124 |
scan(tree.typarams); |
|
15385 | 125 |
scan(tree.recvparam); |
10 | 126 |
scan(tree.params); |
127 |
scan(tree.thrown); |
|
1786
88f03aba5cf9
6512707: "incompatible types" after (unrelated) annotation processing
jjg
parents:
10
diff
changeset
|
128 |
scan(tree.defaultValue); |
10 | 129 |
scan(tree.body); |
130 |
} |
|
131 |
||
132 |
public void visitVarDef(JCVariableDecl tree) { |
|
133 |
scan(tree.mods); |
|
134 |
scan(tree.vartype); |
|
17578 | 135 |
scan(tree.nameexpr); |
10 | 136 |
scan(tree.init); |
137 |
} |
|
138 |
||
139 |
public void visitSkip(JCSkip tree) { |
|
140 |
} |
|
141 |
||
142 |
public void visitBlock(JCBlock tree) { |
|
143 |
scan(tree.stats); |
|
144 |
} |
|
145 |
||
146 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
147 |
scan(tree.body); |
|
148 |
scan(tree.cond); |
|
149 |
} |
|
150 |
||
151 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
152 |
scan(tree.cond); |
|
153 |
scan(tree.body); |
|
154 |
} |
|
155 |
||
156 |
public void visitForLoop(JCForLoop tree) { |
|
157 |
scan(tree.init); |
|
158 |
scan(tree.cond); |
|
159 |
scan(tree.step); |
|
160 |
scan(tree.body); |
|
161 |
} |
|
162 |
||
163 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
164 |
scan(tree.var); |
|
165 |
scan(tree.expr); |
|
166 |
scan(tree.body); |
|
167 |
} |
|
168 |
||
169 |
public void visitLabelled(JCLabeledStatement tree) { |
|
170 |
scan(tree.body); |
|
171 |
} |
|
172 |
||
173 |
public void visitSwitch(JCSwitch tree) { |
|
174 |
scan(tree.selector); |
|
175 |
scan(tree.cases); |
|
176 |
} |
|
177 |
||
178 |
public void visitCase(JCCase tree) { |
|
179 |
scan(tree.pat); |
|
180 |
scan(tree.stats); |
|
181 |
} |
|
182 |
||
183 |
public void visitSynchronized(JCSynchronized tree) { |
|
184 |
scan(tree.lock); |
|
185 |
scan(tree.body); |
|
186 |
} |
|
187 |
||
188 |
public void visitTry(JCTry tree) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
189 |
scan(tree.resources); |
10 | 190 |
scan(tree.body); |
191 |
scan(tree.catchers); |
|
192 |
scan(tree.finalizer); |
|
193 |
} |
|
194 |
||
195 |
public void visitCatch(JCCatch tree) { |
|
196 |
scan(tree.param); |
|
197 |
scan(tree.body); |
|
198 |
} |
|
199 |
||
200 |
public void visitConditional(JCConditional tree) { |
|
201 |
scan(tree.cond); |
|
202 |
scan(tree.truepart); |
|
203 |
scan(tree.falsepart); |
|
204 |
} |
|
205 |
||
206 |
public void visitIf(JCIf tree) { |
|
207 |
scan(tree.cond); |
|
208 |
scan(tree.thenpart); |
|
209 |
scan(tree.elsepart); |
|
210 |
} |
|
211 |
||
212 |
public void visitExec(JCExpressionStatement tree) { |
|
213 |
scan(tree.expr); |
|
214 |
} |
|
215 |
||
216 |
public void visitBreak(JCBreak tree) { |
|
217 |
} |
|
218 |
||
219 |
public void visitContinue(JCContinue tree) { |
|
220 |
} |
|
221 |
||
222 |
public void visitReturn(JCReturn tree) { |
|
223 |
scan(tree.expr); |
|
224 |
} |
|
225 |
||
226 |
public void visitThrow(JCThrow tree) { |
|
227 |
scan(tree.expr); |
|
228 |
} |
|
229 |
||
230 |
public void visitAssert(JCAssert tree) { |
|
231 |
scan(tree.cond); |
|
232 |
scan(tree.detail); |
|
233 |
} |
|
234 |
||
235 |
public void visitApply(JCMethodInvocation tree) { |
|
4877
b642d21c9f74
6923080: TreeScanner.visitNewClass should scan tree.typeargs
jjg
parents:
3149
diff
changeset
|
236 |
scan(tree.typeargs); |
10 | 237 |
scan(tree.meth); |
238 |
scan(tree.args); |
|
239 |
} |
|
240 |
||
241 |
public void visitNewClass(JCNewClass tree) { |
|
242 |
scan(tree.encl); |
|
15385 | 243 |
scan(tree.typeargs); |
10 | 244 |
scan(tree.clazz); |
245 |
scan(tree.args); |
|
246 |
scan(tree.def); |
|
247 |
} |
|
248 |
||
249 |
public void visitNewArray(JCNewArray tree) { |
|
15385 | 250 |
scan(tree.annotations); |
10 | 251 |
scan(tree.elemtype); |
252 |
scan(tree.dims); |
|
15385 | 253 |
for (List<JCAnnotation> annos : tree.dimAnnotations) |
254 |
scan(annos); |
|
10 | 255 |
scan(tree.elems); |
256 |
} |
|
257 |
||
11141 | 258 |
public void visitLambda(JCLambda tree) { |
259 |
scan(tree.body); |
|
260 |
scan(tree.params); |
|
261 |
} |
|
262 |
||
10 | 263 |
public void visitParens(JCParens tree) { |
264 |
scan(tree.expr); |
|
265 |
} |
|
266 |
||
267 |
public void visitAssign(JCAssign tree) { |
|
268 |
scan(tree.lhs); |
|
269 |
scan(tree.rhs); |
|
270 |
} |
|
271 |
||
272 |
public void visitAssignop(JCAssignOp tree) { |
|
273 |
scan(tree.lhs); |
|
274 |
scan(tree.rhs); |
|
275 |
} |
|
276 |
||
277 |
public void visitUnary(JCUnary tree) { |
|
278 |
scan(tree.arg); |
|
279 |
} |
|
280 |
||
281 |
public void visitBinary(JCBinary tree) { |
|
282 |
scan(tree.lhs); |
|
283 |
scan(tree.rhs); |
|
284 |
} |
|
285 |
||
286 |
public void visitTypeCast(JCTypeCast tree) { |
|
287 |
scan(tree.clazz); |
|
288 |
scan(tree.expr); |
|
289 |
} |
|
290 |
||
291 |
public void visitTypeTest(JCInstanceOf tree) { |
|
292 |
scan(tree.expr); |
|
293 |
scan(tree.clazz); |
|
294 |
} |
|
295 |
||
296 |
public void visitIndexed(JCArrayAccess tree) { |
|
297 |
scan(tree.indexed); |
|
298 |
scan(tree.index); |
|
299 |
} |
|
300 |
||
301 |
public void visitSelect(JCFieldAccess tree) { |
|
302 |
scan(tree.selected); |
|
303 |
} |
|
304 |
||
11142 | 305 |
public void visitReference(JCMemberReference tree) { |
306 |
scan(tree.expr); |
|
307 |
scan(tree.typeargs); |
|
308 |
} |
|
309 |
||
10 | 310 |
public void visitIdent(JCIdent tree) { |
311 |
} |
|
312 |
||
313 |
public void visitLiteral(JCLiteral tree) { |
|
314 |
} |
|
315 |
||
316 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
317 |
} |
|
318 |
||
319 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
320 |
scan(tree.elemtype); |
|
321 |
} |
|
322 |
||
323 |
public void visitTypeApply(JCTypeApply tree) { |
|
324 |
scan(tree.clazz); |
|
325 |
scan(tree.arguments); |
|
326 |
} |
|
327 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8032
diff
changeset
|
328 |
public void visitTypeUnion(JCTypeUnion tree) { |
7074 | 329 |
scan(tree.alternatives); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4877
diff
changeset
|
330 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4877
diff
changeset
|
331 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
332 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
333 |
scan(tree.bounds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
334 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
335 |
|
10 | 336 |
public void visitTypeParameter(JCTypeParameter tree) { |
15385 | 337 |
scan(tree.annotations); |
10 | 338 |
scan(tree.bounds); |
339 |
} |
|
340 |
||
341 |
@Override |
|
342 |
public void visitWildcard(JCWildcard tree) { |
|
343 |
scan(tree.kind); |
|
344 |
if (tree.inner != null) |
|
345 |
scan(tree.inner); |
|
346 |
} |
|
347 |
||
348 |
@Override |
|
349 |
public void visitTypeBoundKind(TypeBoundKind that) { |
|
350 |
} |
|
351 |
||
352 |
public void visitModifiers(JCModifiers tree) { |
|
353 |
scan(tree.annotations); |
|
354 |
} |
|
355 |
||
356 |
public void visitAnnotation(JCAnnotation tree) { |
|
357 |
scan(tree.annotationType); |
|
358 |
scan(tree.args); |
|
359 |
} |
|
360 |
||
15385 | 361 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
362 |
scan(tree.annotations); |
|
363 |
scan(tree.underlyingType); |
|
364 |
} |
|
365 |
||
10 | 366 |
public void visitErroneous(JCErroneous tree) { |
367 |
} |
|
368 |
||
369 |
public void visitLetExpr(LetExpr tree) { |
|
370 |
scan(tree.defs); |
|
371 |
scan(tree.expr); |
|
372 |
} |
|
373 |
||
374 |
public void visitTree(JCTree tree) { |
|
8032 | 375 |
Assert.error(); |
10 | 376 |
} |
377 |
} |