author | chegar |
Sun, 17 Aug 2014 15:52:32 +0100 | |
changeset 25874 | 83c19f00452c |
parent 24069 | langtools/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java@dfb8f11542fc |
child 26266 | 2d24bda701dc |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 2006, 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.source.tree.*; |
|
29 |
import com.sun.tools.javac.tree.JCTree.*; |
|
30 |
import com.sun.tools.javac.util.List; |
|
31 |
import com.sun.tools.javac.util.ListBuffer; |
|
32 |
||
33 |
/** |
|
34 |
* Creates a copy of a tree, using a given TreeMaker. |
|
35 |
* Names, literal values, etc are shared with the original. |
|
36 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
37 |
* <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
|
38 |
* If you write code that depends on this, you do so at your own risk. |
10 | 39 |
* This code and its internal interfaces are subject to change or |
40 |
* deletion without notice.</b> |
|
41 |
*/ |
|
42 |
public class TreeCopier<P> implements TreeVisitor<JCTree,P> { |
|
43 |
private TreeMaker M; |
|
44 |
||
45 |
/** Creates a new instance of TreeCopier */ |
|
46 |
public TreeCopier(TreeMaker M) { |
|
47 |
this.M = M; |
|
48 |
} |
|
49 |
||
50 |
public <T extends JCTree> T copy(T tree) { |
|
51 |
return copy(tree, null); |
|
52 |
} |
|
53 |
||
54 |
@SuppressWarnings("unchecked") |
|
55 |
public <T extends JCTree> T copy(T tree, P p) { |
|
56 |
if (tree == null) |
|
57 |
return null; |
|
58 |
return (T) (tree.accept(this, p)); |
|
59 |
} |
|
60 |
||
61 |
public <T extends JCTree> List<T> copy(List<T> trees) { |
|
62 |
return copy(trees, null); |
|
63 |
} |
|
64 |
||
65 |
public <T extends JCTree> List<T> copy(List<T> trees, P p) { |
|
66 |
if (trees == null) |
|
67 |
return null; |
|
22163 | 68 |
ListBuffer<T> lb = new ListBuffer<>(); |
10 | 69 |
for (T tree: trees) |
70 |
lb.append(copy(tree, p)); |
|
71 |
return lb.toList(); |
|
72 |
} |
|
73 |
||
15385 | 74 |
public JCTree visitAnnotatedType(AnnotatedTypeTree node, P p) { |
75 |
JCAnnotatedType t = (JCAnnotatedType) node; |
|
76 |
List<JCAnnotation> annotations = copy(t.annotations, p); |
|
77 |
JCExpression underlyingType = copy(t.underlyingType, p); |
|
78 |
return M.at(t.pos).AnnotatedType(annotations, underlyingType); |
|
79 |
} |
|
80 |
||
10 | 81 |
public JCTree visitAnnotation(AnnotationTree node, P p) { |
82 |
JCAnnotation t = (JCAnnotation) node; |
|
83 |
JCTree annotationType = copy(t.annotationType, p); |
|
84 |
List<JCExpression> args = copy(t.args, p); |
|
15385 | 85 |
if (t.getKind() == Tree.Kind.TYPE_ANNOTATION) { |
86 |
JCAnnotation newTA = M.at(t.pos).TypeAnnotation(annotationType, args); |
|
87 |
newTA.attribute = t.attribute; |
|
88 |
return newTA; |
|
89 |
} else { |
|
90 |
JCAnnotation newT = M.at(t.pos).Annotation(annotationType, args); |
|
91 |
newT.attribute = t.attribute; |
|
92 |
return newT; |
|
93 |
} |
|
10 | 94 |
} |
95 |
||
96 |
public JCTree visitAssert(AssertTree node, P p) { |
|
97 |
JCAssert t = (JCAssert) node; |
|
98 |
JCExpression cond = copy(t.cond, p); |
|
99 |
JCExpression detail = copy(t.detail, p); |
|
100 |
return M.at(t.pos).Assert(cond, detail); |
|
101 |
} |
|
102 |
||
103 |
public JCTree visitAssignment(AssignmentTree node, P p) { |
|
104 |
JCAssign t = (JCAssign) node; |
|
105 |
JCExpression lhs = copy(t.lhs, p); |
|
106 |
JCExpression rhs = copy(t.rhs, p); |
|
107 |
return M.at(t.pos).Assign(lhs, rhs); |
|
108 |
} |
|
109 |
||
110 |
public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) { |
|
111 |
JCAssignOp t = (JCAssignOp) node; |
|
112 |
JCTree lhs = copy(t.lhs, p); |
|
113 |
JCTree rhs = copy(t.rhs, p); |
|
114 |
return M.at(t.pos).Assignop(t.getTag(), lhs, rhs); |
|
115 |
} |
|
116 |
||
117 |
public JCTree visitBinary(BinaryTree node, P p) { |
|
118 |
JCBinary t = (JCBinary) node; |
|
119 |
JCExpression lhs = copy(t.lhs, p); |
|
120 |
JCExpression rhs = copy(t.rhs, p); |
|
121 |
return M.at(t.pos).Binary(t.getTag(), lhs, rhs); |
|
122 |
} |
|
123 |
||
124 |
public JCTree visitBlock(BlockTree node, P p) { |
|
125 |
JCBlock t = (JCBlock) node; |
|
126 |
List<JCStatement> stats = copy(t.stats, p); |
|
127 |
return M.at(t.pos).Block(t.flags, stats); |
|
128 |
} |
|
129 |
||
130 |
public JCTree visitBreak(BreakTree node, P p) { |
|
131 |
JCBreak t = (JCBreak) node; |
|
132 |
return M.at(t.pos).Break(t.label); |
|
133 |
} |
|
134 |
||
135 |
public JCTree visitCase(CaseTree node, P p) { |
|
136 |
JCCase t = (JCCase) node; |
|
137 |
JCExpression pat = copy(t.pat, p); |
|
138 |
List<JCStatement> stats = copy(t.stats, p); |
|
139 |
return M.at(t.pos).Case(pat, stats); |
|
140 |
} |
|
141 |
||
142 |
public JCTree visitCatch(CatchTree node, P p) { |
|
143 |
JCCatch t = (JCCatch) node; |
|
144 |
JCVariableDecl param = copy(t.param, p); |
|
145 |
JCBlock body = copy(t.body, p); |
|
146 |
return M.at(t.pos).Catch(param, body); |
|
147 |
} |
|
148 |
||
149 |
public JCTree visitClass(ClassTree node, P p) { |
|
150 |
JCClassDecl t = (JCClassDecl) node; |
|
151 |
JCModifiers mods = copy(t.mods, p); |
|
152 |
List<JCTypeParameter> typarams = copy(t.typarams, p); |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8031
diff
changeset
|
153 |
JCExpression extending = copy(t.extending, p); |
10 | 154 |
List<JCExpression> implementing = copy(t.implementing, p); |
155 |
List<JCTree> defs = copy(t.defs, p); |
|
156 |
return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs); |
|
157 |
} |
|
158 |
||
159 |
public JCTree visitConditionalExpression(ConditionalExpressionTree node, P p) { |
|
160 |
JCConditional t = (JCConditional) node; |
|
161 |
JCExpression cond = copy(t.cond, p); |
|
162 |
JCExpression truepart = copy(t.truepart, p); |
|
163 |
JCExpression falsepart = copy(t.falsepart, p); |
|
164 |
return M.at(t.pos).Conditional(cond, truepart, falsepart); |
|
165 |
} |
|
166 |
||
167 |
public JCTree visitContinue(ContinueTree node, P p) { |
|
168 |
JCContinue t = (JCContinue) node; |
|
169 |
return M.at(t.pos).Continue(t.label); |
|
170 |
} |
|
171 |
||
172 |
public JCTree visitDoWhileLoop(DoWhileLoopTree node, P p) { |
|
173 |
JCDoWhileLoop t = (JCDoWhileLoop) node; |
|
174 |
JCStatement body = copy(t.body, p); |
|
175 |
JCExpression cond = copy(t.cond, p); |
|
176 |
return M.at(t.pos).DoLoop(body, cond); |
|
177 |
} |
|
178 |
||
179 |
public JCTree visitErroneous(ErroneousTree node, P p) { |
|
180 |
JCErroneous t = (JCErroneous) node; |
|
181 |
List<? extends JCTree> errs = copy(t.errs, p); |
|
182 |
return M.at(t.pos).Erroneous(errs); |
|
183 |
} |
|
184 |
||
185 |
public JCTree visitExpressionStatement(ExpressionStatementTree node, P p) { |
|
186 |
JCExpressionStatement t = (JCExpressionStatement) node; |
|
187 |
JCExpression expr = copy(t.expr, p); |
|
188 |
return M.at(t.pos).Exec(expr); |
|
189 |
} |
|
190 |
||
191 |
public JCTree visitEnhancedForLoop(EnhancedForLoopTree node, P p) { |
|
192 |
JCEnhancedForLoop t = (JCEnhancedForLoop) node; |
|
193 |
JCVariableDecl var = copy(t.var, p); |
|
194 |
JCExpression expr = copy(t.expr, p); |
|
195 |
JCStatement body = copy(t.body, p); |
|
196 |
return M.at(t.pos).ForeachLoop(var, expr, body); |
|
197 |
} |
|
198 |
||
199 |
public JCTree visitForLoop(ForLoopTree node, P p) { |
|
200 |
JCForLoop t = (JCForLoop) node; |
|
201 |
List<JCStatement> init = copy(t.init, p); |
|
202 |
JCExpression cond = copy(t.cond, p); |
|
203 |
List<JCExpressionStatement> step = copy(t.step, p); |
|
204 |
JCStatement body = copy(t.body, p); |
|
205 |
return M.at(t.pos).ForLoop(init, cond, step, body); |
|
206 |
} |
|
207 |
||
208 |
public JCTree visitIdentifier(IdentifierTree node, P p) { |
|
209 |
JCIdent t = (JCIdent) node; |
|
210 |
return M.at(t.pos).Ident(t.name); |
|
211 |
} |
|
212 |
||
213 |
public JCTree visitIf(IfTree node, P p) { |
|
214 |
JCIf t = (JCIf) node; |
|
215 |
JCExpression cond = copy(t.cond, p); |
|
216 |
JCStatement thenpart = copy(t.thenpart, p); |
|
217 |
JCStatement elsepart = copy(t.elsepart, p); |
|
218 |
return M.at(t.pos).If(cond, thenpart, elsepart); |
|
219 |
} |
|
220 |
||
221 |
public JCTree visitImport(ImportTree node, P p) { |
|
222 |
JCImport t = (JCImport) node; |
|
223 |
JCTree qualid = copy(t.qualid, p); |
|
224 |
return M.at(t.pos).Import(qualid, t.staticImport); |
|
225 |
} |
|
226 |
||
227 |
public JCTree visitArrayAccess(ArrayAccessTree node, P p) { |
|
228 |
JCArrayAccess t = (JCArrayAccess) node; |
|
229 |
JCExpression indexed = copy(t.indexed, p); |
|
230 |
JCExpression index = copy(t.index, p); |
|
231 |
return M.at(t.pos).Indexed(indexed, index); |
|
232 |
} |
|
233 |
||
234 |
public JCTree visitLabeledStatement(LabeledStatementTree node, P p) { |
|
235 |
JCLabeledStatement t = (JCLabeledStatement) node; |
|
236 |
JCStatement body = copy(t.body, p); |
|
20243
21740b37e9aa
8025110: TreeCopier does not correctly copy LabeledStatementTree
jjg
parents:
17807
diff
changeset
|
237 |
return M.at(t.pos).Labelled(t.label, body); |
10 | 238 |
} |
239 |
||
240 |
public JCTree visitLiteral(LiteralTree node, P p) { |
|
241 |
JCLiteral t = (JCLiteral) node; |
|
242 |
return M.at(t.pos).Literal(t.typetag, t.value); |
|
243 |
} |
|
244 |
||
245 |
public JCTree visitMethod(MethodTree node, P p) { |
|
246 |
JCMethodDecl t = (JCMethodDecl) node; |
|
247 |
JCModifiers mods = copy(t.mods, p); |
|
248 |
JCExpression restype = copy(t.restype, p); |
|
249 |
List<JCTypeParameter> typarams = copy(t.typarams, p); |
|
250 |
List<JCVariableDecl> params = copy(t.params, p); |
|
15385 | 251 |
JCVariableDecl recvparam = copy(t.recvparam, p); |
10 | 252 |
List<JCExpression> thrown = copy(t.thrown, p); |
253 |
JCBlock body = copy(t.body, p); |
|
254 |
JCExpression defaultValue = copy(t.defaultValue, p); |
|
15385 | 255 |
return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, recvparam, params, thrown, body, defaultValue); |
10 | 256 |
} |
257 |
||
258 |
public JCTree visitMethodInvocation(MethodInvocationTree node, P p) { |
|
259 |
JCMethodInvocation t = (JCMethodInvocation) node; |
|
260 |
List<JCExpression> typeargs = copy(t.typeargs, p); |
|
261 |
JCExpression meth = copy(t.meth, p); |
|
262 |
List<JCExpression> args = copy(t.args, p); |
|
263 |
return M.at(t.pos).Apply(typeargs, meth, args); |
|
264 |
} |
|
265 |
||
266 |
public JCTree visitModifiers(ModifiersTree node, P p) { |
|
267 |
JCModifiers t = (JCModifiers) node; |
|
268 |
List<JCAnnotation> annotations = copy(t.annotations, p); |
|
269 |
return M.at(t.pos).Modifiers(t.flags, annotations); |
|
270 |
} |
|
271 |
||
272 |
public JCTree visitNewArray(NewArrayTree node, P p) { |
|
273 |
JCNewArray t = (JCNewArray) node; |
|
274 |
JCExpression elemtype = copy(t.elemtype, p); |
|
275 |
List<JCExpression> dims = copy(t.dims, p); |
|
276 |
List<JCExpression> elems = copy(t.elems, p); |
|
277 |
return M.at(t.pos).NewArray(elemtype, dims, elems); |
|
278 |
} |
|
279 |
||
280 |
public JCTree visitNewClass(NewClassTree node, P p) { |
|
281 |
JCNewClass t = (JCNewClass) node; |
|
282 |
JCExpression encl = copy(t.encl, p); |
|
283 |
List<JCExpression> typeargs = copy(t.typeargs, p); |
|
284 |
JCExpression clazz = copy(t.clazz, p); |
|
285 |
List<JCExpression> args = copy(t.args, p); |
|
286 |
JCClassDecl def = copy(t.def, p); |
|
287 |
return M.at(t.pos).NewClass(encl, typeargs, clazz, args, def); |
|
288 |
} |
|
289 |
||
11141 | 290 |
public JCTree visitLambdaExpression(LambdaExpressionTree node, P p) { |
291 |
JCLambda t = (JCLambda) node; |
|
292 |
List<JCVariableDecl> params = copy(t.params, p); |
|
293 |
JCTree body = copy(t.body, p); |
|
294 |
return M.at(t.pos).Lambda(params, body); |
|
295 |
} |
|
296 |
||
10 | 297 |
public JCTree visitParenthesized(ParenthesizedTree node, P p) { |
298 |
JCParens t = (JCParens) node; |
|
299 |
JCExpression expr = copy(t.expr, p); |
|
300 |
return M.at(t.pos).Parens(expr); |
|
301 |
} |
|
302 |
||
303 |
public JCTree visitReturn(ReturnTree node, P p) { |
|
304 |
JCReturn t = (JCReturn) node; |
|
305 |
JCExpression expr = copy(t.expr, p); |
|
306 |
return M.at(t.pos).Return(expr); |
|
307 |
} |
|
308 |
||
309 |
public JCTree visitMemberSelect(MemberSelectTree node, P p) { |
|
310 |
JCFieldAccess t = (JCFieldAccess) node; |
|
311 |
JCExpression selected = copy(t.selected, p); |
|
312 |
return M.at(t.pos).Select(selected, t.name); |
|
313 |
} |
|
314 |
||
11142 | 315 |
public JCTree visitMemberReference(MemberReferenceTree node, P p) { |
316 |
JCMemberReference t = (JCMemberReference) node; |
|
317 |
JCExpression expr = copy(t.expr, p); |
|
318 |
List<JCExpression> typeargs = copy(t.typeargs, p); |
|
319 |
return M.at(t.pos).Reference(t.mode, t.name, expr, typeargs); |
|
320 |
} |
|
321 |
||
10 | 322 |
public JCTree visitEmptyStatement(EmptyStatementTree node, P p) { |
323 |
JCSkip t = (JCSkip) node; |
|
324 |
return M.at(t.pos).Skip(); |
|
325 |
} |
|
326 |
||
327 |
public JCTree visitSwitch(SwitchTree node, P p) { |
|
328 |
JCSwitch t = (JCSwitch) node; |
|
329 |
JCExpression selector = copy(t.selector, p); |
|
330 |
List<JCCase> cases = copy(t.cases, p); |
|
331 |
return M.at(t.pos).Switch(selector, cases); |
|
332 |
} |
|
333 |
||
334 |
public JCTree visitSynchronized(SynchronizedTree node, P p) { |
|
335 |
JCSynchronized t = (JCSynchronized) node; |
|
336 |
JCExpression lock = copy(t.lock, p); |
|
337 |
JCBlock body = copy(t.body, p); |
|
338 |
return M.at(t.pos).Synchronized(lock, body); |
|
339 |
} |
|
340 |
||
341 |
public JCTree visitThrow(ThrowTree node, P p) { |
|
342 |
JCThrow t = (JCThrow) node; |
|
17807
36cff8c58cdf
7030476: Fix conflicting use of JCTree/JCExpression
vromero
parents:
17578
diff
changeset
|
343 |
JCExpression expr = copy(t.expr, p); |
10 | 344 |
return M.at(t.pos).Throw(expr); |
345 |
} |
|
346 |
||
347 |
public JCTree visitCompilationUnit(CompilationUnitTree node, P p) { |
|
348 |
JCCompilationUnit t = (JCCompilationUnit) node; |
|
24069 | 349 |
List<JCTree> defs = copy(t.defs, p); |
350 |
return M.at(t.pos).TopLevel(defs); |
|
351 |
} |
|
352 |
||
353 |
public JCTree visitPackage(PackageTree node, P p) { |
|
354 |
JCPackageDecl t = (JCPackageDecl) node; |
|
355 |
List<JCAnnotation> annotations = copy(t.annotations, p); |
|
10 | 356 |
JCExpression pid = copy(t.pid, p); |
24069 | 357 |
return M.at(t.pos).PackageDecl(annotations, pid); |
10 | 358 |
} |
359 |
||
360 |
public JCTree visitTry(TryTree node, P p) { |
|
361 |
JCTry t = (JCTry) node; |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
362 |
List<JCTree> resources = copy(t.resources, p); |
10 | 363 |
JCBlock body = copy(t.body, p); |
364 |
List<JCCatch> catchers = copy(t.catchers, p); |
|
365 |
JCBlock finalizer = copy(t.finalizer, p); |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
366 |
return M.at(t.pos).Try(resources, body, catchers, finalizer); |
10 | 367 |
} |
368 |
||
369 |
public JCTree visitParameterizedType(ParameterizedTypeTree node, P p) { |
|
370 |
JCTypeApply t = (JCTypeApply) node; |
|
371 |
JCExpression clazz = copy(t.clazz, p); |
|
372 |
List<JCExpression> arguments = copy(t.arguments, p); |
|
373 |
return M.at(t.pos).TypeApply(clazz, arguments); |
|
374 |
} |
|
375 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8625
diff
changeset
|
376 |
public JCTree visitUnionType(UnionTypeTree node, P p) { |
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8625
diff
changeset
|
377 |
JCTypeUnion t = (JCTypeUnion) node; |
7074 | 378 |
List<JCExpression> components = copy(t.alternatives, p); |
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8625
diff
changeset
|
379 |
return M.at(t.pos).TypeUnion(components); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
3149
diff
changeset
|
380 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
3149
diff
changeset
|
381 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
382 |
public JCTree visitIntersectionType(IntersectionTypeTree node, P p) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
383 |
JCTypeIntersection t = (JCTypeIntersection) node; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
384 |
List<JCExpression> bounds = copy(t.bounds, p); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
385 |
return M.at(t.pos).TypeIntersection(bounds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
386 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
11142
diff
changeset
|
387 |
|
10 | 388 |
public JCTree visitArrayType(ArrayTypeTree node, P p) { |
389 |
JCArrayTypeTree t = (JCArrayTypeTree) node; |
|
390 |
JCExpression elemtype = copy(t.elemtype, p); |
|
391 |
return M.at(t.pos).TypeArray(elemtype); |
|
392 |
} |
|
393 |
||
394 |
public JCTree visitTypeCast(TypeCastTree node, P p) { |
|
395 |
JCTypeCast t = (JCTypeCast) node; |
|
396 |
JCTree clazz = copy(t.clazz, p); |
|
397 |
JCExpression expr = copy(t.expr, p); |
|
398 |
return M.at(t.pos).TypeCast(clazz, expr); |
|
399 |
} |
|
400 |
||
401 |
public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) { |
|
402 |
JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node; |
|
403 |
return M.at(t.pos).TypeIdent(t.typetag); |
|
404 |
} |
|
405 |
||
406 |
public JCTree visitTypeParameter(TypeParameterTree node, P p) { |
|
407 |
JCTypeParameter t = (JCTypeParameter) node; |
|
15385 | 408 |
List<JCAnnotation> annos = copy(t.annotations, p); |
10 | 409 |
List<JCExpression> bounds = copy(t.bounds, p); |
15385 | 410 |
return M.at(t.pos).TypeParameter(t.name, bounds, annos); |
10 | 411 |
} |
412 |
||
413 |
public JCTree visitInstanceOf(InstanceOfTree node, P p) { |
|
414 |
JCInstanceOf t = (JCInstanceOf) node; |
|
415 |
JCExpression expr = copy(t.expr, p); |
|
416 |
JCTree clazz = copy(t.clazz, p); |
|
417 |
return M.at(t.pos).TypeTest(expr, clazz); |
|
418 |
} |
|
419 |
||
420 |
public JCTree visitUnary(UnaryTree node, P p) { |
|
421 |
JCUnary t = (JCUnary) node; |
|
422 |
JCExpression arg = copy(t.arg, p); |
|
423 |
return M.at(t.pos).Unary(t.getTag(), arg); |
|
424 |
} |
|
425 |
||
426 |
public JCTree visitVariable(VariableTree node, P p) { |
|
427 |
JCVariableDecl t = (JCVariableDecl) node; |
|
428 |
JCModifiers mods = copy(t.mods, p); |
|
429 |
JCExpression vartype = copy(t.vartype, p); |
|
17578 | 430 |
if (t.nameexpr == null) { |
431 |
JCExpression init = copy(t.init, p); |
|
432 |
return M.at(t.pos).VarDef(mods, t.name, vartype, init); |
|
433 |
} else { |
|
434 |
JCExpression nameexpr = copy(t.nameexpr, p); |
|
435 |
return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype); |
|
436 |
} |
|
10 | 437 |
} |
438 |
||
439 |
public JCTree visitWhileLoop(WhileLoopTree node, P p) { |
|
440 |
JCWhileLoop t = (JCWhileLoop) node; |
|
441 |
JCStatement body = copy(t.body, p); |
|
442 |
JCExpression cond = copy(t.cond, p); |
|
443 |
return M.at(t.pos).WhileLoop(cond, body); |
|
444 |
} |
|
445 |
||
446 |
public JCTree visitWildcard(WildcardTree node, P p) { |
|
447 |
JCWildcard t = (JCWildcard) node; |
|
448 |
TypeBoundKind kind = M.at(t.kind.pos).TypeBoundKind(t.kind.kind); |
|
449 |
JCTree inner = copy(t.inner, p); |
|
450 |
return M.at(t.pos).Wildcard(kind, inner); |
|
451 |
} |
|
452 |
||
453 |
public JCTree visitOther(Tree node, P p) { |
|
454 |
JCTree tree = (JCTree) node; |
|
455 |
switch (tree.getTag()) { |
|
10950 | 456 |
case LETEXPR: { |
10 | 457 |
LetExpr t = (LetExpr) node; |
458 |
List<JCVariableDecl> defs = copy(t.defs, p); |
|
459 |
JCTree expr = copy(t.expr, p); |
|
460 |
return M.at(t.pos).LetExpr(defs, expr); |
|
461 |
} |
|
462 |
default: |
|
463 |
throw new AssertionError("unknown tree tag: " + tree.getTag()); |
|
464 |
} |
|
465 |
} |
|
466 |
||
467 |
} |