author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 22154 | 3c8d86bf756b |
child 24069 | dfb8f11542fc |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 1999, 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.tools.javac.code.*; |
|
29 |
import com.sun.tools.javac.code.Symbol.*; |
|
30 |
import com.sun.tools.javac.code.Type.*; |
|
31 |
import com.sun.tools.javac.util.*; |
|
32 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
33 |
||
34 |
import com.sun.tools.javac.tree.JCTree.*; |
|
35 |
||
36 |
import static com.sun.tools.javac.code.Flags.*; |
|
37 |
import static com.sun.tools.javac.code.Kinds.*; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13845
diff
changeset
|
38 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 39 |
|
40 |
/** Factory class for trees. |
|
41 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
42 |
* <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
|
43 |
* If you write code that depends on this, you do so at your own risk. |
10 | 44 |
* This code and its internal interfaces are subject to change or |
45 |
* deletion without notice.</b> |
|
46 |
*/ |
|
47 |
public class TreeMaker implements JCTree.Factory { |
|
48 |
||
49 |
/** The context key for the tree factory. */ |
|
22163 | 50 |
protected static final Context.Key<TreeMaker> treeMakerKey = new Context.Key<>(); |
10 | 51 |
|
52 |
/** Get the TreeMaker instance. */ |
|
53 |
public static TreeMaker instance(Context context) { |
|
54 |
TreeMaker instance = context.get(treeMakerKey); |
|
55 |
if (instance == null) |
|
56 |
instance = new TreeMaker(context); |
|
57 |
return instance; |
|
58 |
} |
|
59 |
||
60 |
/** The position at which subsequent trees will be created. |
|
61 |
*/ |
|
62 |
public int pos = Position.NOPOS; |
|
63 |
||
64 |
/** The toplevel tree to which created trees belong. |
|
65 |
*/ |
|
66 |
public JCCompilationUnit toplevel; |
|
67 |
||
68 |
/** The current name table. */ |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
69 |
Names names; |
10 | 70 |
|
71 |
Types types; |
|
72 |
||
73 |
/** The current symbol table. */ |
|
74 |
Symtab syms; |
|
75 |
||
76 |
/** Create a tree maker with null toplevel and NOPOS as initial position. |
|
77 |
*/ |
|
78 |
protected TreeMaker(Context context) { |
|
79 |
context.put(treeMakerKey, this); |
|
80 |
this.pos = Position.NOPOS; |
|
81 |
this.toplevel = null; |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
82 |
this.names = Names.instance(context); |
10 | 83 |
this.syms = Symtab.instance(context); |
84 |
this.types = Types.instance(context); |
|
85 |
} |
|
86 |
||
87 |
/** Create a tree maker with a given toplevel and FIRSTPOS as initial position. |
|
88 |
*/ |
|
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13689
diff
changeset
|
89 |
protected TreeMaker(JCCompilationUnit toplevel, Names names, Types types, Symtab syms) { |
10 | 90 |
this.pos = Position.FIRSTPOS; |
91 |
this.toplevel = toplevel; |
|
92 |
this.names = names; |
|
93 |
this.types = types; |
|
94 |
this.syms = syms; |
|
95 |
} |
|
96 |
||
97 |
/** Create a new tree maker for a given toplevel. |
|
98 |
*/ |
|
99 |
public TreeMaker forToplevel(JCCompilationUnit toplevel) { |
|
100 |
return new TreeMaker(toplevel, names, types, syms); |
|
101 |
} |
|
102 |
||
103 |
/** Reassign current position. |
|
104 |
*/ |
|
105 |
public TreeMaker at(int pos) { |
|
106 |
this.pos = pos; |
|
107 |
return this; |
|
108 |
} |
|
109 |
||
110 |
/** Reassign current position. |
|
111 |
*/ |
|
112 |
public TreeMaker at(DiagnosticPosition pos) { |
|
113 |
this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); |
|
114 |
return this; |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* Create given tree node at current position. |
|
119 |
* @param defs a list of ClassDef, Import, and Skip |
|
120 |
*/ |
|
121 |
public JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations, |
|
122 |
JCExpression pid, |
|
123 |
List<JCTree> defs) { |
|
8032 | 124 |
Assert.checkNonNull(packageAnnotations); |
10 | 125 |
for (JCTree node : defs) |
8032 | 126 |
Assert.check(node instanceof JCClassDecl |
10 | 127 |
|| node instanceof JCImport |
128 |
|| node instanceof JCSkip |
|
129 |
|| node instanceof JCErroneous |
|
130 |
|| (node instanceof JCExpressionStatement |
|
8032 | 131 |
&& ((JCExpressionStatement)node).expr instanceof JCErroneous), |
132 |
node.getClass().getSimpleName()); |
|
10 | 133 |
JCCompilationUnit tree = new JCCompilationUnit(packageAnnotations, pid, defs, |
134 |
null, null, null, null); |
|
135 |
tree.pos = pos; |
|
136 |
return tree; |
|
137 |
} |
|
138 |
||
139 |
public JCImport Import(JCTree qualid, boolean importStatic) { |
|
140 |
JCImport tree = new JCImport(qualid, importStatic); |
|
141 |
tree.pos = pos; |
|
142 |
return tree; |
|
143 |
} |
|
144 |
||
145 |
public JCClassDecl ClassDef(JCModifiers mods, |
|
146 |
Name name, |
|
147 |
List<JCTypeParameter> typarams, |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8032
diff
changeset
|
148 |
JCExpression extending, |
10 | 149 |
List<JCExpression> implementing, |
150 |
List<JCTree> defs) |
|
151 |
{ |
|
152 |
JCClassDecl tree = new JCClassDecl(mods, |
|
153 |
name, |
|
154 |
typarams, |
|
155 |
extending, |
|
156 |
implementing, |
|
157 |
defs, |
|
158 |
null); |
|
159 |
tree.pos = pos; |
|
160 |
return tree; |
|
161 |
} |
|
162 |
||
163 |
public JCMethodDecl MethodDef(JCModifiers mods, |
|
164 |
Name name, |
|
165 |
JCExpression restype, |
|
166 |
List<JCTypeParameter> typarams, |
|
167 |
List<JCVariableDecl> params, |
|
168 |
List<JCExpression> thrown, |
|
169 |
JCBlock body, |
|
3149 | 170 |
JCExpression defaultValue) { |
15385 | 171 |
return MethodDef( |
172 |
mods, name, restype, typarams, null, params, |
|
173 |
thrown, body, defaultValue); |
|
174 |
} |
|
175 |
||
176 |
public JCMethodDecl MethodDef(JCModifiers mods, |
|
177 |
Name name, |
|
178 |
JCExpression restype, |
|
179 |
List<JCTypeParameter> typarams, |
|
180 |
JCVariableDecl recvparam, |
|
181 |
List<JCVariableDecl> params, |
|
182 |
List<JCExpression> thrown, |
|
183 |
JCBlock body, |
|
184 |
JCExpression defaultValue) |
|
185 |
{ |
|
10 | 186 |
JCMethodDecl tree = new JCMethodDecl(mods, |
187 |
name, |
|
188 |
restype, |
|
189 |
typarams, |
|
15385 | 190 |
recvparam, |
10 | 191 |
params, |
192 |
thrown, |
|
193 |
body, |
|
194 |
defaultValue, |
|
195 |
null); |
|
196 |
tree.pos = pos; |
|
197 |
return tree; |
|
198 |
} |
|
199 |
||
200 |
public JCVariableDecl VarDef(JCModifiers mods, Name name, JCExpression vartype, JCExpression init) { |
|
201 |
JCVariableDecl tree = new JCVariableDecl(mods, name, vartype, init, null); |
|
202 |
tree.pos = pos; |
|
203 |
return tree; |
|
204 |
} |
|
205 |
||
17578 | 206 |
public JCVariableDecl ReceiverVarDef(JCModifiers mods, JCExpression name, JCExpression vartype) { |
207 |
JCVariableDecl tree = new JCVariableDecl(mods, name, vartype); |
|
208 |
tree.pos = pos; |
|
209 |
return tree; |
|
210 |
} |
|
211 |
||
10 | 212 |
public JCSkip Skip() { |
213 |
JCSkip tree = new JCSkip(); |
|
214 |
tree.pos = pos; |
|
215 |
return tree; |
|
216 |
} |
|
217 |
||
218 |
public JCBlock Block(long flags, List<JCStatement> stats) { |
|
219 |
JCBlock tree = new JCBlock(flags, stats); |
|
220 |
tree.pos = pos; |
|
221 |
return tree; |
|
222 |
} |
|
223 |
||
224 |
public JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond) { |
|
225 |
JCDoWhileLoop tree = new JCDoWhileLoop(body, cond); |
|
226 |
tree.pos = pos; |
|
227 |
return tree; |
|
228 |
} |
|
229 |
||
230 |
public JCWhileLoop WhileLoop(JCExpression cond, JCStatement body) { |
|
231 |
JCWhileLoop tree = new JCWhileLoop(cond, body); |
|
232 |
tree.pos = pos; |
|
233 |
return tree; |
|
234 |
} |
|
235 |
||
236 |
public JCForLoop ForLoop(List<JCStatement> init, |
|
237 |
JCExpression cond, |
|
238 |
List<JCExpressionStatement> step, |
|
239 |
JCStatement body) |
|
240 |
{ |
|
241 |
JCForLoop tree = new JCForLoop(init, cond, step, body); |
|
242 |
tree.pos = pos; |
|
243 |
return tree; |
|
244 |
} |
|
245 |
||
246 |
public JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body) { |
|
247 |
JCEnhancedForLoop tree = new JCEnhancedForLoop(var, expr, body); |
|
248 |
tree.pos = pos; |
|
249 |
return tree; |
|
250 |
} |
|
251 |
||
252 |
public JCLabeledStatement Labelled(Name label, JCStatement body) { |
|
253 |
JCLabeledStatement tree = new JCLabeledStatement(label, body); |
|
254 |
tree.pos = pos; |
|
255 |
return tree; |
|
256 |
} |
|
257 |
||
258 |
public JCSwitch Switch(JCExpression selector, List<JCCase> cases) { |
|
259 |
JCSwitch tree = new JCSwitch(selector, cases); |
|
260 |
tree.pos = pos; |
|
261 |
return tree; |
|
262 |
} |
|
263 |
||
264 |
public JCCase Case(JCExpression pat, List<JCStatement> stats) { |
|
265 |
JCCase tree = new JCCase(pat, stats); |
|
266 |
tree.pos = pos; |
|
267 |
return tree; |
|
268 |
} |
|
269 |
||
270 |
public JCSynchronized Synchronized(JCExpression lock, JCBlock body) { |
|
271 |
JCSynchronized tree = new JCSynchronized(lock, body); |
|
272 |
tree.pos = pos; |
|
273 |
return tree; |
|
274 |
} |
|
275 |
||
276 |
public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
277 |
return Try(List.<JCTree>nil(), body, catchers, finalizer); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
278 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
279 |
|
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
280 |
public JCTry Try(List<JCTree> resources, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
281 |
JCBlock body, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
282 |
List<JCCatch> catchers, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
283 |
JCBlock finalizer) { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
284 |
JCTry tree = new JCTry(resources, body, catchers, finalizer); |
10 | 285 |
tree.pos = pos; |
286 |
return tree; |
|
287 |
} |
|
288 |
||
289 |
public JCCatch Catch(JCVariableDecl param, JCBlock body) { |
|
290 |
JCCatch tree = new JCCatch(param, body); |
|
291 |
tree.pos = pos; |
|
292 |
return tree; |
|
293 |
} |
|
294 |
||
295 |
public JCConditional Conditional(JCExpression cond, |
|
296 |
JCExpression thenpart, |
|
297 |
JCExpression elsepart) |
|
298 |
{ |
|
299 |
JCConditional tree = new JCConditional(cond, thenpart, elsepart); |
|
300 |
tree.pos = pos; |
|
301 |
return tree; |
|
302 |
} |
|
303 |
||
304 |
public JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart) { |
|
305 |
JCIf tree = new JCIf(cond, thenpart, elsepart); |
|
306 |
tree.pos = pos; |
|
307 |
return tree; |
|
308 |
} |
|
309 |
||
310 |
public JCExpressionStatement Exec(JCExpression expr) { |
|
311 |
JCExpressionStatement tree = new JCExpressionStatement(expr); |
|
312 |
tree.pos = pos; |
|
313 |
return tree; |
|
314 |
} |
|
315 |
||
316 |
public JCBreak Break(Name label) { |
|
317 |
JCBreak tree = new JCBreak(label, null); |
|
318 |
tree.pos = pos; |
|
319 |
return tree; |
|
320 |
} |
|
321 |
||
322 |
public JCContinue Continue(Name label) { |
|
323 |
JCContinue tree = new JCContinue(label, null); |
|
324 |
tree.pos = pos; |
|
325 |
return tree; |
|
326 |
} |
|
327 |
||
328 |
public JCReturn Return(JCExpression expr) { |
|
329 |
JCReturn tree = new JCReturn(expr); |
|
330 |
tree.pos = pos; |
|
331 |
return tree; |
|
332 |
} |
|
333 |
||
17807
36cff8c58cdf
7030476: Fix conflicting use of JCTree/JCExpression
vromero
parents:
17578
diff
changeset
|
334 |
public JCThrow Throw(JCExpression expr) { |
10 | 335 |
JCThrow tree = new JCThrow(expr); |
336 |
tree.pos = pos; |
|
337 |
return tree; |
|
338 |
} |
|
339 |
||
340 |
public JCAssert Assert(JCExpression cond, JCExpression detail) { |
|
341 |
JCAssert tree = new JCAssert(cond, detail); |
|
342 |
tree.pos = pos; |
|
343 |
return tree; |
|
344 |
} |
|
345 |
||
346 |
public JCMethodInvocation Apply(List<JCExpression> typeargs, |
|
347 |
JCExpression fn, |
|
348 |
List<JCExpression> args) |
|
349 |
{ |
|
350 |
JCMethodInvocation tree = new JCMethodInvocation(typeargs, fn, args); |
|
351 |
tree.pos = pos; |
|
352 |
return tree; |
|
353 |
} |
|
354 |
||
355 |
public JCNewClass NewClass(JCExpression encl, |
|
356 |
List<JCExpression> typeargs, |
|
357 |
JCExpression clazz, |
|
358 |
List<JCExpression> args, |
|
359 |
JCClassDecl def) |
|
360 |
{ |
|
361 |
JCNewClass tree = new JCNewClass(encl, typeargs, clazz, args, def); |
|
362 |
tree.pos = pos; |
|
363 |
return tree; |
|
364 |
} |
|
365 |
||
366 |
public JCNewArray NewArray(JCExpression elemtype, |
|
367 |
List<JCExpression> dims, |
|
368 |
List<JCExpression> elems) |
|
369 |
{ |
|
370 |
JCNewArray tree = new JCNewArray(elemtype, dims, elems); |
|
371 |
tree.pos = pos; |
|
372 |
return tree; |
|
373 |
} |
|
374 |
||
11141 | 375 |
public JCLambda Lambda(List<JCVariableDecl> params, |
376 |
JCTree body) |
|
377 |
{ |
|
378 |
JCLambda tree = new JCLambda(params, body); |
|
379 |
tree.pos = pos; |
|
380 |
return tree; |
|
381 |
} |
|
382 |
||
10 | 383 |
public JCParens Parens(JCExpression expr) { |
384 |
JCParens tree = new JCParens(expr); |
|
385 |
tree.pos = pos; |
|
386 |
return tree; |
|
387 |
} |
|
388 |
||
389 |
public JCAssign Assign(JCExpression lhs, JCExpression rhs) { |
|
390 |
JCAssign tree = new JCAssign(lhs, rhs); |
|
391 |
tree.pos = pos; |
|
392 |
return tree; |
|
393 |
} |
|
394 |
||
10950 | 395 |
public JCAssignOp Assignop(JCTree.Tag opcode, JCTree lhs, JCTree rhs) { |
10 | 396 |
JCAssignOp tree = new JCAssignOp(opcode, lhs, rhs, null); |
397 |
tree.pos = pos; |
|
398 |
return tree; |
|
399 |
} |
|
400 |
||
10950 | 401 |
public JCUnary Unary(JCTree.Tag opcode, JCExpression arg) { |
10 | 402 |
JCUnary tree = new JCUnary(opcode, arg); |
403 |
tree.pos = pos; |
|
404 |
return tree; |
|
405 |
} |
|
406 |
||
10950 | 407 |
public JCBinary Binary(JCTree.Tag opcode, JCExpression lhs, JCExpression rhs) { |
10 | 408 |
JCBinary tree = new JCBinary(opcode, lhs, rhs, null); |
409 |
tree.pos = pos; |
|
410 |
return tree; |
|
411 |
} |
|
412 |
||
413 |
public JCTypeCast TypeCast(JCTree clazz, JCExpression expr) { |
|
414 |
JCTypeCast tree = new JCTypeCast(clazz, expr); |
|
415 |
tree.pos = pos; |
|
416 |
return tree; |
|
417 |
} |
|
418 |
||
419 |
public JCInstanceOf TypeTest(JCExpression expr, JCTree clazz) { |
|
420 |
JCInstanceOf tree = new JCInstanceOf(expr, clazz); |
|
421 |
tree.pos = pos; |
|
422 |
return tree; |
|
423 |
} |
|
424 |
||
425 |
public JCArrayAccess Indexed(JCExpression indexed, JCExpression index) { |
|
426 |
JCArrayAccess tree = new JCArrayAccess(indexed, index); |
|
427 |
tree.pos = pos; |
|
428 |
return tree; |
|
429 |
} |
|
430 |
||
431 |
public JCFieldAccess Select(JCExpression selected, Name selector) { |
|
432 |
JCFieldAccess tree = new JCFieldAccess(selected, selector, null); |
|
433 |
tree.pos = pos; |
|
434 |
return tree; |
|
435 |
} |
|
436 |
||
11142 | 437 |
public JCMemberReference Reference(JCMemberReference.ReferenceMode mode, Name name, |
438 |
JCExpression expr, List<JCExpression> typeargs) { |
|
439 |
JCMemberReference tree = new JCMemberReference(mode, name, expr, typeargs); |
|
440 |
tree.pos = pos; |
|
441 |
return tree; |
|
442 |
} |
|
443 |
||
10 | 444 |
public JCIdent Ident(Name name) { |
445 |
JCIdent tree = new JCIdent(name, null); |
|
446 |
tree.pos = pos; |
|
447 |
return tree; |
|
448 |
} |
|
449 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13845
diff
changeset
|
450 |
public JCLiteral Literal(TypeTag tag, Object value) { |
10 | 451 |
JCLiteral tree = new JCLiteral(tag, value); |
452 |
tree.pos = pos; |
|
453 |
return tree; |
|
454 |
} |
|
455 |
||
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13845
diff
changeset
|
456 |
public JCPrimitiveTypeTree TypeIdent(TypeTag typetag) { |
10 | 457 |
JCPrimitiveTypeTree tree = new JCPrimitiveTypeTree(typetag); |
458 |
tree.pos = pos; |
|
459 |
return tree; |
|
460 |
} |
|
461 |
||
462 |
public JCArrayTypeTree TypeArray(JCExpression elemtype) { |
|
463 |
JCArrayTypeTree tree = new JCArrayTypeTree(elemtype); |
|
464 |
tree.pos = pos; |
|
465 |
return tree; |
|
466 |
} |
|
467 |
||
468 |
public JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments) { |
|
469 |
JCTypeApply tree = new JCTypeApply(clazz, arguments); |
|
470 |
tree.pos = pos; |
|
471 |
return tree; |
|
472 |
} |
|
473 |
||
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8625
diff
changeset
|
474 |
public JCTypeUnion TypeUnion(List<JCExpression> components) { |
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
8625
diff
changeset
|
475 |
JCTypeUnion tree = new JCTypeUnion(components); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4870
diff
changeset
|
476 |
tree.pos = pos; |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4870
diff
changeset
|
477 |
return tree; |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4870
diff
changeset
|
478 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
4870
diff
changeset
|
479 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
480 |
public JCTypeIntersection TypeIntersection(List<JCExpression> components) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
481 |
JCTypeIntersection tree = new JCTypeIntersection(components); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
482 |
tree.pos = pos; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
483 |
return tree; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
484 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14359
diff
changeset
|
485 |
|
10 | 486 |
public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds) { |
15385 | 487 |
return TypeParameter(name, bounds, List.<JCAnnotation>nil()); |
488 |
} |
|
489 |
||
490 |
public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annos) { |
|
491 |
JCTypeParameter tree = new JCTypeParameter(name, bounds, annos); |
|
10 | 492 |
tree.pos = pos; |
493 |
return tree; |
|
494 |
} |
|
495 |
||
496 |
public JCWildcard Wildcard(TypeBoundKind kind, JCTree type) { |
|
497 |
JCWildcard tree = new JCWildcard(kind, type); |
|
498 |
tree.pos = pos; |
|
499 |
return tree; |
|
500 |
} |
|
501 |
||
502 |
public TypeBoundKind TypeBoundKind(BoundKind kind) { |
|
503 |
TypeBoundKind tree = new TypeBoundKind(kind); |
|
504 |
tree.pos = pos; |
|
505 |
return tree; |
|
506 |
} |
|
507 |
||
508 |
public JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args) { |
|
15385 | 509 |
JCAnnotation tree = new JCAnnotation(Tag.ANNOTATION, annotationType, args); |
510 |
tree.pos = pos; |
|
511 |
return tree; |
|
512 |
} |
|
513 |
||
514 |
public JCAnnotation TypeAnnotation(JCTree annotationType, List<JCExpression> args) { |
|
515 |
JCAnnotation tree = new JCAnnotation(Tag.TYPE_ANNOTATION, annotationType, args); |
|
10 | 516 |
tree.pos = pos; |
517 |
return tree; |
|
518 |
} |
|
519 |
||
520 |
public JCModifiers Modifiers(long flags, List<JCAnnotation> annotations) { |
|
521 |
JCModifiers tree = new JCModifiers(flags, annotations); |
|
6152
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
6148
diff
changeset
|
522 |
boolean noFlags = (flags & (Flags.ModifierFlags | Flags.ANNOTATION)) == 0; |
10 | 523 |
tree.pos = (noFlags && annotations.isEmpty()) ? Position.NOPOS : pos; |
524 |
return tree; |
|
525 |
} |
|
526 |
||
527 |
public JCModifiers Modifiers(long flags) { |
|
528 |
return Modifiers(flags, List.<JCAnnotation>nil()); |
|
529 |
} |
|
530 |
||
15385 | 531 |
public JCAnnotatedType AnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) { |
532 |
JCAnnotatedType tree = new JCAnnotatedType(annotations, underlyingType); |
|
533 |
tree.pos = pos; |
|
534 |
return tree; |
|
535 |
} |
|
536 |
||
10 | 537 |
public JCErroneous Erroneous() { |
538 |
return Erroneous(List.<JCTree>nil()); |
|
539 |
} |
|
540 |
||
541 |
public JCErroneous Erroneous(List<? extends JCTree> errs) { |
|
542 |
JCErroneous tree = new JCErroneous(errs); |
|
543 |
tree.pos = pos; |
|
544 |
return tree; |
|
545 |
} |
|
546 |
||
547 |
public LetExpr LetExpr(List<JCVariableDecl> defs, JCTree expr) { |
|
548 |
LetExpr tree = new LetExpr(defs, expr); |
|
549 |
tree.pos = pos; |
|
550 |
return tree; |
|
551 |
} |
|
552 |
||
553 |
/* *************************************************************************** |
|
554 |
* Derived building blocks. |
|
555 |
****************************************************************************/ |
|
556 |
||
557 |
public JCClassDecl AnonymousClassDef(JCModifiers mods, |
|
558 |
List<JCTree> defs) |
|
559 |
{ |
|
560 |
return ClassDef(mods, |
|
561 |
names.empty, |
|
562 |
List.<JCTypeParameter>nil(), |
|
563 |
null, |
|
564 |
List.<JCExpression>nil(), |
|
565 |
defs); |
|
566 |
} |
|
567 |
||
568 |
public LetExpr LetExpr(JCVariableDecl def, JCTree expr) { |
|
569 |
LetExpr tree = new LetExpr(List.of(def), expr); |
|
570 |
tree.pos = pos; |
|
571 |
return tree; |
|
572 |
} |
|
573 |
||
574 |
/** Create an identifier from a symbol. |
|
575 |
*/ |
|
576 |
public JCIdent Ident(Symbol sym) { |
|
577 |
return (JCIdent)new JCIdent((sym.name != names.empty) |
|
578 |
? sym.name |
|
579 |
: sym.flatName(), sym) |
|
580 |
.setPos(pos) |
|
581 |
.setType(sym.type); |
|
582 |
} |
|
583 |
||
584 |
/** Create a selection node from a qualifier tree and a symbol. |
|
585 |
* @param base The qualifier tree. |
|
586 |
*/ |
|
587 |
public JCExpression Select(JCExpression base, Symbol sym) { |
|
588 |
return new JCFieldAccess(base, sym.name, sym).setPos(pos).setType(sym.type); |
|
589 |
} |
|
590 |
||
591 |
/** Create a qualified identifier from a symbol, adding enough qualifications |
|
592 |
* to make the reference unique. |
|
593 |
*/ |
|
594 |
public JCExpression QualIdent(Symbol sym) { |
|
595 |
return isUnqualifiable(sym) |
|
596 |
? Ident(sym) |
|
597 |
: Select(QualIdent(sym.owner), sym); |
|
598 |
} |
|
599 |
||
600 |
/** Create an identifier that refers to the variable declared in given variable |
|
601 |
* declaration. |
|
602 |
*/ |
|
603 |
public JCExpression Ident(JCVariableDecl param) { |
|
604 |
return Ident(param.sym); |
|
605 |
} |
|
606 |
||
607 |
/** Create a list of identifiers referring to the variables declared |
|
608 |
* in given list of variable declarations. |
|
609 |
*/ |
|
610 |
public List<JCExpression> Idents(List<JCVariableDecl> params) { |
|
22163 | 611 |
ListBuffer<JCExpression> ids = new ListBuffer<>(); |
10 | 612 |
for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) |
613 |
ids.append(Ident(l.head)); |
|
614 |
return ids.toList(); |
|
615 |
} |
|
616 |
||
617 |
/** Create a tree representing `this', given its type. |
|
618 |
*/ |
|
619 |
public JCExpression This(Type t) { |
|
620 |
return Ident(new VarSymbol(FINAL, names._this, t, t.tsym)); |
|
621 |
} |
|
622 |
||
623 |
/** Create a tree representing a class literal. |
|
624 |
*/ |
|
625 |
public JCExpression ClassLiteral(ClassSymbol clazz) { |
|
626 |
return ClassLiteral(clazz.type); |
|
627 |
} |
|
628 |
||
629 |
/** Create a tree representing a class literal. |
|
630 |
*/ |
|
631 |
public JCExpression ClassLiteral(Type t) { |
|
632 |
VarSymbol lit = new VarSymbol(STATIC | PUBLIC | FINAL, |
|
633 |
names._class, |
|
634 |
t, |
|
635 |
t.tsym); |
|
636 |
return Select(Type(t), lit); |
|
637 |
} |
|
638 |
||
639 |
/** Create a tree representing `super', given its type and owner. |
|
640 |
*/ |
|
641 |
public JCIdent Super(Type t, TypeSymbol owner) { |
|
642 |
return Ident(new VarSymbol(FINAL, names._super, t, owner)); |
|
643 |
} |
|
644 |
||
645 |
/** |
|
646 |
* Create a method invocation from a method tree and a list of |
|
647 |
* argument trees. |
|
648 |
*/ |
|
649 |
public JCMethodInvocation App(JCExpression meth, List<JCExpression> args) { |
|
650 |
return Apply(null, meth, args).setType(meth.type.getReturnType()); |
|
651 |
} |
|
652 |
||
653 |
/** |
|
654 |
* Create a no-arg method invocation from a method tree |
|
655 |
*/ |
|
656 |
public JCMethodInvocation App(JCExpression meth) { |
|
657 |
return Apply(null, meth, List.<JCExpression>nil()).setType(meth.type.getReturnType()); |
|
658 |
} |
|
659 |
||
660 |
/** Create a method invocation from a method tree and a list of argument trees. |
|
661 |
*/ |
|
662 |
public JCExpression Create(Symbol ctor, List<JCExpression> args) { |
|
663 |
Type t = ctor.owner.erasure(types); |
|
664 |
JCNewClass newclass = NewClass(null, null, Type(t), args, null); |
|
665 |
newclass.constructor = ctor; |
|
666 |
newclass.setType(t); |
|
667 |
return newclass; |
|
668 |
} |
|
669 |
||
670 |
/** Create a tree representing given type. |
|
671 |
*/ |
|
672 |
public JCExpression Type(Type t) { |
|
673 |
if (t == null) return null; |
|
674 |
JCExpression tp; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13845
diff
changeset
|
675 |
switch (t.getTag()) { |
10 | 676 |
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: |
677 |
case DOUBLE: case BOOLEAN: case VOID: |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13845
diff
changeset
|
678 |
tp = TypeIdent(t.getTag()); |
10 | 679 |
break; |
680 |
case TYPEVAR: |
|
681 |
tp = Ident(t.tsym); |
|
682 |
break; |
|
683 |
case WILDCARD: { |
|
684 |
WildcardType a = ((WildcardType) t); |
|
685 |
tp = Wildcard(TypeBoundKind(a.kind), Type(a.type)); |
|
686 |
break; |
|
687 |
} |
|
688 |
case CLASS: |
|
689 |
Type outer = t.getEnclosingType(); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13845
diff
changeset
|
690 |
JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP |
10 | 691 |
? Select(Type(outer), t.tsym) |
692 |
: QualIdent(t.tsym); |
|
693 |
tp = t.getTypeArguments().isEmpty() |
|
694 |
? clazz |
|
695 |
: TypeApply(clazz, Types(t.getTypeArguments())); |
|
696 |
break; |
|
697 |
case ARRAY: |
|
698 |
tp = TypeArray(Type(types.elemtype(t))); |
|
699 |
break; |
|
700 |
case ERROR: |
|
701 |
tp = TypeIdent(ERROR); |
|
702 |
break; |
|
703 |
default: |
|
704 |
throw new AssertionError("unexpected type: " + t); |
|
705 |
} |
|
706 |
return tp.setType(t); |
|
707 |
} |
|
708 |
||
709 |
/** Create a list of trees representing given list of types. |
|
710 |
*/ |
|
711 |
public List<JCExpression> Types(List<Type> ts) { |
|
22163 | 712 |
ListBuffer<JCExpression> lb = new ListBuffer<>(); |
10 | 713 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
8032 | 714 |
lb.append(Type(l.head)); |
715 |
return lb.toList(); |
|
10 | 716 |
} |
717 |
||
718 |
/** Create a variable definition from a variable symbol and an initializer |
|
719 |
* expression. |
|
720 |
*/ |
|
721 |
public JCVariableDecl VarDef(VarSymbol v, JCExpression init) { |
|
722 |
return (JCVariableDecl) |
|
723 |
new JCVariableDecl( |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14725
diff
changeset
|
724 |
Modifiers(v.flags(), Annotations(v.getRawAttributes())), |
10 | 725 |
v.name, |
726 |
Type(v.type), |
|
727 |
init, |
|
728 |
v).setPos(pos).setType(v.type); |
|
729 |
} |
|
730 |
||
731 |
/** Create annotation trees from annotations. |
|
732 |
*/ |
|
733 |
public List<JCAnnotation> Annotations(List<Attribute.Compound> attributes) { |
|
734 |
if (attributes == null) return List.nil(); |
|
22163 | 735 |
ListBuffer<JCAnnotation> result = new ListBuffer<>(); |
10 | 736 |
for (List<Attribute.Compound> i = attributes; i.nonEmpty(); i=i.tail) { |
737 |
Attribute a = i.head; |
|
738 |
result.append(Annotation(a)); |
|
739 |
} |
|
740 |
return result.toList(); |
|
741 |
} |
|
742 |
||
743 |
public JCLiteral Literal(Object value) { |
|
744 |
JCLiteral result = null; |
|
745 |
if (value instanceof String) { |
|
746 |
result = Literal(CLASS, value). |
|
747 |
setType(syms.stringType.constType(value)); |
|
748 |
} else if (value instanceof Integer) { |
|
749 |
result = Literal(INT, value). |
|
750 |
setType(syms.intType.constType(value)); |
|
751 |
} else if (value instanceof Long) { |
|
752 |
result = Literal(LONG, value). |
|
753 |
setType(syms.longType.constType(value)); |
|
754 |
} else if (value instanceof Byte) { |
|
755 |
result = Literal(BYTE, value). |
|
756 |
setType(syms.byteType.constType(value)); |
|
757 |
} else if (value instanceof Character) { |
|
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
7074
diff
changeset
|
758 |
int v = (int) (((Character) value).toString().charAt(0)); |
22154
3c8d86bf756b
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
jlahoda
parents:
20244
diff
changeset
|
759 |
result = Literal(CHAR, v). |
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
7074
diff
changeset
|
760 |
setType(syms.charType.constType(v)); |
10 | 761 |
} else if (value instanceof Double) { |
762 |
result = Literal(DOUBLE, value). |
|
763 |
setType(syms.doubleType.constType(value)); |
|
764 |
} else if (value instanceof Float) { |
|
765 |
result = Literal(FLOAT, value). |
|
766 |
setType(syms.floatType.constType(value)); |
|
767 |
} else if (value instanceof Short) { |
|
768 |
result = Literal(SHORT, value). |
|
769 |
setType(syms.shortType.constType(value)); |
|
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
7074
diff
changeset
|
770 |
} else if (value instanceof Boolean) { |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
7074
diff
changeset
|
771 |
int v = ((Boolean) value) ? 1 : 0; |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
7074
diff
changeset
|
772 |
result = Literal(BOOLEAN, v). |
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
7074
diff
changeset
|
773 |
setType(syms.booleanType.constType(v)); |
10 | 774 |
} else { |
775 |
throw new AssertionError(value); |
|
776 |
} |
|
777 |
return result; |
|
778 |
} |
|
779 |
||
780 |
class AnnotationBuilder implements Attribute.Visitor { |
|
781 |
JCExpression result = null; |
|
782 |
public void visitConstant(Attribute.Constant v) { |
|
19251
c3b7abd43bc0
8020997: TreeMaker.AnnotationBuilder creates broken element literals with repeating annotations
vromero
parents:
17807
diff
changeset
|
783 |
result = Literal(v.type.getTag(), v.value); |
10 | 784 |
} |
785 |
public void visitClass(Attribute.Class clazz) { |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
11142
diff
changeset
|
786 |
result = ClassLiteral(clazz.classType).setType(syms.classType); |
10 | 787 |
} |
788 |
public void visitEnum(Attribute.Enum e) { |
|
789 |
result = QualIdent(e.value); |
|
790 |
} |
|
791 |
public void visitError(Attribute.Error e) { |
|
792 |
result = Erroneous(); |
|
793 |
} |
|
794 |
public void visitCompound(Attribute.Compound compound) { |
|
15385 | 795 |
if (compound instanceof Attribute.TypeCompound) { |
796 |
result = visitTypeCompoundInternal((Attribute.TypeCompound) compound); |
|
797 |
} else { |
|
798 |
result = visitCompoundInternal(compound); |
|
799 |
} |
|
10 | 800 |
} |
801 |
public JCAnnotation visitCompoundInternal(Attribute.Compound compound) { |
|
22163 | 802 |
ListBuffer<JCExpression> args = new ListBuffer<>(); |
10 | 803 |
for (List<Pair<Symbol.MethodSymbol,Attribute>> values = compound.values; values.nonEmpty(); values=values.tail) { |
804 |
Pair<MethodSymbol,Attribute> pair = values.head; |
|
805 |
JCExpression valueTree = translate(pair.snd); |
|
806 |
args.append(Assign(Ident(pair.fst), valueTree).setType(valueTree.type)); |
|
807 |
} |
|
808 |
return Annotation(Type(compound.type), args.toList()); |
|
809 |
} |
|
15385 | 810 |
public JCAnnotation visitTypeCompoundInternal(Attribute.TypeCompound compound) { |
22163 | 811 |
ListBuffer<JCExpression> args = new ListBuffer<>(); |
15385 | 812 |
for (List<Pair<Symbol.MethodSymbol,Attribute>> values = compound.values; values.nonEmpty(); values=values.tail) { |
813 |
Pair<MethodSymbol,Attribute> pair = values.head; |
|
814 |
JCExpression valueTree = translate(pair.snd); |
|
815 |
args.append(Assign(Ident(pair.fst), valueTree).setType(valueTree.type)); |
|
816 |
} |
|
817 |
return TypeAnnotation(Type(compound.type), args.toList()); |
|
818 |
} |
|
10 | 819 |
public void visitArray(Attribute.Array array) { |
22163 | 820 |
ListBuffer<JCExpression> elems = new ListBuffer<>(); |
10 | 821 |
for (int i = 0; i < array.values.length; i++) |
822 |
elems.append(translate(array.values[i])); |
|
823 |
result = NewArray(null, List.<JCExpression>nil(), elems.toList()).setType(array.type); |
|
824 |
} |
|
825 |
JCExpression translate(Attribute a) { |
|
826 |
a.accept(this); |
|
827 |
return result; |
|
828 |
} |
|
829 |
JCAnnotation translate(Attribute.Compound a) { |
|
830 |
return visitCompoundInternal(a); |
|
831 |
} |
|
15385 | 832 |
JCAnnotation translate(Attribute.TypeCompound a) { |
833 |
return visitTypeCompoundInternal(a); |
|
834 |
} |
|
10 | 835 |
} |
15385 | 836 |
|
10 | 837 |
AnnotationBuilder annotationBuilder = new AnnotationBuilder(); |
838 |
||
839 |
/** Create an annotation tree from an attribute. |
|
840 |
*/ |
|
841 |
public JCAnnotation Annotation(Attribute a) { |
|
842 |
return annotationBuilder.translate((Attribute.Compound)a); |
|
843 |
} |
|
844 |
||
15385 | 845 |
public JCAnnotation TypeAnnotation(Attribute a) { |
846 |
return annotationBuilder.translate((Attribute.TypeCompound) a); |
|
847 |
} |
|
848 |
||
10 | 849 |
/** Create a method definition from a method symbol and a method body. |
850 |
*/ |
|
851 |
public JCMethodDecl MethodDef(MethodSymbol m, JCBlock body) { |
|
852 |
return MethodDef(m, m.type, body); |
|
853 |
} |
|
854 |
||
855 |
/** Create a method definition from a method symbol, method type |
|
856 |
* and a method body. |
|
857 |
*/ |
|
858 |
public JCMethodDecl MethodDef(MethodSymbol m, Type mtype, JCBlock body) { |
|
859 |
return (JCMethodDecl) |
|
860 |
new JCMethodDecl( |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14725
diff
changeset
|
861 |
Modifiers(m.flags(), Annotations(m.getRawAttributes())), |
10 | 862 |
m.name, |
863 |
Type(mtype.getReturnType()), |
|
864 |
TypeParams(mtype.getTypeArguments()), |
|
15385 | 865 |
null, // receiver type |
10 | 866 |
Params(mtype.getParameterTypes(), m), |
867 |
Types(mtype.getThrownTypes()), |
|
868 |
body, |
|
869 |
null, |
|
870 |
m).setPos(pos).setType(mtype); |
|
871 |
} |
|
872 |
||
873 |
/** Create a type parameter tree from its name and type. |
|
874 |
*/ |
|
875 |
public JCTypeParameter TypeParam(Name name, TypeVar tvar) { |
|
876 |
return (JCTypeParameter) |
|
877 |
TypeParameter(name, Types(types.getBounds(tvar))).setPos(pos).setType(tvar); |
|
878 |
} |
|
879 |
||
880 |
/** Create a list of type parameter trees from a list of type variables. |
|
881 |
*/ |
|
882 |
public List<JCTypeParameter> TypeParams(List<Type> typarams) { |
|
22163 | 883 |
ListBuffer<JCTypeParameter> tparams = new ListBuffer<>(); |
10 | 884 |
for (List<Type> l = typarams; l.nonEmpty(); l = l.tail) |
885 |
tparams.append(TypeParam(l.head.tsym.name, (TypeVar)l.head)); |
|
886 |
return tparams.toList(); |
|
887 |
} |
|
888 |
||
889 |
/** Create a value parameter tree from its name, type, and owner. |
|
890 |
*/ |
|
891 |
public JCVariableDecl Param(Name name, Type argtype, Symbol owner) { |
|
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19251
diff
changeset
|
892 |
return VarDef(new VarSymbol(PARAMETER, name, argtype, owner), null); |
10 | 893 |
} |
894 |
||
895 |
/** Create a a list of value parameter trees x0, ..., xn from a list of |
|
896 |
* their types and an their owner. |
|
897 |
*/ |
|
898 |
public List<JCVariableDecl> Params(List<Type> argtypes, Symbol owner) { |
|
22163 | 899 |
ListBuffer<JCVariableDecl> params = new ListBuffer<>(); |
10 | 900 |
MethodSymbol mth = (owner.kind == MTH) ? ((MethodSymbol)owner) : null; |
901 |
if (mth != null && mth.params != null && argtypes.length() == mth.params.length()) { |
|
902 |
for (VarSymbol param : ((MethodSymbol)owner).params) |
|
903 |
params.append(VarDef(param, null)); |
|
904 |
} else { |
|
905 |
int i = 0; |
|
906 |
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail) |
|
907 |
params.append(Param(paramName(i++), l.head, owner)); |
|
908 |
} |
|
909 |
return params.toList(); |
|
910 |
} |
|
911 |
||
912 |
/** Wrap a method invocation in an expression statement or return statement, |
|
913 |
* depending on whether the method invocation expression's type is void. |
|
914 |
*/ |
|
915 |
public JCStatement Call(JCExpression apply) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
13845
diff
changeset
|
916 |
return apply.type.hasTag(VOID) ? Exec(apply) : Return(apply); |
10 | 917 |
} |
918 |
||
919 |
/** Construct an assignment from a variable symbol and a right hand side. |
|
920 |
*/ |
|
921 |
public JCStatement Assignment(Symbol v, JCExpression rhs) { |
|
922 |
return Exec(Assign(Ident(v), rhs).setType(v.type)); |
|
923 |
} |
|
924 |
||
925 |
/** Construct an index expression from a variable and an expression. |
|
926 |
*/ |
|
927 |
public JCArrayAccess Indexed(Symbol v, JCExpression index) { |
|
928 |
JCArrayAccess tree = new JCArrayAccess(QualIdent(v), index); |
|
929 |
tree.type = ((ArrayType)v.type).elemtype; |
|
930 |
return tree; |
|
931 |
} |
|
932 |
||
933 |
/** Make an attributed type cast expression. |
|
934 |
*/ |
|
935 |
public JCTypeCast TypeCast(Type type, JCExpression expr) { |
|
936 |
return (JCTypeCast)TypeCast(Type(type), expr).setType(type); |
|
937 |
} |
|
938 |
||
939 |
/* *************************************************************************** |
|
940 |
* Helper methods. |
|
941 |
****************************************************************************/ |
|
942 |
||
943 |
/** Can given symbol be referred to in unqualified form? |
|
944 |
*/ |
|
945 |
boolean isUnqualifiable(Symbol sym) { |
|
946 |
if (sym.name == names.empty || |
|
947 |
sym.owner == null || |
|
20244 | 948 |
sym.owner == syms.rootPackage || |
10 | 949 |
sym.owner.kind == MTH || sym.owner.kind == VAR) { |
950 |
return true; |
|
951 |
} else if (sym.kind == TYP && toplevel != null) { |
|
952 |
Scope.Entry e; |
|
953 |
e = toplevel.namedImportScope.lookup(sym.name); |
|
954 |
if (e.scope != null) { |
|
955 |
return |
|
956 |
e.sym == sym && |
|
957 |
e.next().scope == null; |
|
958 |
} |
|
959 |
e = toplevel.packge.members().lookup(sym.name); |
|
960 |
if (e.scope != null) { |
|
961 |
return |
|
962 |
e.sym == sym && |
|
963 |
e.next().scope == null; |
|
964 |
} |
|
965 |
e = toplevel.starImportScope.lookup(sym.name); |
|
966 |
if (e.scope != null) { |
|
967 |
return |
|
968 |
e.sym == sym && |
|
969 |
e.next().scope == null; |
|
970 |
} |
|
971 |
} |
|
972 |
return false; |
|
973 |
} |
|
974 |
||
975 |
/** The name of synthetic parameter number `i'. |
|
976 |
*/ |
|
977 |
public Name paramName(int i) { return names.fromString("x" + i); } |
|
978 |
||
979 |
/** The name of synthetic type parameter number `i'. |
|
980 |
*/ |
|
981 |
public Name typaramName(int i) { return names.fromString("A" + i); } |
|
982 |
} |