author | jjg |
Wed, 07 Jan 2009 14:48:29 -0800 | |
changeset 1786 | 88f03aba5cf9 |
parent 10 | 06bc494ca11e |
child 3149 | 0cd06d598d6f |
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); |
|
88 |
scan(tree.thrown); |
|
1786
88f03aba5cf9
6512707: "incompatible types" after (unrelated) annotation processing
jjg
parents:
10
diff
changeset
|
89 |
scan(tree.defaultValue); |
10 | 90 |
scan(tree.body); |
91 |
} |
|
92 |
||
93 |
public void visitVarDef(JCVariableDecl tree) { |
|
94 |
scan(tree.mods); |
|
95 |
scan(tree.vartype); |
|
96 |
scan(tree.init); |
|
97 |
} |
|
98 |
||
99 |
public void visitSkip(JCSkip tree) { |
|
100 |
} |
|
101 |
||
102 |
public void visitBlock(JCBlock tree) { |
|
103 |
scan(tree.stats); |
|
104 |
} |
|
105 |
||
106 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
107 |
scan(tree.body); |
|
108 |
scan(tree.cond); |
|
109 |
} |
|
110 |
||
111 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
112 |
scan(tree.cond); |
|
113 |
scan(tree.body); |
|
114 |
} |
|
115 |
||
116 |
public void visitForLoop(JCForLoop tree) { |
|
117 |
scan(tree.init); |
|
118 |
scan(tree.cond); |
|
119 |
scan(tree.step); |
|
120 |
scan(tree.body); |
|
121 |
} |
|
122 |
||
123 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
124 |
scan(tree.var); |
|
125 |
scan(tree.expr); |
|
126 |
scan(tree.body); |
|
127 |
} |
|
128 |
||
129 |
public void visitLabelled(JCLabeledStatement tree) { |
|
130 |
scan(tree.body); |
|
131 |
} |
|
132 |
||
133 |
public void visitSwitch(JCSwitch tree) { |
|
134 |
scan(tree.selector); |
|
135 |
scan(tree.cases); |
|
136 |
} |
|
137 |
||
138 |
public void visitCase(JCCase tree) { |
|
139 |
scan(tree.pat); |
|
140 |
scan(tree.stats); |
|
141 |
} |
|
142 |
||
143 |
public void visitSynchronized(JCSynchronized tree) { |
|
144 |
scan(tree.lock); |
|
145 |
scan(tree.body); |
|
146 |
} |
|
147 |
||
148 |
public void visitTry(JCTry tree) { |
|
149 |
scan(tree.body); |
|
150 |
scan(tree.catchers); |
|
151 |
scan(tree.finalizer); |
|
152 |
} |
|
153 |
||
154 |
public void visitCatch(JCCatch tree) { |
|
155 |
scan(tree.param); |
|
156 |
scan(tree.body); |
|
157 |
} |
|
158 |
||
159 |
public void visitConditional(JCConditional tree) { |
|
160 |
scan(tree.cond); |
|
161 |
scan(tree.truepart); |
|
162 |
scan(tree.falsepart); |
|
163 |
} |
|
164 |
||
165 |
public void visitIf(JCIf tree) { |
|
166 |
scan(tree.cond); |
|
167 |
scan(tree.thenpart); |
|
168 |
scan(tree.elsepart); |
|
169 |
} |
|
170 |
||
171 |
public void visitExec(JCExpressionStatement tree) { |
|
172 |
scan(tree.expr); |
|
173 |
} |
|
174 |
||
175 |
public void visitBreak(JCBreak tree) { |
|
176 |
} |
|
177 |
||
178 |
public void visitContinue(JCContinue tree) { |
|
179 |
} |
|
180 |
||
181 |
public void visitReturn(JCReturn tree) { |
|
182 |
scan(tree.expr); |
|
183 |
} |
|
184 |
||
185 |
public void visitThrow(JCThrow tree) { |
|
186 |
scan(tree.expr); |
|
187 |
} |
|
188 |
||
189 |
public void visitAssert(JCAssert tree) { |
|
190 |
scan(tree.cond); |
|
191 |
scan(tree.detail); |
|
192 |
} |
|
193 |
||
194 |
public void visitApply(JCMethodInvocation tree) { |
|
195 |
scan(tree.meth); |
|
196 |
scan(tree.args); |
|
197 |
} |
|
198 |
||
199 |
public void visitNewClass(JCNewClass tree) { |
|
200 |
scan(tree.encl); |
|
201 |
scan(tree.clazz); |
|
202 |
scan(tree.args); |
|
203 |
scan(tree.def); |
|
204 |
} |
|
205 |
||
206 |
public void visitNewArray(JCNewArray tree) { |
|
207 |
scan(tree.elemtype); |
|
208 |
scan(tree.dims); |
|
209 |
scan(tree.elems); |
|
210 |
} |
|
211 |
||
212 |
public void visitParens(JCParens tree) { |
|
213 |
scan(tree.expr); |
|
214 |
} |
|
215 |
||
216 |
public void visitAssign(JCAssign tree) { |
|
217 |
scan(tree.lhs); |
|
218 |
scan(tree.rhs); |
|
219 |
} |
|
220 |
||
221 |
public void visitAssignop(JCAssignOp tree) { |
|
222 |
scan(tree.lhs); |
|
223 |
scan(tree.rhs); |
|
224 |
} |
|
225 |
||
226 |
public void visitUnary(JCUnary tree) { |
|
227 |
scan(tree.arg); |
|
228 |
} |
|
229 |
||
230 |
public void visitBinary(JCBinary tree) { |
|
231 |
scan(tree.lhs); |
|
232 |
scan(tree.rhs); |
|
233 |
} |
|
234 |
||
235 |
public void visitTypeCast(JCTypeCast tree) { |
|
236 |
scan(tree.clazz); |
|
237 |
scan(tree.expr); |
|
238 |
} |
|
239 |
||
240 |
public void visitTypeTest(JCInstanceOf tree) { |
|
241 |
scan(tree.expr); |
|
242 |
scan(tree.clazz); |
|
243 |
} |
|
244 |
||
245 |
public void visitIndexed(JCArrayAccess tree) { |
|
246 |
scan(tree.indexed); |
|
247 |
scan(tree.index); |
|
248 |
} |
|
249 |
||
250 |
public void visitSelect(JCFieldAccess tree) { |
|
251 |
scan(tree.selected); |
|
252 |
} |
|
253 |
||
254 |
public void visitIdent(JCIdent tree) { |
|
255 |
} |
|
256 |
||
257 |
public void visitLiteral(JCLiteral tree) { |
|
258 |
} |
|
259 |
||
260 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
|
261 |
} |
|
262 |
||
263 |
public void visitTypeArray(JCArrayTypeTree tree) { |
|
264 |
scan(tree.elemtype); |
|
265 |
} |
|
266 |
||
267 |
public void visitTypeApply(JCTypeApply tree) { |
|
268 |
scan(tree.clazz); |
|
269 |
scan(tree.arguments); |
|
270 |
} |
|
271 |
||
272 |
public void visitTypeParameter(JCTypeParameter tree) { |
|
273 |
scan(tree.bounds); |
|
274 |
} |
|
275 |
||
276 |
@Override |
|
277 |
public void visitWildcard(JCWildcard tree) { |
|
278 |
scan(tree.kind); |
|
279 |
if (tree.inner != null) |
|
280 |
scan(tree.inner); |
|
281 |
} |
|
282 |
||
283 |
@Override |
|
284 |
public void visitTypeBoundKind(TypeBoundKind that) { |
|
285 |
} |
|
286 |
||
287 |
public void visitModifiers(JCModifiers tree) { |
|
288 |
scan(tree.annotations); |
|
289 |
} |
|
290 |
||
291 |
public void visitAnnotation(JCAnnotation tree) { |
|
292 |
scan(tree.annotationType); |
|
293 |
scan(tree.args); |
|
294 |
} |
|
295 |
||
296 |
public void visitErroneous(JCErroneous tree) { |
|
297 |
} |
|
298 |
||
299 |
public void visitLetExpr(LetExpr tree) { |
|
300 |
scan(tree.defs); |
|
301 |
scan(tree.expr); |
|
302 |
} |
|
303 |
||
304 |
public void visitTree(JCTree tree) { |
|
305 |
assert false; |
|
306 |
} |
|
307 |
} |