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