src/share/classes/com/sun/tools/javac/comp/MemberEnter.java

Mon, 04 Feb 2013 18:08:53 -0500

author
dholmes
date
Mon, 04 Feb 2013 18:08:53 -0500
changeset 1570
f91144b7da75
parent 1521
71f35e4b93a5
child 1565
d04960f05593
permissions
-rw-r--r--

Merge

duke@1 1 /*
jjg@1521 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.comp;
duke@1 27
jjg@1521 28 import java.util.HashMap;
jjg@1521 29 import java.util.HashSet;
jjg@1521 30 import java.util.LinkedHashMap;
jjg@1521 31 import java.util.Map;
duke@1 32 import java.util.Set;
jjg@1521 33
jjg@1521 34 import javax.lang.model.type.TypeKind;
duke@1 35 import javax.tools.JavaFileObject;
duke@1 36
duke@1 37 import com.sun.tools.javac.code.*;
duke@1 38 import com.sun.tools.javac.jvm.*;
duke@1 39 import com.sun.tools.javac.tree.*;
duke@1 40 import com.sun.tools.javac.util.*;
duke@1 41
duke@1 42 import com.sun.tools.javac.code.Type.*;
duke@1 43 import com.sun.tools.javac.code.Symbol.*;
duke@1 44 import com.sun.tools.javac.tree.JCTree.*;
duke@1 45
duke@1 46 import static com.sun.tools.javac.code.Flags.*;
jjg@1127 47 import static com.sun.tools.javac.code.Flags.ANNOTATION;
duke@1 48 import static com.sun.tools.javac.code.Kinds.*;
jjg@1374 49 import static com.sun.tools.javac.code.TypeTag.CLASS;
jjg@1374 50 import static com.sun.tools.javac.code.TypeTag.ERROR;
jjg@1374 51 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
jjg@1127 52 import static com.sun.tools.javac.tree.JCTree.Tag.*;
jjh@1188 53 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
duke@1 54 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
duke@1 55
duke@1 56 /** This is the second phase of Enter, in which classes are completed
duke@1 57 * by entering their members into the class scope using
duke@1 58 * MemberEnter.complete(). See Enter for an overview.
duke@1 59 *
jjg@581 60 * <p><b>This is NOT part of any supported API.
jjg@581 61 * If you write code that depends on this, you do so at your own risk.
duke@1 62 * This code and its internal interfaces are subject to change or
duke@1 63 * deletion without notice.</b>
duke@1 64 */
duke@1 65 public class MemberEnter extends JCTree.Visitor implements Completer {
duke@1 66 protected static final Context.Key<MemberEnter> memberEnterKey =
duke@1 67 new Context.Key<MemberEnter>();
duke@1 68
duke@1 69 /** A switch to determine whether we check for package/class conflicts
duke@1 70 */
duke@1 71 final static boolean checkClash = true;
duke@1 72
jjg@113 73 private final Names names;
duke@1 74 private final Enter enter;
duke@1 75 private final Log log;
duke@1 76 private final Check chk;
duke@1 77 private final Attr attr;
duke@1 78 private final Symtab syms;
duke@1 79 private final TreeMaker make;
duke@1 80 private final ClassReader reader;
duke@1 81 private final Todo todo;
duke@1 82 private final Annotate annotate;
duke@1 83 private final Types types;
mcimadamore@89 84 private final JCDiagnostic.Factory diags;
jfranck@1313 85 private final Source source;
duke@1 86 private final Target target;
mcimadamore@852 87 private final DeferredLintHandler deferredLintHandler;
duke@1 88
duke@1 89 public static MemberEnter instance(Context context) {
duke@1 90 MemberEnter instance = context.get(memberEnterKey);
duke@1 91 if (instance == null)
duke@1 92 instance = new MemberEnter(context);
duke@1 93 return instance;
duke@1 94 }
duke@1 95
duke@1 96 protected MemberEnter(Context context) {
duke@1 97 context.put(memberEnterKey, this);
jjg@113 98 names = Names.instance(context);
duke@1 99 enter = Enter.instance(context);
duke@1 100 log = Log.instance(context);
duke@1 101 chk = Check.instance(context);
duke@1 102 attr = Attr.instance(context);
duke@1 103 syms = Symtab.instance(context);
duke@1 104 make = TreeMaker.instance(context);
duke@1 105 reader = ClassReader.instance(context);
duke@1 106 todo = Todo.instance(context);
duke@1 107 annotate = Annotate.instance(context);
duke@1 108 types = Types.instance(context);
mcimadamore@89 109 diags = JCDiagnostic.Factory.instance(context);
jfranck@1313 110 source = Source.instance(context);
duke@1 111 target = Target.instance(context);
mcimadamore@852 112 deferredLintHandler = DeferredLintHandler.instance(context);
duke@1 113 }
duke@1 114
duke@1 115 /** A queue for classes whose members still need to be entered into the
duke@1 116 * symbol table.
duke@1 117 */
duke@1 118 ListBuffer<Env<AttrContext>> halfcompleted = new ListBuffer<Env<AttrContext>>();
duke@1 119
duke@1 120 /** Set to true only when the first of a set of classes is
duke@1 121 * processed from the halfcompleted queue.
duke@1 122 */
duke@1 123 boolean isFirst = true;
duke@1 124
duke@1 125 /** A flag to disable completion from time to time during member
duke@1 126 * enter, as we only need to look up types. This avoids
duke@1 127 * unnecessarily deep recursion.
duke@1 128 */
duke@1 129 boolean completionEnabled = true;
duke@1 130
duke@1 131 /* ---------- Processing import clauses ----------------
duke@1 132 */
duke@1 133
duke@1 134 /** Import all classes of a class or package on demand.
duke@1 135 * @param pos Position to be used for error reporting.
duke@1 136 * @param tsym The class or package the members of which are imported.
jjg@1358 137 * @param env The env in which the imported classes will be entered.
duke@1 138 */
duke@1 139 private void importAll(int pos,
duke@1 140 final TypeSymbol tsym,
duke@1 141 Env<AttrContext> env) {
duke@1 142 // Check that packages imported from exist (JLS ???).
duke@1 143 if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) {
duke@1 144 // If we can't find java.lang, exit immediately.
duke@1 145 if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) {
mcimadamore@89 146 JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang");
duke@1 147 throw new FatalError(msg);
duke@1 148 } else {
jjh@1188 149 log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym);
duke@1 150 }
duke@1 151 }
jjg@767 152 env.toplevel.starImportScope.importAll(tsym.members());
duke@1 153 }
duke@1 154
duke@1 155 /** Import all static members of a class or package on demand.
duke@1 156 * @param pos Position to be used for error reporting.
duke@1 157 * @param tsym The class or package the members of which are imported.
jjg@1358 158 * @param env The env in which the imported classes will be entered.
duke@1 159 */
duke@1 160 private void importStaticAll(int pos,
duke@1 161 final TypeSymbol tsym,
duke@1 162 Env<AttrContext> env) {
duke@1 163 final JavaFileObject sourcefile = env.toplevel.sourcefile;
duke@1 164 final Scope toScope = env.toplevel.starImportScope;
duke@1 165 final PackageSymbol packge = env.toplevel.packge;
duke@1 166 final TypeSymbol origin = tsym;
duke@1 167
duke@1 168 // enter imported types immediately
duke@1 169 new Object() {
duke@1 170 Set<Symbol> processed = new HashSet<Symbol>();
duke@1 171 void importFrom(TypeSymbol tsym) {
duke@1 172 if (tsym == null || !processed.add(tsym))
duke@1 173 return;
duke@1 174
duke@1 175 // also import inherited names
duke@1 176 importFrom(types.supertype(tsym.type).tsym);
duke@1 177 for (Type t : types.interfaces(tsym.type))
duke@1 178 importFrom(t.tsym);
duke@1 179
duke@1 180 final Scope fromScope = tsym.members();
duke@1 181 for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
duke@1 182 Symbol sym = e.sym;
duke@1 183 if (sym.kind == TYP &&
duke@1 184 (sym.flags() & STATIC) != 0 &&
duke@1 185 staticImportAccessible(sym, packge) &&
duke@1 186 sym.isMemberOf(origin, types) &&
duke@1 187 !toScope.includes(sym))
duke@1 188 toScope.enter(sym, fromScope, origin.members());
duke@1 189 }
duke@1 190 }
duke@1 191 }.importFrom(tsym);
duke@1 192
duke@1 193 // enter non-types before annotations that might use them
duke@1 194 annotate.earlier(new Annotate.Annotator() {
duke@1 195 Set<Symbol> processed = new HashSet<Symbol>();
duke@1 196
duke@1 197 public String toString() {
duke@1 198 return "import static " + tsym + ".*" + " in " + sourcefile;
duke@1 199 }
duke@1 200 void importFrom(TypeSymbol tsym) {
duke@1 201 if (tsym == null || !processed.add(tsym))
duke@1 202 return;
duke@1 203
duke@1 204 // also import inherited names
duke@1 205 importFrom(types.supertype(tsym.type).tsym);
duke@1 206 for (Type t : types.interfaces(tsym.type))
duke@1 207 importFrom(t.tsym);
duke@1 208
duke@1 209 final Scope fromScope = tsym.members();
duke@1 210 for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) {
duke@1 211 Symbol sym = e.sym;
duke@1 212 if (sym.isStatic() && sym.kind != TYP &&
duke@1 213 staticImportAccessible(sym, packge) &&
duke@1 214 !toScope.includes(sym) &&
duke@1 215 sym.isMemberOf(origin, types)) {
duke@1 216 toScope.enter(sym, fromScope, origin.members());
duke@1 217 }
duke@1 218 }
duke@1 219 }
duke@1 220 public void enterAnnotation() {
duke@1 221 importFrom(tsym);
duke@1 222 }
duke@1 223 });
duke@1 224 }
duke@1 225
duke@1 226 // is the sym accessible everywhere in packge?
duke@1 227 boolean staticImportAccessible(Symbol sym, PackageSymbol packge) {
duke@1 228 int flags = (int)(sym.flags() & AccessFlags);
duke@1 229 switch (flags) {
duke@1 230 default:
duke@1 231 case PUBLIC:
duke@1 232 return true;
duke@1 233 case PRIVATE:
duke@1 234 return false;
duke@1 235 case 0:
duke@1 236 case PROTECTED:
duke@1 237 return sym.packge() == packge;
duke@1 238 }
duke@1 239 }
duke@1 240
duke@1 241 /** Import statics types of a given name. Non-types are handled in Attr.
duke@1 242 * @param pos Position to be used for error reporting.
duke@1 243 * @param tsym The class from which the name is imported.
duke@1 244 * @param name The (simple) name being imported.
duke@1 245 * @param env The environment containing the named import
duke@1 246 * scope to add to.
duke@1 247 */
duke@1 248 private void importNamedStatic(final DiagnosticPosition pos,
duke@1 249 final TypeSymbol tsym,
duke@1 250 final Name name,
duke@1 251 final Env<AttrContext> env) {
duke@1 252 if (tsym.kind != TYP) {
jjh@1270 253 log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces");
duke@1 254 return;
duke@1 255 }
duke@1 256
duke@1 257 final Scope toScope = env.toplevel.namedImportScope;
duke@1 258 final PackageSymbol packge = env.toplevel.packge;
duke@1 259 final TypeSymbol origin = tsym;
duke@1 260
duke@1 261 // enter imported types immediately
duke@1 262 new Object() {
duke@1 263 Set<Symbol> processed = new HashSet<Symbol>();
duke@1 264 void importFrom(TypeSymbol tsym) {
duke@1 265 if (tsym == null || !processed.add(tsym))
duke@1 266 return;
duke@1 267
duke@1 268 // also import inherited names
duke@1 269 importFrom(types.supertype(tsym.type).tsym);
duke@1 270 for (Type t : types.interfaces(tsym.type))
duke@1 271 importFrom(t.tsym);
duke@1 272
duke@1 273 for (Scope.Entry e = tsym.members().lookup(name);
duke@1 274 e.scope != null;
duke@1 275 e = e.next()) {
duke@1 276 Symbol sym = e.sym;
duke@1 277 if (sym.isStatic() &&
duke@1 278 sym.kind == TYP &&
duke@1 279 staticImportAccessible(sym, packge) &&
duke@1 280 sym.isMemberOf(origin, types) &&
duke@1 281 chk.checkUniqueStaticImport(pos, sym, toScope))
duke@1 282 toScope.enter(sym, sym.owner.members(), origin.members());
duke@1 283 }
duke@1 284 }
duke@1 285 }.importFrom(tsym);
duke@1 286
duke@1 287 // enter non-types before annotations that might use them
duke@1 288 annotate.earlier(new Annotate.Annotator() {
duke@1 289 Set<Symbol> processed = new HashSet<Symbol>();
duke@1 290 boolean found = false;
duke@1 291
duke@1 292 public String toString() {
duke@1 293 return "import static " + tsym + "." + name;
duke@1 294 }
duke@1 295 void importFrom(TypeSymbol tsym) {
duke@1 296 if (tsym == null || !processed.add(tsym))
duke@1 297 return;
duke@1 298
duke@1 299 // also import inherited names
duke@1 300 importFrom(types.supertype(tsym.type).tsym);
duke@1 301 for (Type t : types.interfaces(tsym.type))
duke@1 302 importFrom(t.tsym);
duke@1 303
duke@1 304 for (Scope.Entry e = tsym.members().lookup(name);
duke@1 305 e.scope != null;
duke@1 306 e = e.next()) {
duke@1 307 Symbol sym = e.sym;
duke@1 308 if (sym.isStatic() &&
duke@1 309 staticImportAccessible(sym, packge) &&
duke@1 310 sym.isMemberOf(origin, types)) {
duke@1 311 found = true;
duke@1 312 if (sym.kind == MTH ||
duke@1 313 sym.kind != TYP && chk.checkUniqueStaticImport(pos, sym, toScope))
duke@1 314 toScope.enter(sym, sym.owner.members(), origin.members());
duke@1 315 }
duke@1 316 }
duke@1 317 }
duke@1 318 public void enterAnnotation() {
duke@1 319 JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
duke@1 320 try {
duke@1 321 importFrom(tsym);
duke@1 322 if (!found) {
duke@1 323 log.error(pos, "cant.resolve.location",
mcimadamore@80 324 KindName.STATIC,
mcimadamore@80 325 name, List.<Type>nil(), List.<Type>nil(),
mcimadamore@89 326 Kinds.typeKindName(tsym.type),
duke@1 327 tsym.type);
duke@1 328 }
duke@1 329 } finally {
duke@1 330 log.useSource(prev);
duke@1 331 }
duke@1 332 }
duke@1 333 });
duke@1 334 }
duke@1 335 /** Import given class.
duke@1 336 * @param pos Position to be used for error reporting.
duke@1 337 * @param tsym The class to be imported.
duke@1 338 * @param env The environment containing the named import
duke@1 339 * scope to add to.
duke@1 340 */
duke@1 341 private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) {
duke@1 342 if (tsym.kind == TYP &&
duke@1 343 chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope))
duke@1 344 env.toplevel.namedImportScope.enter(tsym, tsym.owner.members());
duke@1 345 }
duke@1 346
duke@1 347 /** Construct method type from method signature.
duke@1 348 * @param typarams The method's type parameters.
duke@1 349 * @param params The method's value parameters.
duke@1 350 * @param res The method's result type,
duke@1 351 * null if it is a constructor.
jjg@1521 352 * @param recvparam The method's receiver parameter,
jjg@1521 353 * null if none given; TODO: or already set here?
duke@1 354 * @param thrown The method's thrown exceptions.
duke@1 355 * @param env The method's (local) environment.
duke@1 356 */
duke@1 357 Type signature(List<JCTypeParameter> typarams,
duke@1 358 List<JCVariableDecl> params,
duke@1 359 JCTree res,
jjg@1521 360 JCVariableDecl recvparam,
duke@1 361 List<JCExpression> thrown,
duke@1 362 Env<AttrContext> env) {
duke@1 363
duke@1 364 // Enter and attribute type parameters.
duke@1 365 List<Type> tvars = enter.classEnter(typarams, env);
duke@1 366 attr.attribTypeVariables(typarams, env);
duke@1 367
duke@1 368 // Enter and attribute value parameters.
duke@1 369 ListBuffer<Type> argbuf = new ListBuffer<Type>();
duke@1 370 for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) {
duke@1 371 memberEnter(l.head, env);
duke@1 372 argbuf.append(l.head.vartype.type);
duke@1 373 }
duke@1 374
duke@1 375 // Attribute result type, if one is given.
duke@1 376 Type restype = res == null ? syms.voidType : attr.attribType(res, env);
duke@1 377
jjg@1521 378 // Attribute receiver type, if one is given.
jjg@1521 379 Type recvtype;
jjg@1521 380 if (recvparam!=null) {
jjg@1521 381 memberEnter(recvparam, env);
jjg@1521 382 recvtype = recvparam.vartype.type;
jjg@1521 383 } else {
jjg@1521 384 recvtype = null;
jjg@1521 385 }
jjg@1521 386
duke@1 387 // Attribute thrown exceptions.
duke@1 388 ListBuffer<Type> thrownbuf = new ListBuffer<Type>();
duke@1 389 for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) {
duke@1 390 Type exc = attr.attribType(l.head, env);
jjg@1374 391 if (!exc.hasTag(TYPEVAR))
duke@1 392 exc = chk.checkClassType(l.head.pos(), exc);
duke@1 393 thrownbuf.append(exc);
duke@1 394 }
jjg@1521 395 MethodType mtype = new MethodType(argbuf.toList(),
duke@1 396 restype,
duke@1 397 thrownbuf.toList(),
duke@1 398 syms.methodClass);
jjg@1521 399 mtype.recvtype = recvtype;
jjg@1521 400
duke@1 401 return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype);
duke@1 402 }
duke@1 403
duke@1 404 /* ********************************************************************
duke@1 405 * Visitor methods for member enter
duke@1 406 *********************************************************************/
duke@1 407
duke@1 408 /** Visitor argument: the current environment
duke@1 409 */
duke@1 410 protected Env<AttrContext> env;
duke@1 411
duke@1 412 /** Enter field and method definitions and process import
duke@1 413 * clauses, catching any completion failure exceptions.
duke@1 414 */
duke@1 415 protected void memberEnter(JCTree tree, Env<AttrContext> env) {
duke@1 416 Env<AttrContext> prevEnv = this.env;
duke@1 417 try {
duke@1 418 this.env = env;
duke@1 419 tree.accept(this);
duke@1 420 } catch (CompletionFailure ex) {
duke@1 421 chk.completionError(tree.pos(), ex);
duke@1 422 } finally {
duke@1 423 this.env = prevEnv;
duke@1 424 }
duke@1 425 }
duke@1 426
duke@1 427 /** Enter members from a list of trees.
duke@1 428 */
duke@1 429 void memberEnter(List<? extends JCTree> trees, Env<AttrContext> env) {
duke@1 430 for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
duke@1 431 memberEnter(l.head, env);
duke@1 432 }
duke@1 433
duke@1 434 /** Enter members for a class.
duke@1 435 */
duke@1 436 void finishClass(JCClassDecl tree, Env<AttrContext> env) {
duke@1 437 if ((tree.mods.flags & Flags.ENUM) != 0 &&
duke@1 438 (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
duke@1 439 addEnumMembers(tree, env);
duke@1 440 }
duke@1 441 memberEnter(tree.defs, env);
duke@1 442 }
duke@1 443
duke@1 444 /** Add the implicit members for an enum type
duke@1 445 * to the symbol table.
duke@1 446 */
duke@1 447 private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) {
duke@1 448 JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass));
duke@1 449
duke@1 450 // public static T[] values() { return ???; }
duke@1 451 JCMethodDecl values = make.
duke@1 452 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
duke@1 453 names.values,
duke@1 454 valuesType,
duke@1 455 List.<JCTypeParameter>nil(),
duke@1 456 List.<JCVariableDecl>nil(),
duke@1 457 List.<JCExpression>nil(), // thrown
duke@1 458 null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
duke@1 459 null);
duke@1 460 memberEnter(values, env);
duke@1 461
duke@1 462 // public static T valueOf(String name) { return ???; }
duke@1 463 JCMethodDecl valueOf = make.
duke@1 464 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC),
duke@1 465 names.valueOf,
duke@1 466 make.Type(tree.sym.type),
duke@1 467 List.<JCTypeParameter>nil(),
duke@1 468 List.of(make.VarDef(make.Modifiers(Flags.PARAMETER),
duke@1 469 names.fromString("name"),
duke@1 470 make.Type(syms.stringType), null)),
duke@1 471 List.<JCExpression>nil(), // thrown
duke@1 472 null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))),
duke@1 473 null);
duke@1 474 memberEnter(valueOf, env);
duke@1 475
duke@1 476 // the remaining members are for bootstrapping only
duke@1 477 if (!target.compilerBootstrap(tree.sym)) return;
duke@1 478
duke@1 479 // public final int ordinal() { return ???; }
duke@1 480 JCMethodDecl ordinal = make.at(tree.pos).
duke@1 481 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
duke@1 482 names.ordinal,
duke@1 483 make.Type(syms.intType),
duke@1 484 List.<JCTypeParameter>nil(),
duke@1 485 List.<JCVariableDecl>nil(),
duke@1 486 List.<JCExpression>nil(),
duke@1 487 null,
duke@1 488 null);
duke@1 489 memberEnter(ordinal, env);
duke@1 490
duke@1 491 // public final String name() { return ???; }
duke@1 492 JCMethodDecl name = make.
duke@1 493 MethodDef(make.Modifiers(Flags.PUBLIC|Flags.FINAL),
duke@1 494 names._name,
duke@1 495 make.Type(syms.stringType),
duke@1 496 List.<JCTypeParameter>nil(),
duke@1 497 List.<JCVariableDecl>nil(),
duke@1 498 List.<JCExpression>nil(),
duke@1 499 null,
duke@1 500 null);
duke@1 501 memberEnter(name, env);
duke@1 502
duke@1 503 // public int compareTo(E other) { return ???; }
duke@1 504 MethodSymbol compareTo = new
duke@1 505 MethodSymbol(Flags.PUBLIC,
duke@1 506 names.compareTo,
duke@1 507 new MethodType(List.of(tree.sym.type),
duke@1 508 syms.intType,
duke@1 509 List.<Type>nil(),
duke@1 510 syms.methodClass),
duke@1 511 tree.sym);
duke@1 512 memberEnter(make.MethodDef(compareTo, null), env);
duke@1 513 }
duke@1 514
duke@1 515 public void visitTopLevel(JCCompilationUnit tree) {
duke@1 516 if (tree.starImportScope.elems != null) {
duke@1 517 // we must have already processed this toplevel
duke@1 518 return;
duke@1 519 }
duke@1 520
duke@1 521 // check that no class exists with same fully qualified name as
duke@1 522 // toplevel package
duke@1 523 if (checkClash && tree.pid != null) {
duke@1 524 Symbol p = tree.packge;
duke@1 525 while (p.owner != syms.rootPackage) {
duke@1 526 p.owner.complete(); // enter all class members of p
duke@1 527 if (syms.classes.get(p.getQualifiedName()) != null) {
duke@1 528 log.error(tree.pos,
duke@1 529 "pkg.clashes.with.class.of.same.name",
duke@1 530 p);
duke@1 531 }
duke@1 532 p = p.owner;
duke@1 533 }
duke@1 534 }
duke@1 535
duke@1 536 // process package annotations
duke@1 537 annotateLater(tree.packageAnnotations, env, tree.packge);
duke@1 538
duke@1 539 // Import-on-demand java.lang.
duke@1 540 importAll(tree.pos, reader.enterPackage(names.java_lang), env);
duke@1 541
duke@1 542 // Process all import clauses.
duke@1 543 memberEnter(tree.defs, env);
duke@1 544 }
duke@1 545
duke@1 546 // process the non-static imports and the static imports of types.
duke@1 547 public void visitImport(JCImport tree) {
mcimadamore@1220 548 JCFieldAccess imp = (JCFieldAccess)tree.qualid;
duke@1 549 Name name = TreeInfo.name(imp);
duke@1 550
duke@1 551 // Create a local environment pointing to this tree to disable
duke@1 552 // effects of other imports in Resolve.findGlobalType
duke@1 553 Env<AttrContext> localEnv = env.dup(tree);
duke@1 554
mcimadamore@1220 555 TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym;
duke@1 556 if (name == names.asterisk) {
duke@1 557 // Import on demand.
mcimadamore@1220 558 chk.checkCanonical(imp.selected);
duke@1 559 if (tree.staticImport)
duke@1 560 importStaticAll(tree.pos, p, env);
duke@1 561 else
duke@1 562 importAll(tree.pos, p, env);
duke@1 563 } else {
duke@1 564 // Named type import.
duke@1 565 if (tree.staticImport) {
duke@1 566 importNamedStatic(tree.pos(), p, name, localEnv);
mcimadamore@1220 567 chk.checkCanonical(imp.selected);
duke@1 568 } else {
duke@1 569 TypeSymbol c = attribImportType(imp, localEnv).tsym;
duke@1 570 chk.checkCanonical(imp);
duke@1 571 importNamed(tree.pos(), c, env);
duke@1 572 }
duke@1 573 }
duke@1 574 }
duke@1 575
duke@1 576 public void visitMethodDef(JCMethodDecl tree) {
duke@1 577 Scope enclScope = enter.enterScope(env);
duke@1 578 MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner);
duke@1 579 m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree);
duke@1 580 tree.sym = m;
mcimadamore@1393 581
mcimadamore@1393 582 //if this is a default method, add the DEFAULT flag to the enclosing interface
mcimadamore@1393 583 if ((tree.mods.flags & DEFAULT) != 0) {
mcimadamore@1393 584 m.enclClass().flags_field |= DEFAULT;
mcimadamore@1393 585 }
mcimadamore@1393 586
duke@1 587 Env<AttrContext> localEnv = methodEnv(tree, env);
duke@1 588
mcimadamore@852 589 DeferredLintHandler prevLintHandler =
mcimadamore@852 590 chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
mcimadamore@852 591 try {
mcimadamore@852 592 // Compute the method type
mcimadamore@852 593 m.type = signature(tree.typarams, tree.params,
jjg@1521 594 tree.restype, tree.recvparam,
jjg@1521 595 tree.thrown,
mcimadamore@852 596 localEnv);
mcimadamore@852 597 } finally {
mcimadamore@852 598 chk.setDeferredLintHandler(prevLintHandler);
mcimadamore@852 599 }
duke@1 600
duke@1 601 // Set m.params
duke@1 602 ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
duke@1 603 JCVariableDecl lastParam = null;
duke@1 604 for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
duke@1 605 JCVariableDecl param = lastParam = l.head;
jjg@816 606 params.append(Assert.checkNonNull(param.sym));
duke@1 607 }
duke@1 608 m.params = params.toList();
duke@1 609
duke@1 610 // mark the method varargs, if necessary
duke@1 611 if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
duke@1 612 m.flags_field |= Flags.VARARGS;
duke@1 613
duke@1 614 localEnv.info.scope.leave();
duke@1 615 if (chk.checkUnique(tree.pos(), m, enclScope)) {
duke@1 616 enclScope.enter(m);
duke@1 617 }
duke@1 618 annotateLater(tree.mods.annotations, localEnv, m);
jjg@1521 619 // Visit the signature of the method. Note that
jjg@1521 620 // TypeAnnotate doesn't descend into the body.
jjg@1521 621 typeAnnotate(tree, localEnv, m);
jjg@1521 622
duke@1 623 if (tree.defaultValue != null)
duke@1 624 annotateDefaultValueLater(tree.defaultValue, localEnv, m);
duke@1 625 }
duke@1 626
duke@1 627 /** Create a fresh environment for method bodies.
duke@1 628 * @param tree The method definition.
duke@1 629 * @param env The environment current outside of the method definition.
duke@1 630 */
duke@1 631 Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
duke@1 632 Env<AttrContext> localEnv =
duke@1 633 env.dup(tree, env.info.dup(env.info.scope.dupUnshared()));
duke@1 634 localEnv.enclMethod = tree;
duke@1 635 localEnv.info.scope.owner = tree.sym;
mcimadamore@1347 636 if (tree.sym.type != null) {
mcimadamore@1347 637 //when this is called in the enter stage, there's no type to be set
mcimadamore@1347 638 localEnv.info.returnResult = attr.new ResultInfo(VAL, tree.sym.type.getReturnType());
mcimadamore@1347 639 }
duke@1 640 if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++;
duke@1 641 return localEnv;
duke@1 642 }
duke@1 643
duke@1 644 public void visitVarDef(JCVariableDecl tree) {
duke@1 645 Env<AttrContext> localEnv = env;
duke@1 646 if ((tree.mods.flags & STATIC) != 0 ||
duke@1 647 (env.info.scope.owner.flags() & INTERFACE) != 0) {
duke@1 648 localEnv = env.dup(tree, env.info.dup());
duke@1 649 localEnv.info.staticLevel++;
duke@1 650 }
mcimadamore@852 651 DeferredLintHandler prevLintHandler =
mcimadamore@852 652 chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
mcimadamore@852 653 try {
mcimadamore@1269 654 if (TreeInfo.isEnumInit(tree)) {
mcimadamore@1269 655 attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
mcimadamore@1269 656 } else {
mcimadamore@1269 657 attr.attribType(tree.vartype, localEnv);
mcimadamore@1269 658 }
mcimadamore@852 659 } finally {
mcimadamore@852 660 chk.setDeferredLintHandler(prevLintHandler);
mcimadamore@852 661 }
mcimadamore@852 662
mcimadamore@795 663 if ((tree.mods.flags & VARARGS) != 0) {
mcimadamore@795 664 //if we are entering a varargs parameter, we need to replace its type
mcimadamore@795 665 //(a plain array type) with the more precise VarargsType --- we need
mcimadamore@795 666 //to do it this way because varargs is represented in the tree as a modifier
mcimadamore@795 667 //on the parameter declaration, and not as a distinct type of array node.
jjg@1521 668 ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType();
mcimadamore@795 669 tree.vartype.type = atype.makeVarargs();
mcimadamore@795 670 }
duke@1 671 Scope enclScope = enter.enterScope(env);
duke@1 672 VarSymbol v =
duke@1 673 new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
duke@1 674 v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
duke@1 675 tree.sym = v;
duke@1 676 if (tree.init != null) {
duke@1 677 v.flags_field |= HASINIT;
mcimadamore@1348 678 if ((v.flags_field & FINAL) != 0 &&
mcimadamore@1348 679 !tree.init.hasTag(NEWCLASS) &&
mcimadamore@1348 680 !tree.init.hasTag(LAMBDA)) {
mcimadamore@94 681 Env<AttrContext> initEnv = getInitEnv(tree, env);
mcimadamore@94 682 initEnv.info.enclVar = v;
jjg@841 683 v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init);
mcimadamore@94 684 }
duke@1 685 }
duke@1 686 if (chk.checkUnique(tree.pos(), v, enclScope)) {
duke@1 687 chk.checkTransparentVar(tree.pos(), v, enclScope);
duke@1 688 enclScope.enter(v);
duke@1 689 }
duke@1 690 annotateLater(tree.mods.annotations, localEnv, v);
jjg@1521 691 typeAnnotate(tree.vartype, env, tree.sym);
jjg@1521 692 annotate.flush();
duke@1 693 v.pos = tree.pos;
duke@1 694 }
duke@1 695
duke@1 696 /** Create a fresh environment for a variable's initializer.
duke@1 697 * If the variable is a field, the owner of the environment's scope
duke@1 698 * is be the variable itself, otherwise the owner is the method
duke@1 699 * enclosing the variable definition.
duke@1 700 *
duke@1 701 * @param tree The variable definition.
duke@1 702 * @param env The environment current outside of the variable definition.
duke@1 703 */
duke@1 704 Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) {
duke@1 705 Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup()));
duke@1 706 if (tree.sym.owner.kind == TYP) {
mcimadamore@1348 707 localEnv.info.scope = env.info.scope.dupUnshared();
duke@1 708 localEnv.info.scope.owner = tree.sym;
duke@1 709 }
duke@1 710 if ((tree.mods.flags & STATIC) != 0 ||
mcimadamore@1393 711 ((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null))
duke@1 712 localEnv.info.staticLevel++;
duke@1 713 return localEnv;
duke@1 714 }
duke@1 715
duke@1 716 /** Default member enter visitor method: do nothing
duke@1 717 */
duke@1 718 public void visitTree(JCTree tree) {
duke@1 719 }
duke@1 720
duke@1 721 public void visitErroneous(JCErroneous tree) {
jjg@711 722 if (tree.errs != null)
jjg@711 723 memberEnter(tree.errs, env);
duke@1 724 }
duke@1 725
duke@1 726 public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
duke@1 727 Env<AttrContext> mEnv = methodEnv(tree, env);
jfranck@1313 728 mEnv.info.lint = mEnv.info.lint.augment(tree.sym.annotations, tree.sym.flags());
duke@1 729 for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail)
duke@1 730 mEnv.info.scope.enterIfAbsent(l.head.type.tsym);
duke@1 731 for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail)
duke@1 732 mEnv.info.scope.enterIfAbsent(l.head.sym);
duke@1 733 return mEnv;
duke@1 734 }
duke@1 735
duke@1 736 public Env<AttrContext> getInitEnv(JCVariableDecl tree, Env<AttrContext> env) {
duke@1 737 Env<AttrContext> iEnv = initEnv(tree, env);
duke@1 738 return iEnv;
duke@1 739 }
duke@1 740
duke@1 741 /* ********************************************************************
duke@1 742 * Type completion
duke@1 743 *********************************************************************/
duke@1 744
duke@1 745 Type attribImportType(JCTree tree, Env<AttrContext> env) {
jjg@816 746 Assert.check(completionEnabled);
duke@1 747 try {
duke@1 748 // To prevent deep recursion, suppress completion of some
duke@1 749 // types.
duke@1 750 completionEnabled = false;
duke@1 751 return attr.attribType(tree, env);
duke@1 752 } finally {
duke@1 753 completionEnabled = true;
duke@1 754 }
duke@1 755 }
duke@1 756
duke@1 757 /* ********************************************************************
duke@1 758 * Annotation processing
duke@1 759 *********************************************************************/
duke@1 760
duke@1 761 /** Queue annotations for later processing. */
duke@1 762 void annotateLater(final List<JCAnnotation> annotations,
duke@1 763 final Env<AttrContext> localEnv,
duke@1 764 final Symbol s) {
jfranck@1313 765 if (annotations.isEmpty()) {
jfranck@1313 766 return;
jfranck@1313 767 }
jfranck@1313 768 if (s.kind != PCK) {
jfranck@1313 769 s.annotations.reset(); // mark Annotations as incomplete for now
jfranck@1313 770 }
jfranck@1313 771 annotate.normal(new Annotate.Annotator() {
jfranck@1313 772 @Override
duke@1 773 public String toString() {
duke@1 774 return "annotate " + annotations + " onto " + s + " in " + s.owner;
duke@1 775 }
jfranck@1313 776
jfranck@1313 777 @Override
duke@1 778 public void enterAnnotation() {
jfranck@1313 779 Assert.check(s.kind == PCK || s.annotations.pendingCompletion());
duke@1 780 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
duke@1 781 try {
jfranck@1313 782 if (!s.annotations.isEmpty() &&
duke@1 783 annotations.nonEmpty())
duke@1 784 log.error(annotations.head.pos,
duke@1 785 "already.annotated",
mcimadamore@80 786 kindName(s), s);
jjg@1521 787 actualEnterAnnotations(annotations, localEnv, s);
duke@1 788 } finally {
duke@1 789 log.useSource(prev);
duke@1 790 }
duke@1 791 }
duke@1 792 });
duke@1 793 }
duke@1 794
duke@1 795 /**
duke@1 796 * Check if a list of annotations contains a reference to
duke@1 797 * java.lang.Deprecated.
duke@1 798 **/
duke@1 799 private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) {
jfranck@1313 800 for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
duke@1 801 JCAnnotation a = al.head;
duke@1 802 if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty())
duke@1 803 return true;
duke@1 804 }
duke@1 805 return false;
duke@1 806 }
duke@1 807
duke@1 808 /** Enter a set of annotations. */
jjg@1521 809 private void actualEnterAnnotations(List<JCAnnotation> annotations,
duke@1 810 Env<AttrContext> env,
duke@1 811 Symbol s) {
jfranck@1313 812 Map<TypeSymbol, ListBuffer<Attribute.Compound>> annotated =
jfranck@1313 813 new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.Compound>>();
jfranck@1313 814 Map<Attribute.Compound, DiagnosticPosition> pos =
jfranck@1313 815 new HashMap<Attribute.Compound, DiagnosticPosition>();
jfranck@1313 816
jfranck@1313 817 for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
duke@1 818 JCAnnotation a = al.head;
duke@1 819 Attribute.Compound c = annotate.enterAnnotation(a,
duke@1 820 syms.annotationType,
duke@1 821 env);
jfranck@1313 822 if (c == null) {
jfranck@1313 823 continue;
jfranck@1313 824 }
jfranck@1313 825
jfranck@1313 826 if (annotated.containsKey(a.type.tsym)) {
jfranck@1313 827 if (source.allowRepeatedAnnotations()) {
jfranck@1313 828 ListBuffer<Attribute.Compound> l = annotated.get(a.type.tsym);
jfranck@1313 829 l = l.append(c);
jfranck@1313 830 annotated.put(a.type.tsym, l);
jfranck@1313 831 pos.put(c, a.pos());
jfranck@1313 832 } else {
jfranck@1313 833 log.error(a.pos(), "duplicate.annotation");
jfranck@1313 834 }
jfranck@1313 835 } else {
jfranck@1313 836 annotated.put(a.type.tsym, ListBuffer.of(c));
jfranck@1313 837 pos.put(c, a.pos());
jfranck@1313 838 }
jfranck@1313 839
duke@1 840 // Note: @Deprecated has no effect on local variables and parameters
duke@1 841 if (!c.type.isErroneous()
duke@1 842 && s.owner.kind != MTH
jfranck@1313 843 && types.isSameType(c.type, syms.deprecatedType)) {
duke@1 844 s.flags_field |= Flags.DEPRECATED;
jjg@1521 845 }
jfranck@1313 846 }
jfranck@1313 847
jjg@1521 848 s.annotations.setDeclarationAttributesWithCompletion(
jjg@1521 849 annotate.new AnnotateRepeatedContext<Attribute.Compound>(env, annotated, pos, log, false));
duke@1 850 }
duke@1 851
duke@1 852 /** Queue processing of an attribute default value. */
duke@1 853 void annotateDefaultValueLater(final JCExpression defaultValue,
duke@1 854 final Env<AttrContext> localEnv,
duke@1 855 final MethodSymbol m) {
jfranck@1313 856 annotate.normal(new Annotate.Annotator() {
jfranck@1313 857 @Override
duke@1 858 public String toString() {
duke@1 859 return "annotate " + m.owner + "." +
duke@1 860 m + " default " + defaultValue;
duke@1 861 }
jfranck@1313 862
jfranck@1313 863 @Override
duke@1 864 public void enterAnnotation() {
duke@1 865 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
duke@1 866 try {
duke@1 867 enterDefaultValue(defaultValue, localEnv, m);
duke@1 868 } finally {
duke@1 869 log.useSource(prev);
duke@1 870 }
duke@1 871 }
duke@1 872 });
duke@1 873 }
duke@1 874
duke@1 875 /** Enter a default value for an attribute method. */
duke@1 876 private void enterDefaultValue(final JCExpression defaultValue,
duke@1 877 final Env<AttrContext> localEnv,
duke@1 878 final MethodSymbol m) {
duke@1 879 m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(),
duke@1 880 defaultValue,
duke@1 881 localEnv);
duke@1 882 }
duke@1 883
duke@1 884 /* ********************************************************************
duke@1 885 * Source completer
duke@1 886 *********************************************************************/
duke@1 887
duke@1 888 /** Complete entering a class.
duke@1 889 * @param sym The symbol of the class to be completed.
duke@1 890 */
duke@1 891 public void complete(Symbol sym) throws CompletionFailure {
duke@1 892 // Suppress some (recursive) MemberEnter invocations
duke@1 893 if (!completionEnabled) {
duke@1 894 // Re-install same completer for next time around and return.
jjg@816 895 Assert.check((sym.flags() & Flags.COMPOUND) == 0);
duke@1 896 sym.completer = this;
duke@1 897 return;
duke@1 898 }
duke@1 899
duke@1 900 ClassSymbol c = (ClassSymbol)sym;
duke@1 901 ClassType ct = (ClassType)c.type;
duke@1 902 Env<AttrContext> env = enter.typeEnvs.get(c);
duke@1 903 JCClassDecl tree = (JCClassDecl)env.tree;
duke@1 904 boolean wasFirst = isFirst;
duke@1 905 isFirst = false;
duke@1 906
duke@1 907 JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
duke@1 908 try {
duke@1 909 // Save class environment for later member enter (2) processing.
duke@1 910 halfcompleted.append(env);
duke@1 911
mcimadamore@92 912 // Mark class as not yet attributed.
mcimadamore@92 913 c.flags_field |= UNATTRIBUTED;
mcimadamore@92 914
duke@1 915 // If this is a toplevel-class, make sure any preceding import
duke@1 916 // clauses have been seen.
duke@1 917 if (c.owner.kind == PCK) {
jjg@1127 918 memberEnter(env.toplevel, env.enclosing(TOPLEVEL));
duke@1 919 todo.append(env);
duke@1 920 }
duke@1 921
duke@1 922 if (c.owner.kind == TYP)
duke@1 923 c.owner.complete();
duke@1 924
duke@1 925 // create an environment for evaluating the base clauses
duke@1 926 Env<AttrContext> baseEnv = baseEnv(tree, env);
duke@1 927
jjg@1521 928 if (tree.extending != null)
jjg@1521 929 typeAnnotate(tree.extending, baseEnv, sym);
jjg@1521 930 for (JCExpression impl : tree.implementing)
jjg@1521 931 typeAnnotate(impl, baseEnv, sym);
jjg@1521 932 annotate.flush();
jjg@1521 933
duke@1 934 // Determine supertype.
duke@1 935 Type supertype =
duke@1 936 (tree.extending != null)
duke@1 937 ? attr.attribBase(tree.extending, baseEnv, true, false, true)
duke@1 938 : ((tree.mods.flags & Flags.ENUM) != 0 && !target.compilerBootstrap(c))
duke@1 939 ? attr.attribBase(enumBase(tree.pos, c), baseEnv,
duke@1 940 true, false, false)
duke@1 941 : (c.fullname == names.java_lang_Object)
duke@1 942 ? Type.noType
duke@1 943 : syms.objectType;
jjg@904 944 ct.supertype_field = modelMissingTypes(supertype, tree.extending, false);
duke@1 945
duke@1 946 // Determine interfaces.
duke@1 947 ListBuffer<Type> interfaces = new ListBuffer<Type>();
jjg@904 948 ListBuffer<Type> all_interfaces = null; // lazy init
duke@1 949 Set<Type> interfaceSet = new HashSet<Type>();
duke@1 950 List<JCExpression> interfaceTrees = tree.implementing;
duke@1 951 if ((tree.mods.flags & Flags.ENUM) != 0 && target.compilerBootstrap(c)) {
duke@1 952 // add interface Comparable<T>
duke@1 953 interfaceTrees =
duke@1 954 interfaceTrees.prepend(make.Type(new ClassType(syms.comparableType.getEnclosingType(),
duke@1 955 List.of(c.type),
duke@1 956 syms.comparableType.tsym)));
duke@1 957 // add interface Serializable
duke@1 958 interfaceTrees =
duke@1 959 interfaceTrees.prepend(make.Type(syms.serializableType));
duke@1 960 }
duke@1 961 for (JCExpression iface : interfaceTrees) {
duke@1 962 Type i = attr.attribBase(iface, baseEnv, false, true, true);
jjg@1374 963 if (i.hasTag(CLASS)) {
duke@1 964 interfaces.append(i);
jjg@904 965 if (all_interfaces != null) all_interfaces.append(i);
duke@1 966 chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet);
jjg@904 967 } else {
jjg@904 968 if (all_interfaces == null)
jjg@904 969 all_interfaces = new ListBuffer<Type>().appendList(interfaces);
jjg@904 970 all_interfaces.append(modelMissingTypes(i, iface, true));
duke@1 971 }
duke@1 972 }
jjg@904 973 if ((c.flags_field & ANNOTATION) != 0) {
duke@1 974 ct.interfaces_field = List.of(syms.annotationType);
jjg@904 975 ct.all_interfaces_field = ct.interfaces_field;
jjg@904 976 } else {
duke@1 977 ct.interfaces_field = interfaces.toList();
jjg@904 978 ct.all_interfaces_field = (all_interfaces == null)
jjg@904 979 ? ct.interfaces_field : all_interfaces.toList();
jjg@904 980 }
duke@1 981
duke@1 982 if (c.fullname == names.java_lang_Object) {
duke@1 983 if (tree.extending != null) {
duke@1 984 chk.checkNonCyclic(tree.extending.pos(),
duke@1 985 supertype);
duke@1 986 ct.supertype_field = Type.noType;
duke@1 987 }
duke@1 988 else if (tree.implementing.nonEmpty()) {
duke@1 989 chk.checkNonCyclic(tree.implementing.head.pos(),
duke@1 990 ct.interfaces_field.head);
duke@1 991 ct.interfaces_field = List.nil();
duke@1 992 }
duke@1 993 }
duke@1 994
duke@1 995 // Annotations.
duke@1 996 // In general, we cannot fully process annotations yet, but we
duke@1 997 // can attribute the annotation types and then check to see if the
duke@1 998 // @Deprecated annotation is present.
duke@1 999 attr.attribAnnotationTypes(tree.mods.annotations, baseEnv);
duke@1 1000 if (hasDeprecatedAnnotation(tree.mods.annotations))
duke@1 1001 c.flags_field |= DEPRECATED;
duke@1 1002 annotateLater(tree.mods.annotations, baseEnv, c);
jjg@1521 1003 // class type parameters use baseEnv but everything uses env
duke@1 1004
mcimadamore@690 1005 chk.checkNonCyclicDecl(tree);
mcimadamore@8 1006
duke@1 1007 attr.attribTypeVariables(tree.typarams, baseEnv);
jjg@1521 1008 // Do this here, where we have the symbol.
jjg@1521 1009 for (JCTypeParameter tp : tree.typarams)
jjg@1521 1010 typeAnnotate(tp, baseEnv, sym);
jjg@1521 1011 annotate.flush();
duke@1 1012
duke@1 1013 // Add default constructor if needed.
duke@1 1014 if ((c.flags() & INTERFACE) == 0 &&
duke@1 1015 !TreeInfo.hasConstructors(tree.defs)) {
duke@1 1016 List<Type> argtypes = List.nil();
duke@1 1017 List<Type> typarams = List.nil();
duke@1 1018 List<Type> thrown = List.nil();
duke@1 1019 long ctorFlags = 0;
duke@1 1020 boolean based = false;
mcimadamore@1341 1021 boolean addConstructor = true;
jjg@113 1022 if (c.name.isEmpty()) {
duke@1 1023 JCNewClass nc = (JCNewClass)env.next.tree;
duke@1 1024 if (nc.constructor != null) {
mcimadamore@1341 1025 addConstructor = nc.constructor.kind != ERR;
duke@1 1026 Type superConstrType = types.memberType(c.type,
duke@1 1027 nc.constructor);
duke@1 1028 argtypes = superConstrType.getParameterTypes();
duke@1 1029 typarams = superConstrType.getTypeArguments();
duke@1 1030 ctorFlags = nc.constructor.flags() & VARARGS;
duke@1 1031 if (nc.encl != null) {
duke@1 1032 argtypes = argtypes.prepend(nc.encl.type);
duke@1 1033 based = true;
duke@1 1034 }
duke@1 1035 thrown = superConstrType.getThrownTypes();
duke@1 1036 }
duke@1 1037 }
mcimadamore@1341 1038 if (addConstructor) {
mcimadamore@1341 1039 JCTree constrDef = DefaultConstructor(make.at(tree.pos), c,
mcimadamore@1341 1040 typarams, argtypes, thrown,
mcimadamore@1341 1041 ctorFlags, based);
mcimadamore@1341 1042 tree.defs = tree.defs.prepend(constrDef);
mcimadamore@1341 1043 }
duke@1 1044 }
duke@1 1045
mcimadamore@1393 1046 // enter symbols for 'this' into current scope.
mcimadamore@1393 1047 VarSymbol thisSym =
mcimadamore@1393 1048 new VarSymbol(FINAL | HASINIT, names._this, c.type, c);
mcimadamore@1393 1049 thisSym.pos = Position.FIRSTPOS;
mcimadamore@1393 1050 env.info.scope.enter(thisSym);
mcimadamore@1393 1051 // if this is a class, enter symbol for 'super' into current scope.
mcimadamore@1393 1052 if ((c.flags_field & INTERFACE) == 0 &&
mcimadamore@1393 1053 ct.supertype_field.hasTag(CLASS)) {
mcimadamore@1393 1054 VarSymbol superSym =
mcimadamore@1393 1055 new VarSymbol(FINAL | HASINIT, names._super,
mcimadamore@1393 1056 ct.supertype_field, c);
mcimadamore@1393 1057 superSym.pos = Position.FIRSTPOS;
mcimadamore@1393 1058 env.info.scope.enter(superSym);
duke@1 1059 }
duke@1 1060
duke@1 1061 // check that no package exists with same fully qualified name,
duke@1 1062 // but admit classes in the unnamed package which have the same
duke@1 1063 // name as a top-level package.
duke@1 1064 if (checkClash &&
duke@1 1065 c.owner.kind == PCK && c.owner != syms.unnamedPackage &&
ohrstrom@1384 1066 reader.packageExists(c.fullname)) {
ohrstrom@1384 1067 log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c);
ohrstrom@1384 1068 }
ohrstrom@1384 1069 if (c.owner.kind == PCK && (c.flags_field & PUBLIC) == 0 &&
ohrstrom@1384 1070 !env.toplevel.sourcefile.isNameCompatible(c.name.toString(),JavaFileObject.Kind.SOURCE)) {
ohrstrom@1384 1071 c.flags_field |= AUXILIARY;
ohrstrom@1384 1072 }
duke@1 1073 } catch (CompletionFailure ex) {
duke@1 1074 chk.completionError(tree.pos(), ex);
duke@1 1075 } finally {
duke@1 1076 log.useSource(prev);
duke@1 1077 }
duke@1 1078
duke@1 1079 // Enter all member fields and methods of a set of half completed
duke@1 1080 // classes in a second phase.
duke@1 1081 if (wasFirst) {
duke@1 1082 try {
duke@1 1083 while (halfcompleted.nonEmpty()) {
duke@1 1084 finish(halfcompleted.next());
duke@1 1085 }
duke@1 1086 } finally {
duke@1 1087 isFirst = true;
duke@1 1088 }
jjg@1521 1089 }
jjg@1521 1090 annotate.afterRepeated(TypeAnnotations.organizeTypeAnnotationsSignatures(syms, names, log, tree));
jjg@1521 1091 }
duke@1 1092
jjg@1521 1093 private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations,
jjg@1521 1094 final Env<AttrContext> env,
jjg@1521 1095 final Symbol s) {
jjg@1521 1096 Map<TypeSymbol, ListBuffer<Attribute.TypeCompound>> annotated =
jjg@1521 1097 new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.TypeCompound>>();
jjg@1521 1098 Map<Attribute.TypeCompound, DiagnosticPosition> pos =
jjg@1521 1099 new HashMap<Attribute.TypeCompound, DiagnosticPosition>();
jjg@1521 1100
jjg@1521 1101 for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
jjg@1521 1102 JCAnnotation a = al.head;
jjg@1521 1103 Attribute.TypeCompound tc = annotate.enterTypeAnnotation(a,
jjg@1521 1104 syms.annotationType,
jjg@1521 1105 env);
jjg@1521 1106 if (tc == null) {
jjg@1521 1107 continue;
jjg@1521 1108 }
jjg@1521 1109
jjg@1521 1110 if (annotated.containsKey(a.type.tsym)) {
jjg@1521 1111 if (source.allowRepeatedAnnotations()) {
jjg@1521 1112 ListBuffer<Attribute.TypeCompound> l = annotated.get(a.type.tsym);
jjg@1521 1113 l = l.append(tc);
jjg@1521 1114 annotated.put(a.type.tsym, l);
jjg@1521 1115 pos.put(tc, a.pos());
jjg@1521 1116 } else {
jjg@1521 1117 log.error(a.pos(), "duplicate.annotation");
jjg@1521 1118 }
jjg@1521 1119 } else {
jjg@1521 1120 annotated.put(a.type.tsym, ListBuffer.of(tc));
jjg@1521 1121 pos.put(tc, a.pos());
jjg@1521 1122 }
jjg@1521 1123 }
jjg@1521 1124
jjg@1521 1125 s.annotations.appendTypeAttributesWithCompletion(
jjg@1521 1126 annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true));
jjg@1521 1127 }
jjg@1521 1128
jjg@1521 1129 public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym) {
jjg@1521 1130 tree.accept(new TypeAnnotate(env, sym));
jjg@1521 1131 }
jjg@1521 1132
jjg@1521 1133 /**
jjg@1521 1134 * We need to use a TreeScanner, because it is not enough to visit the top-level
jjg@1521 1135 * annotations. We also need to visit type arguments, etc.
jjg@1521 1136 */
jjg@1521 1137 private class TypeAnnotate extends TreeScanner {
jjg@1521 1138 private Env<AttrContext> env;
jjg@1521 1139 private Symbol sym;
jjg@1521 1140
jjg@1521 1141 public TypeAnnotate(final Env<AttrContext> env, final Symbol sym) {
jjg@1521 1142 this.env = env;
jjg@1521 1143 this.sym = sym;
jjg@1521 1144 }
jjg@1521 1145
jjg@1521 1146 void annotateTypeLater(final List<JCAnnotation> annotations) {
jjg@1521 1147 if (annotations.isEmpty()) {
jjg@1521 1148 return;
jjg@1521 1149 }
jjg@1521 1150
jjg@1521 1151 annotate.normal(new Annotate.Annotator() {
jjg@1521 1152 @Override
jjg@1521 1153 public String toString() {
jjg@1521 1154 return "type annotate " + annotations + " onto " + sym + " in " + sym.owner;
jjg@1521 1155 }
jjg@1521 1156 @Override
jjg@1521 1157 public void enterAnnotation() {
jjg@1521 1158 JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
jjg@1521 1159 try {
jjg@1521 1160 actualEnterTypeAnnotations(annotations, env, sym);
jjg@1521 1161 } finally {
jjg@1521 1162 log.useSource(prev);
jjg@1521 1163 }
jjg@1521 1164 }
jjg@1521 1165 });
jjg@1521 1166 }
jjg@1521 1167
jjg@1521 1168 @Override
jjg@1521 1169 public void visitAnnotatedType(final JCAnnotatedType tree) {
jjg@1521 1170 annotateTypeLater(tree.annotations);
jjg@1521 1171 super.visitAnnotatedType(tree);
jjg@1521 1172 }
jjg@1521 1173
jjg@1521 1174 @Override
jjg@1521 1175 public void visitTypeParameter(final JCTypeParameter tree) {
jjg@1521 1176 annotateTypeLater(tree.annotations);
jjg@1521 1177 super.visitTypeParameter(tree);
jjg@1521 1178 }
jjg@1521 1179
jjg@1521 1180 @Override
jjg@1521 1181 public void visitNewArray(final JCNewArray tree) {
jjg@1521 1182 annotateTypeLater(tree.annotations);
jjg@1521 1183 for (List<JCAnnotation> dimAnnos : tree.dimAnnotations)
jjg@1521 1184 annotateTypeLater(dimAnnos);
jjg@1521 1185 super.visitNewArray(tree);
jjg@1521 1186 }
jjg@1521 1187
jjg@1521 1188 @Override
jjg@1521 1189 public void visitMethodDef(final JCMethodDecl tree) {
jjg@1521 1190 scan(tree.mods);
jjg@1521 1191 scan(tree.restype);
jjg@1521 1192 scan(tree.typarams);
jjg@1521 1193 scan(tree.recvparam);
jjg@1521 1194 scan(tree.params);
jjg@1521 1195 scan(tree.thrown);
jjg@1521 1196 scan(tree.defaultValue);
jjg@1521 1197 // Do not annotate the body, just the signature.
jjg@1521 1198 // scan(tree.body);
duke@1 1199 }
duke@1 1200 }
duke@1 1201
jjg@1521 1202
duke@1 1203 private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) {
mcimadamore@858 1204 Scope baseScope = new Scope(tree.sym);
mcimadamore@639 1205 //import already entered local classes into base scope
mcimadamore@639 1206 for (Scope.Entry e = env.outer.info.scope.elems ; e != null ; e = e.sibling) {
mcimadamore@639 1207 if (e.sym.isLocal()) {
mcimadamore@639 1208 baseScope.enter(e.sym);
mcimadamore@639 1209 }
mcimadamore@639 1210 }
mcimadamore@639 1211 //import current type-parameters into base scope
duke@1 1212 if (tree.typarams != null)
duke@1 1213 for (List<JCTypeParameter> typarams = tree.typarams;
duke@1 1214 typarams.nonEmpty();
duke@1 1215 typarams = typarams.tail)
mcimadamore@639 1216 baseScope.enter(typarams.head.type.tsym);
duke@1 1217 Env<AttrContext> outer = env.outer; // the base clause can't see members of this class
mcimadamore@639 1218 Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope));
duke@1 1219 localEnv.baseClause = true;
duke@1 1220 localEnv.outer = outer;
duke@1 1221 localEnv.info.isSelfCall = false;
duke@1 1222 return localEnv;
duke@1 1223 }
duke@1 1224
duke@1 1225 /** Enter member fields and methods of a class
duke@1 1226 * @param env the environment current for the class block.
duke@1 1227 */
duke@1 1228 private void finish(Env<AttrContext> env) {
duke@1 1229 JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
duke@1 1230 try {
duke@1 1231 JCClassDecl tree = (JCClassDecl)env.tree;
duke@1 1232 finishClass(tree, env);
duke@1 1233 } finally {
duke@1 1234 log.useSource(prev);
duke@1 1235 }
duke@1 1236 }
duke@1 1237
duke@1 1238 /** Generate a base clause for an enum type.
duke@1 1239 * @param pos The position for trees and diagnostics, if any
duke@1 1240 * @param c The class symbol of the enum
duke@1 1241 */
duke@1 1242 private JCExpression enumBase(int pos, ClassSymbol c) {
duke@1 1243 JCExpression result = make.at(pos).
duke@1 1244 TypeApply(make.QualIdent(syms.enumSym),
duke@1 1245 List.<JCExpression>of(make.Type(c.type)));
duke@1 1246 return result;
duke@1 1247 }
duke@1 1248
jjg@904 1249 Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) {
jjg@1374 1250 if (!t.hasTag(ERROR))
jjg@904 1251 return t;
jjg@904 1252
jjg@904 1253 return new ErrorType(((ErrorType) t).getOriginalType(), t.tsym) {
jjg@904 1254 private Type modelType;
jjg@904 1255
jjg@904 1256 @Override
jjg@904 1257 public Type getModelType() {
jjg@904 1258 if (modelType == null)
jjg@904 1259 modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree);
jjg@904 1260 return modelType;
jjg@904 1261 }
jjg@904 1262 };
jjg@904 1263 }
jjg@904 1264 // where
jjg@904 1265 private class Synthesizer extends JCTree.Visitor {
jjg@904 1266 Type originalType;
jjg@904 1267 boolean interfaceExpected;
jjg@904 1268 List<ClassSymbol> synthesizedSymbols = List.nil();
jjg@904 1269 Type result;
jjg@904 1270
jjg@904 1271 Synthesizer(Type originalType, boolean interfaceExpected) {
jjg@904 1272 this.originalType = originalType;
jjg@904 1273 this.interfaceExpected = interfaceExpected;
jjg@904 1274 }
jjg@904 1275
jjg@904 1276 Type visit(JCTree tree) {
jjg@904 1277 tree.accept(this);
jjg@904 1278 return result;
jjg@904 1279 }
jjg@904 1280
jjg@904 1281 List<Type> visit(List<? extends JCTree> trees) {
jjg@904 1282 ListBuffer<Type> lb = new ListBuffer<Type>();
jjg@904 1283 for (JCTree t: trees)
jjg@904 1284 lb.append(visit(t));
jjg@904 1285 return lb.toList();
jjg@904 1286 }
jjg@904 1287
jjg@904 1288 @Override
jjg@904 1289 public void visitTree(JCTree tree) {
jjg@904 1290 result = syms.errType;
jjg@904 1291 }
jjg@904 1292
jjg@904 1293 @Override
jjg@904 1294 public void visitIdent(JCIdent tree) {
jjg@1374 1295 if (!tree.type.hasTag(ERROR)) {
jjg@904 1296 result = tree.type;
jjg@904 1297 } else {
jjg@904 1298 result = synthesizeClass(tree.name, syms.unnamedPackage).type;
jjg@904 1299 }
jjg@904 1300 }
jjg@904 1301
jjg@904 1302 @Override
jjg@904 1303 public void visitSelect(JCFieldAccess tree) {
jjg@1374 1304 if (!tree.type.hasTag(ERROR)) {
jjg@904 1305 result = tree.type;
jjg@904 1306 } else {
jjg@904 1307 Type selectedType;
jjg@904 1308 boolean prev = interfaceExpected;
jjg@904 1309 try {
jjg@904 1310 interfaceExpected = false;
jjg@904 1311 selectedType = visit(tree.selected);
jjg@904 1312 } finally {
jjg@904 1313 interfaceExpected = prev;
jjg@904 1314 }
jjg@904 1315 ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym);
jjg@904 1316 result = c.type;
jjg@904 1317 }
jjg@904 1318 }
jjg@904 1319
jjg@904 1320 @Override
jjg@904 1321 public void visitTypeApply(JCTypeApply tree) {
jjg@1374 1322 if (!tree.type.hasTag(ERROR)) {
jjg@904 1323 result = tree.type;
jjg@904 1324 } else {
jjg@904 1325 ClassType clazzType = (ClassType) visit(tree.clazz);
jjg@904 1326 if (synthesizedSymbols.contains(clazzType.tsym))
jjg@904 1327 synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size());
jjg@904 1328 final List<Type> actuals = visit(tree.arguments);
jjg@904 1329 result = new ErrorType(tree.type, clazzType.tsym) {
jjg@904 1330 @Override
jjg@904 1331 public List<Type> getTypeArguments() {
jjg@904 1332 return actuals;
jjg@904 1333 }
jjg@904 1334 };
jjg@904 1335 }
jjg@904 1336 }
jjg@904 1337
jjg@904 1338 ClassSymbol synthesizeClass(Name name, Symbol owner) {
jjg@904 1339 int flags = interfaceExpected ? INTERFACE : 0;
jjg@904 1340 ClassSymbol c = new ClassSymbol(flags, name, owner);
jjg@904 1341 c.members_field = new Scope.ErrorScope(c);
jjg@904 1342 c.type = new ErrorType(originalType, c) {
jjg@904 1343 @Override
jjg@904 1344 public List<Type> getTypeArguments() {
jjg@904 1345 return typarams_field;
jjg@904 1346 }
jjg@904 1347 };
jjg@904 1348 synthesizedSymbols = synthesizedSymbols.prepend(c);
jjg@904 1349 return c;
jjg@904 1350 }
jjg@904 1351
jjg@904 1352 void synthesizeTyparams(ClassSymbol sym, int n) {
jjg@904 1353 ClassType ct = (ClassType) sym.type;
jjg@904 1354 Assert.check(ct.typarams_field.isEmpty());
jjg@904 1355 if (n == 1) {
jjg@904 1356 TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType);
jjg@904 1357 ct.typarams_field = ct.typarams_field.prepend(v);
jjg@904 1358 } else {
jjg@904 1359 for (int i = n; i > 0; i--) {
jjg@904 1360 TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType);
jjg@904 1361 ct.typarams_field = ct.typarams_field.prepend(v);
jjg@904 1362 }
jjg@904 1363 }
jjg@904 1364 }
jjg@904 1365 }
jjg@904 1366
jjg@904 1367
duke@1 1368 /* ***************************************************************************
duke@1 1369 * tree building
duke@1 1370 ****************************************************************************/
duke@1 1371
duke@1 1372 /** Generate default constructor for given class. For classes different
duke@1 1373 * from java.lang.Object, this is:
duke@1 1374 *
duke@1 1375 * c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
duke@1 1376 * super(x_0, ..., x_n)
duke@1 1377 * }
duke@1 1378 *
duke@1 1379 * or, if based == true:
duke@1 1380 *
duke@1 1381 * c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
duke@1 1382 * x_0.super(x_1, ..., x_n)
duke@1 1383 * }
duke@1 1384 *
duke@1 1385 * @param make The tree factory.
duke@1 1386 * @param c The class owning the default constructor.
duke@1 1387 * @param argtypes The parameter types of the constructor.
duke@1 1388 * @param thrown The thrown exceptions of the constructor.
duke@1 1389 * @param based Is first parameter a this$n?
duke@1 1390 */
duke@1 1391 JCTree DefaultConstructor(TreeMaker make,
duke@1 1392 ClassSymbol c,
duke@1 1393 List<Type> typarams,
duke@1 1394 List<Type> argtypes,
duke@1 1395 List<Type> thrown,
duke@1 1396 long flags,
duke@1 1397 boolean based) {
duke@1 1398 List<JCVariableDecl> params = make.Params(argtypes, syms.noSymbol);
duke@1 1399 List<JCStatement> stats = List.nil();
duke@1 1400 if (c.type != syms.objectType)
duke@1 1401 stats = stats.prepend(SuperCall(make, typarams, params, based));
duke@1 1402 if ((c.flags() & ENUM) != 0 &&
duke@1 1403 (types.supertype(c.type).tsym == syms.enumSym ||
duke@1 1404 target.compilerBootstrap(c))) {
duke@1 1405 // constructors of true enums are private
duke@1 1406 flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
duke@1 1407 } else
duke@1 1408 flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR;
jjg@113 1409 if (c.name.isEmpty()) flags |= ANONCONSTR;
duke@1 1410 JCTree result = make.MethodDef(
duke@1 1411 make.Modifiers(flags),
duke@1 1412 names.init,
duke@1 1413 null,
duke@1 1414 make.TypeParams(typarams),
duke@1 1415 params,
duke@1 1416 make.Types(thrown),
duke@1 1417 make.Block(0, stats),
duke@1 1418 null);
duke@1 1419 return result;
duke@1 1420 }
duke@1 1421
duke@1 1422 /** Generate call to superclass constructor. This is:
duke@1 1423 *
duke@1 1424 * super(id_0, ..., id_n)
duke@1 1425 *
duke@1 1426 * or, if based == true
duke@1 1427 *
duke@1 1428 * id_0.super(id_1,...,id_n)
duke@1 1429 *
duke@1 1430 * where id_0, ..., id_n are the names of the given parameters.
duke@1 1431 *
duke@1 1432 * @param make The tree factory
duke@1 1433 * @param params The parameters that need to be passed to super
duke@1 1434 * @param typarams The type parameters that need to be passed to super
duke@1 1435 * @param based Is first parameter a this$n?
duke@1 1436 */
duke@1 1437 JCExpressionStatement SuperCall(TreeMaker make,
duke@1 1438 List<Type> typarams,
duke@1 1439 List<JCVariableDecl> params,
duke@1 1440 boolean based) {
duke@1 1441 JCExpression meth;
duke@1 1442 if (based) {
duke@1 1443 meth = make.Select(make.Ident(params.head), names._super);
duke@1 1444 params = params.tail;
duke@1 1445 } else {
duke@1 1446 meth = make.Ident(names._super);
duke@1 1447 }
duke@1 1448 List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
duke@1 1449 return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
duke@1 1450 }
duke@1 1451 }

mercurial