author | jjg |
Fri, 26 Jun 2009 18:51:39 -0700 | |
changeset 3149 | 0cd06d598d6f |
parent 1786 | 88f03aba5cf9 |
child 4877 | b642d21c9f74 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
2 |
* Copyright 2001-2006 Sun Microsystems, Inc. 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
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 |
* |
|
39 |
* <p><b>This is NOT part of any API supported by Sun Microsystems. If |
|
40 |
* 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 { |
|
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) { |
|
66 |
scan(tree.packageAnnotations); |
|
67 |
scan(tree.pid); |
|
68 |
scan(tree.defs); |
|
69 |
} |
|
70 |
||
71 |
public void visitImport(JCImport tree) { |
|
72 |
scan(tree.qualid); |
|
73 |
} |
|
74 |
||
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 |
} |
|
82 |
||
83 |
public void visitMethodDef(JCMethodDecl tree) { |
|
84 |
scan(tree.mods); |
|
85 |
scan(tree.restype); |
|
86 |
scan(tree.typarams); |
|
87 |
scan(tree.params); |
|
3149 | 88 |
scan(tree.receiverAnnotations); |
10 | 89 |
scan(tree.thrown); |
1786
88f03aba5cf9
6512707: "incompatible types" after (unrelated) annotation processing
jjg
parents:
10
diff
changeset
|
90 |
scan(tree.defaultValue); |
10 | 91 |
scan(tree.body); |
92 |
} |
|
93 |
||
94 |
public void visitVarDef(JCVariableDecl tree) { |
|
95 |
scan(tree.mods); |
|
96 |
scan(tree.vartype); |
|
97 |
scan(tree.init); |
|
98 |
} |
|
99 |
||
100 |
public void visitSkip(JCSkip tree) { |
|
101 |
} |
|
102 |
||
103 |
public void visitBlock(JCBlock tree) { |
|
104 |
scan(tree.stats); |
|
105 |
} |
|
106 |
||
107 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
108 |
scan(tree.body); |
|
109 |
scan(tree.cond); |
|
110 |
} |
|
111 |
||
112 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
113 |
scan(tree.cond); |
|
114 |
scan(tree.body); |
|
115 |
} |
|
116 |
||
117 |
public void visitForLoop(JCForLoop tree) { |
|
118 |
scan(tree.init); |
|
119 |
scan(tree.cond); |
|
120 |
scan(tree.step); |
|
121 |
scan(tree.body); |
|
122 |
} |
|
123 |
||
124 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
125 |
scan(tree.var); |
|
126 |
scan(tree.expr); |
|
127 |
scan(tree.body); |
|
128 |
} |
|
129 |
||
130 |
public void visitLabelled(JCLabeledStatement tree) { |
|
131 |
scan(tree.body); |
|
132 |
} |
|
133 |
||
134 |
public void visitSwitch(JCSwitch tree) { |
|
135 |
scan(tree.selector); |
|
136 |
scan(tree.cases); |
|
137 |
} |
|
138 |
||
139 |
public void visitCase(JCCase tree) { |
|
140 |
scan(tree.pat); |
|
141 |
scan(tree.stats); |
|
142 |
} |
|
143 |
||
144 |
public void visitSynchronized(JCSynchronized tree) { |
|
145 |
scan(tree.lock); |
|
146 |
scan(tree.body); |
|
147 |
} |
|
148 |
||
149 |
public void visitTry(JCTry tree) { |
|
150 |
scan(tree.body); |
|
151 |
scan(tree.catchers); |
|
152 |
scan(tree.finalizer); |
|
153 |
} |
|
154 |
||
155 |
public void visitCatch(JCCatch tree) { |
|
156 |
scan(tree.param); |
|
157 |
scan(tree.body); |
|
158 |
} |
|
159 |
||
160 |
public void visitConditional(JCConditional tree) { |
|
161 |
scan(tree.cond); |
|
162 |
scan(tree.truepart); |
|
163 |
scan(tree.falsepart); |
|
164 |
} |
|
165 |
||
166 |
public void visitIf(JCIf tree) { |
|
167 |
scan(tree.cond); |
|
168 |
scan(tree.thenpart); |
|
169 |
scan(tree.elsepart); |
|
170 |
} |
|
171 |
||
172 |
public void visitExec(JCExpressionStatement tree) { |
|
173 |
scan(tree.expr); |
|
174 |
} |
|
175 |
||
176 |
public void visitBreak(JCBreak tree) { |
|
177 |
} |
|
178 |
||
179 |
public void visitContinue(JCContinue tree) { |
|
180 |
} |
|
181 |
||
182 |
public void visitReturn(JCReturn tree) { |
|
183 |
scan(tree.expr); |
|
184 |
} |
|
185 |
||
186 |
public void visitThrow(JCThrow tree) { |
|
187 |
scan(tree.expr); |
|
188 |
} |
|
189 |
||
190 |
public void visitAssert(JCAssert tree) { |
|
191 |
scan(tree.cond); |
|
192 |
scan(tree.detail); |
|
193 |
} |
|
194 |
||
195 |
public void visitApply(JCMethodInvocation tree) { |
|
196 |
scan(tree.meth); |
|
197 |
scan(tree.args); |
|
198 |
} |
|
199 |
||
200 |
public void visitNewClass(JCNewClass tree) { |
|
201 |
scan(tree.encl); |
|
202 |
scan(tree.clazz); |
|
203 |
scan(tree.args); |
|
204 |
scan(tree.def); |
|
205 |
} |
|
206 |
||
207 |
public void visitNewArray(JCNewArray tree) { |
|
3149 | 208 |
scan(tree.annotations); |
10 | 209 |
scan(tree.elemtype); |
210 |
scan(tree.dims); |
|
3149 | 211 |
for (List<JCTypeAnnotation> annos : tree.dimAnnotations) |
212 |
scan(annos); |
|
10 | 213 |
scan(tree.elems); |
214 |
} |
|
215 |
||
216 |
public void visitParens(JCParens tree) { |
|
217 |
scan(tree.expr); |
|
218 |
} |
|
219 |
||
220 |
public void visitAssign(JCAssign tree) { |
|
221 |
scan(tree.lhs); |
|
222 |
scan(tree.rhs); |
|
223 |
} |
|
224 |
||
225 |
public void visitAssignop(JCAssignOp tree) { |
|
226 |
scan(tree.lhs); |
|
227 |
scan(tree.rhs); |
|
228 |
} |
|
229 |
||
230 |
public void visitUnary(JCUnary tree) { |
|
231 |
scan(tree.arg); |
|
232 |
} |
|
233 |
||
234 |
public void visitBinary(JCBinary tree) { |
|
235 |
scan(tree.lhs); |
|
236 |
scan(tree.rhs); |
|
237 |
} |
|
238 |
||
239 |
public void visitTypeCast(JCTypeCast tree) { |
|
240 |
scan(tree.clazz); |
|
241 |
scan(tree.expr); |
|
242 |
} |
|
243 |
||
244 |
public void visitTypeTest(JCInstanceOf tree) { |
|
245 |
scan(tree.expr); |
|
246 |
scan(tree.clazz); |
|
247 |
} |
|
248 |
||
249 |
public void visitIndexed(JCArrayAccess tree) { |
|
250 |
scan(tree.indexed); |
|
251 |
scan(tree.index); |
|
252 |
} |
|
253 |
||
254 |
public void visitSelect(JCFieldAccess tree) { |
|
255 |
scan(tree.selected); |
|
256 |
} |
|
257 |
||
258 |
public void visitIdent(JCIdent tree) { |
|
259 |
} |
|
260 |
||
261 |
public void visitLiteral(JCLiteral tree) { |
|
262 |
} |
|
263 |
||
264 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
265 |
} |
|
266 |
||
267 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
268 |
scan(tree.elemtype); |
|
269 |
} |
|
270 |
||
271 |
public void visitTypeApply(JCTypeApply tree) { |
|
272 |
scan(tree.clazz); |
|
273 |
scan(tree.arguments); |
|
274 |
} |
|
275 |
||
276 |
public void visitTypeParameter(JCTypeParameter tree) { |
|
3149 | 277 |
scan(tree.annotations); |
10 | 278 |
scan(tree.bounds); |
279 |
} |
|
280 |
||
281 |
@Override |
|
282 |
public void visitWildcard(JCWildcard tree) { |
|
283 |
scan(tree.kind); |
|
284 |
if (tree.inner != null) |
|
285 |
scan(tree.inner); |
|
286 |
} |
|
287 |
||
288 |
@Override |
|
289 |
public void visitTypeBoundKind(TypeBoundKind that) { |
|
290 |
} |
|
291 |
||
292 |
public void visitModifiers(JCModifiers tree) { |
|
293 |
scan(tree.annotations); |
|
294 |
} |
|
295 |
||
296 |
public void visitAnnotation(JCAnnotation tree) { |
|
297 |
scan(tree.annotationType); |
|
298 |
scan(tree.args); |
|
299 |
} |
|
300 |
||
3149 | 301 |
public void visitAnnotatedType(JCAnnotatedType tree) { |
302 |
scan(tree.annotations); |
|
303 |
scan(tree.underlyingType); |
|
304 |
} |
|
305 |
||
10 | 306 |
public void visitErroneous(JCErroneous tree) { |
307 |
} |
|
308 |
||
309 |
public void visitLetExpr(LetExpr tree) { |
|
310 |
scan(tree.defs); |
|
311 |
scan(tree.expr); |
|
312 |
} |
|
313 |
||
314 |
public void visitTree(JCTree tree) { |
|
315 |
assert false; |
|
316 |
} |
|
317 |
} |