src/share/classes/com/sun/tools/javac/tree/TreeMaker.java

Thu, 24 May 2018 16:48:51 +0800

author
aoqi
date
Thu, 24 May 2018 16:48:51 +0800
changeset 3295
859dc787b52b
parent 3172
921a7d6ab90d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Merge

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

mercurial