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