1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,1671 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.javac.comp; 1.30 + 1.31 +import java.util.HashMap; 1.32 +import java.util.HashSet; 1.33 +import java.util.LinkedHashMap; 1.34 +import java.util.Map; 1.35 +import java.util.Set; 1.36 + 1.37 +import javax.tools.JavaFileObject; 1.38 + 1.39 +import com.sun.tools.javac.code.*; 1.40 +import com.sun.tools.javac.jvm.*; 1.41 +import com.sun.tools.javac.tree.*; 1.42 +import com.sun.tools.javac.util.*; 1.43 + 1.44 +import com.sun.tools.javac.code.Type.*; 1.45 +import com.sun.tools.javac.code.Symbol.*; 1.46 +import com.sun.tools.javac.tree.JCTree.*; 1.47 + 1.48 +import static com.sun.tools.javac.code.Flags.*; 1.49 +import static com.sun.tools.javac.code.Flags.ANNOTATION; 1.50 +import static com.sun.tools.javac.code.Kinds.*; 1.51 +import static com.sun.tools.javac.code.TypeTag.CLASS; 1.52 +import static com.sun.tools.javac.code.TypeTag.ERROR; 1.53 +import static com.sun.tools.javac.code.TypeTag.TYPEVAR; 1.54 +import static com.sun.tools.javac.tree.JCTree.Tag.*; 1.55 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; 1.56 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 1.57 + 1.58 +/** This is the second phase of Enter, in which classes are completed 1.59 + * by entering their members into the class scope using 1.60 + * MemberEnter.complete(). See Enter for an overview. 1.61 + * 1.62 + * <p><b>This is NOT part of any supported API. 1.63 + * If you write code that depends on this, you do so at your own risk. 1.64 + * This code and its internal interfaces are subject to change or 1.65 + * deletion without notice.</b> 1.66 + */ 1.67 +public class MemberEnter extends JCTree.Visitor implements Completer { 1.68 + protected static final Context.Key<MemberEnter> memberEnterKey = 1.69 + new Context.Key<MemberEnter>(); 1.70 + 1.71 + /** A switch to determine whether we check for package/class conflicts 1.72 + */ 1.73 + final static boolean checkClash = true; 1.74 + 1.75 + private final Names names; 1.76 + private final Enter enter; 1.77 + private final Log log; 1.78 + private final Check chk; 1.79 + private final Attr attr; 1.80 + private final Symtab syms; 1.81 + private final TreeMaker make; 1.82 + private final ClassReader reader; 1.83 + private final Todo todo; 1.84 + private final Annotate annotate; 1.85 + private final TypeAnnotations typeAnnotations; 1.86 + private final Types types; 1.87 + private final JCDiagnostic.Factory diags; 1.88 + private final Source source; 1.89 + private final Target target; 1.90 + private final DeferredLintHandler deferredLintHandler; 1.91 + private final Lint lint; 1.92 + private final TypeEnvs typeEnvs; 1.93 + 1.94 + public static MemberEnter instance(Context context) { 1.95 + MemberEnter instance = context.get(memberEnterKey); 1.96 + if (instance == null) 1.97 + instance = new MemberEnter(context); 1.98 + return instance; 1.99 + } 1.100 + 1.101 + protected MemberEnter(Context context) { 1.102 + context.put(memberEnterKey, this); 1.103 + names = Names.instance(context); 1.104 + enter = Enter.instance(context); 1.105 + log = Log.instance(context); 1.106 + chk = Check.instance(context); 1.107 + attr = Attr.instance(context); 1.108 + syms = Symtab.instance(context); 1.109 + make = TreeMaker.instance(context); 1.110 + reader = ClassReader.instance(context); 1.111 + todo = Todo.instance(context); 1.112 + annotate = Annotate.instance(context); 1.113 + typeAnnotations = TypeAnnotations.instance(context); 1.114 + types = Types.instance(context); 1.115 + diags = JCDiagnostic.Factory.instance(context); 1.116 + source = Source.instance(context); 1.117 + target = Target.instance(context); 1.118 + deferredLintHandler = DeferredLintHandler.instance(context); 1.119 + lint = Lint.instance(context); 1.120 + typeEnvs = TypeEnvs.instance(context); 1.121 + allowTypeAnnos = source.allowTypeAnnotations(); 1.122 + allowRepeatedAnnos = source.allowRepeatedAnnotations(); 1.123 + } 1.124 + 1.125 + /** Switch: support type annotations. 1.126 + */ 1.127 + boolean allowTypeAnnos; 1.128 + 1.129 + boolean allowRepeatedAnnos; 1.130 + 1.131 + /** A queue for classes whose members still need to be entered into the 1.132 + * symbol table. 1.133 + */ 1.134 + ListBuffer<Env<AttrContext>> halfcompleted = new ListBuffer<Env<AttrContext>>(); 1.135 + 1.136 + /** Set to true only when the first of a set of classes is 1.137 + * processed from the half completed queue. 1.138 + */ 1.139 + boolean isFirst = true; 1.140 + 1.141 + /** A flag to disable completion from time to time during member 1.142 + * enter, as we only need to look up types. This avoids 1.143 + * unnecessarily deep recursion. 1.144 + */ 1.145 + boolean completionEnabled = true; 1.146 + 1.147 + /* ---------- Processing import clauses ---------------- 1.148 + */ 1.149 + 1.150 + /** Import all classes of a class or package on demand. 1.151 + * @param pos Position to be used for error reporting. 1.152 + * @param tsym The class or package the members of which are imported. 1.153 + * @param env The env in which the imported classes will be entered. 1.154 + */ 1.155 + private void importAll(int pos, 1.156 + final TypeSymbol tsym, 1.157 + Env<AttrContext> env) { 1.158 + // Check that packages imported from exist (JLS ???). 1.159 + if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) { 1.160 + // If we can't find java.lang, exit immediately. 1.161 + if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) { 1.162 + JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang"); 1.163 + throw new FatalError(msg); 1.164 + } else { 1.165 + log.error(DiagnosticFlag.RESOLVE_ERROR, pos, "doesnt.exist", tsym); 1.166 + } 1.167 + } 1.168 + env.toplevel.starImportScope.importAll(tsym.members()); 1.169 + } 1.170 + 1.171 + /** Import all static members of a class or package on demand. 1.172 + * @param pos Position to be used for error reporting. 1.173 + * @param tsym The class or package the members of which are imported. 1.174 + * @param env The env in which the imported classes will be entered. 1.175 + */ 1.176 + private void importStaticAll(int pos, 1.177 + final TypeSymbol tsym, 1.178 + Env<AttrContext> env) { 1.179 + final JavaFileObject sourcefile = env.toplevel.sourcefile; 1.180 + final Scope toScope = env.toplevel.starImportScope; 1.181 + final PackageSymbol packge = env.toplevel.packge; 1.182 + final TypeSymbol origin = tsym; 1.183 + 1.184 + // enter imported types immediately 1.185 + new Object() { 1.186 + Set<Symbol> processed = new HashSet<Symbol>(); 1.187 + void importFrom(TypeSymbol tsym) { 1.188 + if (tsym == null || !processed.add(tsym)) 1.189 + return; 1.190 + 1.191 + // also import inherited names 1.192 + importFrom(types.supertype(tsym.type).tsym); 1.193 + for (Type t : types.interfaces(tsym.type)) 1.194 + importFrom(t.tsym); 1.195 + 1.196 + final Scope fromScope = tsym.members(); 1.197 + for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) { 1.198 + Symbol sym = e.sym; 1.199 + if (sym.kind == TYP && 1.200 + (sym.flags() & STATIC) != 0 && 1.201 + staticImportAccessible(sym, packge) && 1.202 + sym.isMemberOf(origin, types) && 1.203 + !toScope.includes(sym)) 1.204 + toScope.enter(sym, fromScope, origin.members(), true); 1.205 + } 1.206 + } 1.207 + }.importFrom(tsym); 1.208 + 1.209 + // enter non-types before annotations that might use them 1.210 + annotate.earlier(new Annotate.Worker() { 1.211 + Set<Symbol> processed = new HashSet<Symbol>(); 1.212 + 1.213 + public String toString() { 1.214 + return "import static " + tsym + ".*" + " in " + sourcefile; 1.215 + } 1.216 + void importFrom(TypeSymbol tsym) { 1.217 + if (tsym == null || !processed.add(tsym)) 1.218 + return; 1.219 + 1.220 + // also import inherited names 1.221 + importFrom(types.supertype(tsym.type).tsym); 1.222 + for (Type t : types.interfaces(tsym.type)) 1.223 + importFrom(t.tsym); 1.224 + 1.225 + final Scope fromScope = tsym.members(); 1.226 + for (Scope.Entry e = fromScope.elems; e != null; e = e.sibling) { 1.227 + Symbol sym = e.sym; 1.228 + if (sym.isStatic() && sym.kind != TYP && 1.229 + staticImportAccessible(sym, packge) && 1.230 + !toScope.includes(sym) && 1.231 + sym.isMemberOf(origin, types)) { 1.232 + toScope.enter(sym, fromScope, origin.members(), true); 1.233 + } 1.234 + } 1.235 + } 1.236 + public void run() { 1.237 + importFrom(tsym); 1.238 + } 1.239 + }); 1.240 + } 1.241 + 1.242 + // is the sym accessible everywhere in packge? 1.243 + boolean staticImportAccessible(Symbol sym, PackageSymbol packge) { 1.244 + int flags = (int)(sym.flags() & AccessFlags); 1.245 + switch (flags) { 1.246 + default: 1.247 + case PUBLIC: 1.248 + return true; 1.249 + case PRIVATE: 1.250 + return false; 1.251 + case 0: 1.252 + case PROTECTED: 1.253 + return sym.packge() == packge; 1.254 + } 1.255 + } 1.256 + 1.257 + /** Import statics types of a given name. Non-types are handled in Attr. 1.258 + * @param pos Position to be used for error reporting. 1.259 + * @param tsym The class from which the name is imported. 1.260 + * @param name The (simple) name being imported. 1.261 + * @param env The environment containing the named import 1.262 + * scope to add to. 1.263 + */ 1.264 + private void importNamedStatic(final DiagnosticPosition pos, 1.265 + final TypeSymbol tsym, 1.266 + final Name name, 1.267 + final Env<AttrContext> env) { 1.268 + if (tsym.kind != TYP) { 1.269 + log.error(DiagnosticFlag.RECOVERABLE, pos, "static.imp.only.classes.and.interfaces"); 1.270 + return; 1.271 + } 1.272 + 1.273 + final Scope toScope = env.toplevel.namedImportScope; 1.274 + final PackageSymbol packge = env.toplevel.packge; 1.275 + final TypeSymbol origin = tsym; 1.276 + 1.277 + // enter imported types immediately 1.278 + new Object() { 1.279 + Set<Symbol> processed = new HashSet<Symbol>(); 1.280 + void importFrom(TypeSymbol tsym) { 1.281 + if (tsym == null || !processed.add(tsym)) 1.282 + return; 1.283 + 1.284 + // also import inherited names 1.285 + importFrom(types.supertype(tsym.type).tsym); 1.286 + for (Type t : types.interfaces(tsym.type)) 1.287 + importFrom(t.tsym); 1.288 + 1.289 + for (Scope.Entry e = tsym.members().lookup(name); 1.290 + e.scope != null; 1.291 + e = e.next()) { 1.292 + Symbol sym = e.sym; 1.293 + if (sym.isStatic() && 1.294 + sym.kind == TYP && 1.295 + staticImportAccessible(sym, packge) && 1.296 + sym.isMemberOf(origin, types) && 1.297 + chk.checkUniqueStaticImport(pos, sym, toScope)) 1.298 + toScope.enter(sym, sym.owner.members(), origin.members(), true); 1.299 + } 1.300 + } 1.301 + }.importFrom(tsym); 1.302 + 1.303 + // enter non-types before annotations that might use them 1.304 + annotate.earlier(new Annotate.Worker() { 1.305 + Set<Symbol> processed = new HashSet<Symbol>(); 1.306 + boolean found = false; 1.307 + 1.308 + public String toString() { 1.309 + return "import static " + tsym + "." + name; 1.310 + } 1.311 + void importFrom(TypeSymbol tsym) { 1.312 + if (tsym == null || !processed.add(tsym)) 1.313 + return; 1.314 + 1.315 + // also import inherited names 1.316 + importFrom(types.supertype(tsym.type).tsym); 1.317 + for (Type t : types.interfaces(tsym.type)) 1.318 + importFrom(t.tsym); 1.319 + 1.320 + for (Scope.Entry e = tsym.members().lookup(name); 1.321 + e.scope != null; 1.322 + e = e.next()) { 1.323 + Symbol sym = e.sym; 1.324 + if (sym.isStatic() && 1.325 + staticImportAccessible(sym, packge) && 1.326 + sym.isMemberOf(origin, types)) { 1.327 + found = true; 1.328 + if (sym.kind != TYP) { 1.329 + toScope.enter(sym, sym.owner.members(), origin.members(), true); 1.330 + } 1.331 + } 1.332 + } 1.333 + } 1.334 + public void run() { 1.335 + JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 1.336 + try { 1.337 + importFrom(tsym); 1.338 + if (!found) { 1.339 + log.error(pos, "cant.resolve.location", 1.340 + KindName.STATIC, 1.341 + name, List.<Type>nil(), List.<Type>nil(), 1.342 + Kinds.typeKindName(tsym.type), 1.343 + tsym.type); 1.344 + } 1.345 + } finally { 1.346 + log.useSource(prev); 1.347 + } 1.348 + } 1.349 + }); 1.350 + } 1.351 + /** Import given class. 1.352 + * @param pos Position to be used for error reporting. 1.353 + * @param tsym The class to be imported. 1.354 + * @param env The environment containing the named import 1.355 + * scope to add to. 1.356 + */ 1.357 + private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) { 1.358 + if (tsym.kind == TYP && 1.359 + chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope)) 1.360 + env.toplevel.namedImportScope.enter(tsym, tsym.owner.members()); 1.361 + } 1.362 + 1.363 + /** Construct method type from method signature. 1.364 + * @param typarams The method's type parameters. 1.365 + * @param params The method's value parameters. 1.366 + * @param res The method's result type, 1.367 + * null if it is a constructor. 1.368 + * @param recvparam The method's receiver parameter, 1.369 + * null if none given; TODO: or already set here? 1.370 + * @param thrown The method's thrown exceptions. 1.371 + * @param env The method's (local) environment. 1.372 + */ 1.373 + Type signature(MethodSymbol msym, 1.374 + List<JCTypeParameter> typarams, 1.375 + List<JCVariableDecl> params, 1.376 + JCTree res, 1.377 + JCVariableDecl recvparam, 1.378 + List<JCExpression> thrown, 1.379 + Env<AttrContext> env) { 1.380 + 1.381 + // Enter and attribute type parameters. 1.382 + List<Type> tvars = enter.classEnter(typarams, env); 1.383 + attr.attribTypeVariables(typarams, env); 1.384 + 1.385 + // Enter and attribute value parameters. 1.386 + ListBuffer<Type> argbuf = new ListBuffer<Type>(); 1.387 + for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) { 1.388 + memberEnter(l.head, env); 1.389 + argbuf.append(l.head.vartype.type); 1.390 + } 1.391 + 1.392 + // Attribute result type, if one is given. 1.393 + Type restype = res == null ? syms.voidType : attr.attribType(res, env); 1.394 + 1.395 + // Attribute receiver type, if one is given. 1.396 + Type recvtype; 1.397 + if (recvparam!=null) { 1.398 + memberEnter(recvparam, env); 1.399 + recvtype = recvparam.vartype.type; 1.400 + } else { 1.401 + recvtype = null; 1.402 + } 1.403 + 1.404 + // Attribute thrown exceptions. 1.405 + ListBuffer<Type> thrownbuf = new ListBuffer<Type>(); 1.406 + for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) { 1.407 + Type exc = attr.attribType(l.head, env); 1.408 + if (!exc.hasTag(TYPEVAR)) { 1.409 + exc = chk.checkClassType(l.head.pos(), exc); 1.410 + } else if (exc.tsym.owner == msym) { 1.411 + //mark inference variables in 'throws' clause 1.412 + exc.tsym.flags_field |= THROWS; 1.413 + } 1.414 + thrownbuf.append(exc); 1.415 + } 1.416 + MethodType mtype = new MethodType(argbuf.toList(), 1.417 + restype, 1.418 + thrownbuf.toList(), 1.419 + syms.methodClass); 1.420 + mtype.recvtype = recvtype; 1.421 + 1.422 + return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype); 1.423 + } 1.424 + 1.425 +/* ******************************************************************** 1.426 + * Visitor methods for member enter 1.427 + *********************************************************************/ 1.428 + 1.429 + /** Visitor argument: the current environment 1.430 + */ 1.431 + protected Env<AttrContext> env; 1.432 + 1.433 + /** Enter field and method definitions and process import 1.434 + * clauses, catching any completion failure exceptions. 1.435 + */ 1.436 + protected void memberEnter(JCTree tree, Env<AttrContext> env) { 1.437 + Env<AttrContext> prevEnv = this.env; 1.438 + try { 1.439 + this.env = env; 1.440 + tree.accept(this); 1.441 + } catch (CompletionFailure ex) { 1.442 + chk.completionError(tree.pos(), ex); 1.443 + } finally { 1.444 + this.env = prevEnv; 1.445 + } 1.446 + } 1.447 + 1.448 + /** Enter members from a list of trees. 1.449 + */ 1.450 + void memberEnter(List<? extends JCTree> trees, Env<AttrContext> env) { 1.451 + for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) 1.452 + memberEnter(l.head, env); 1.453 + } 1.454 + 1.455 + /** Enter members for a class. 1.456 + */ 1.457 + void finishClass(JCClassDecl tree, Env<AttrContext> env) { 1.458 + if ((tree.mods.flags & Flags.ENUM) != 0 && 1.459 + (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { 1.460 + addEnumMembers(tree, env); 1.461 + } 1.462 + memberEnter(tree.defs, env); 1.463 + } 1.464 + 1.465 + /** Add the implicit members for an enum type 1.466 + * to the symbol table. 1.467 + */ 1.468 + private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) { 1.469 + JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass)); 1.470 + 1.471 + // public static T[] values() { return ???; } 1.472 + JCMethodDecl values = make. 1.473 + MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), 1.474 + names.values, 1.475 + valuesType, 1.476 + List.<JCTypeParameter>nil(), 1.477 + List.<JCVariableDecl>nil(), 1.478 + List.<JCExpression>nil(), // thrown 1.479 + null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), 1.480 + null); 1.481 + memberEnter(values, env); 1.482 + 1.483 + // public static T valueOf(String name) { return ???; } 1.484 + JCMethodDecl valueOf = make. 1.485 + MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), 1.486 + names.valueOf, 1.487 + make.Type(tree.sym.type), 1.488 + List.<JCTypeParameter>nil(), 1.489 + List.of(make.VarDef(make.Modifiers(Flags.PARAMETER | 1.490 + Flags.MANDATED), 1.491 + names.fromString("name"), 1.492 + make.Type(syms.stringType), null)), 1.493 + List.<JCExpression>nil(), // thrown 1.494 + null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), 1.495 + null); 1.496 + memberEnter(valueOf, env); 1.497 + } 1.498 + 1.499 + public void visitTopLevel(JCCompilationUnit tree) { 1.500 + if (tree.starImportScope.elems != null) { 1.501 + // we must have already processed this toplevel 1.502 + return; 1.503 + } 1.504 + 1.505 + // check that no class exists with same fully qualified name as 1.506 + // toplevel package 1.507 + if (checkClash && tree.pid != null) { 1.508 + Symbol p = tree.packge; 1.509 + while (p.owner != syms.rootPackage) { 1.510 + p.owner.complete(); // enter all class members of p 1.511 + if (syms.classes.get(p.getQualifiedName()) != null) { 1.512 + log.error(tree.pos, 1.513 + "pkg.clashes.with.class.of.same.name", 1.514 + p); 1.515 + } 1.516 + p = p.owner; 1.517 + } 1.518 + } 1.519 + 1.520 + // process package annotations 1.521 + annotateLater(tree.packageAnnotations, env, tree.packge, null); 1.522 + 1.523 + DiagnosticPosition prevLintPos = deferredLintHandler.immediate(); 1.524 + Lint prevLint = chk.setLint(lint); 1.525 + 1.526 + try { 1.527 + // Import-on-demand java.lang. 1.528 + importAll(tree.pos, reader.enterPackage(names.java_lang), env); 1.529 + 1.530 + // Process all import clauses. 1.531 + memberEnter(tree.defs, env); 1.532 + } finally { 1.533 + chk.setLint(prevLint); 1.534 + deferredLintHandler.setPos(prevLintPos); 1.535 + } 1.536 + } 1.537 + 1.538 + // process the non-static imports and the static imports of types. 1.539 + public void visitImport(JCImport tree) { 1.540 + JCFieldAccess imp = (JCFieldAccess)tree.qualid; 1.541 + Name name = TreeInfo.name(imp); 1.542 + 1.543 + // Create a local environment pointing to this tree to disable 1.544 + // effects of other imports in Resolve.findGlobalType 1.545 + Env<AttrContext> localEnv = env.dup(tree); 1.546 + 1.547 + TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; 1.548 + if (name == names.asterisk) { 1.549 + // Import on demand. 1.550 + chk.checkCanonical(imp.selected); 1.551 + if (tree.staticImport) 1.552 + importStaticAll(tree.pos, p, env); 1.553 + else 1.554 + importAll(tree.pos, p, env); 1.555 + } else { 1.556 + // Named type import. 1.557 + if (tree.staticImport) { 1.558 + importNamedStatic(tree.pos(), p, name, localEnv); 1.559 + chk.checkCanonical(imp.selected); 1.560 + } else { 1.561 + TypeSymbol c = attribImportType(imp, localEnv).tsym; 1.562 + chk.checkCanonical(imp); 1.563 + importNamed(tree.pos(), c, env); 1.564 + } 1.565 + } 1.566 + } 1.567 + 1.568 + public void visitMethodDef(JCMethodDecl tree) { 1.569 + Scope enclScope = enter.enterScope(env); 1.570 + MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner); 1.571 + m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree); 1.572 + tree.sym = m; 1.573 + 1.574 + //if this is a default method, add the DEFAULT flag to the enclosing interface 1.575 + if ((tree.mods.flags & DEFAULT) != 0) { 1.576 + m.enclClass().flags_field |= DEFAULT; 1.577 + } 1.578 + 1.579 + Env<AttrContext> localEnv = methodEnv(tree, env); 1.580 + 1.581 + annotate.enterStart(); 1.582 + try { 1.583 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 1.584 + try { 1.585 + // Compute the method type 1.586 + m.type = signature(m, tree.typarams, tree.params, 1.587 + tree.restype, tree.recvparam, 1.588 + tree.thrown, 1.589 + localEnv); 1.590 + } finally { 1.591 + deferredLintHandler.setPos(prevLintPos); 1.592 + } 1.593 + 1.594 + if (types.isSignaturePolymorphic(m)) { 1.595 + m.flags_field |= SIGNATURE_POLYMORPHIC; 1.596 + } 1.597 + 1.598 + // Set m.params 1.599 + ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>(); 1.600 + JCVariableDecl lastParam = null; 1.601 + for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { 1.602 + JCVariableDecl param = lastParam = l.head; 1.603 + params.append(Assert.checkNonNull(param.sym)); 1.604 + } 1.605 + m.params = params.toList(); 1.606 + 1.607 + // mark the method varargs, if necessary 1.608 + if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) 1.609 + m.flags_field |= Flags.VARARGS; 1.610 + 1.611 + localEnv.info.scope.leave(); 1.612 + if (chk.checkUnique(tree.pos(), m, enclScope)) { 1.613 + enclScope.enter(m); 1.614 + } 1.615 + 1.616 + annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); 1.617 + // Visit the signature of the method. Note that 1.618 + // TypeAnnotate doesn't descend into the body. 1.619 + typeAnnotate(tree, localEnv, m, tree.pos()); 1.620 + 1.621 + if (tree.defaultValue != null) 1.622 + annotateDefaultValueLater(tree.defaultValue, localEnv, m); 1.623 + } finally { 1.624 + annotate.enterDone(); 1.625 + } 1.626 + } 1.627 + 1.628 + /** Create a fresh environment for method bodies. 1.629 + * @param tree The method definition. 1.630 + * @param env The environment current outside of the method definition. 1.631 + */ 1.632 + Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) { 1.633 + Env<AttrContext> localEnv = 1.634 + env.dup(tree, env.info.dup(env.info.scope.dupUnshared())); 1.635 + localEnv.enclMethod = tree; 1.636 + localEnv.info.scope.owner = tree.sym; 1.637 + if (tree.sym.type != null) { 1.638 + //when this is called in the enter stage, there's no type to be set 1.639 + localEnv.info.returnResult = attr.new ResultInfo(VAL, tree.sym.type.getReturnType()); 1.640 + } 1.641 + if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++; 1.642 + return localEnv; 1.643 + } 1.644 + 1.645 + public void visitVarDef(JCVariableDecl tree) { 1.646 + Env<AttrContext> localEnv = env; 1.647 + if ((tree.mods.flags & STATIC) != 0 || 1.648 + (env.info.scope.owner.flags() & INTERFACE) != 0) { 1.649 + localEnv = env.dup(tree, env.info.dup()); 1.650 + localEnv.info.staticLevel++; 1.651 + } 1.652 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 1.653 + annotate.enterStart(); 1.654 + try { 1.655 + try { 1.656 + if (TreeInfo.isEnumInit(tree)) { 1.657 + attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); 1.658 + } else { 1.659 + attr.attribType(tree.vartype, localEnv); 1.660 + if (TreeInfo.isReceiverParam(tree)) 1.661 + checkReceiver(tree, localEnv); 1.662 + } 1.663 + } finally { 1.664 + deferredLintHandler.setPos(prevLintPos); 1.665 + } 1.666 + 1.667 + if ((tree.mods.flags & VARARGS) != 0) { 1.668 + //if we are entering a varargs parameter, we need to 1.669 + //replace its type (a plain array type) with the more 1.670 + //precise VarargsType --- we need to do it this way 1.671 + //because varargs is represented in the tree as a 1.672 + //modifier on the parameter declaration, and not as a 1.673 + //distinct type of array node. 1.674 + ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType(); 1.675 + tree.vartype.type = atype.makeVarargs(); 1.676 + } 1.677 + Scope enclScope = enter.enterScope(env); 1.678 + VarSymbol v = 1.679 + new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); 1.680 + v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); 1.681 + tree.sym = v; 1.682 + if (tree.init != null) { 1.683 + v.flags_field |= HASINIT; 1.684 + if ((v.flags_field & FINAL) != 0 && 1.685 + needsLazyConstValue(tree.init)) { 1.686 + Env<AttrContext> initEnv = getInitEnv(tree, env); 1.687 + initEnv.info.enclVar = v; 1.688 + v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); 1.689 + } 1.690 + } 1.691 + if (chk.checkUnique(tree.pos(), v, enclScope)) { 1.692 + chk.checkTransparentVar(tree.pos(), v, enclScope); 1.693 + enclScope.enter(v); 1.694 + } 1.695 + annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); 1.696 + typeAnnotate(tree.vartype, env, v, tree.pos()); 1.697 + v.pos = tree.pos; 1.698 + } finally { 1.699 + annotate.enterDone(); 1.700 + } 1.701 + } 1.702 + // where 1.703 + void checkType(JCTree tree, Type type, String diag) { 1.704 + if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) { 1.705 + log.error(tree, diag, type, tree.type); 1.706 + } 1.707 + } 1.708 + void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) { 1.709 + attr.attribExpr(tree.nameexpr, localEnv); 1.710 + MethodSymbol m = localEnv.enclMethod.sym; 1.711 + if (m.isConstructor()) { 1.712 + Type outertype = m.owner.owner.type; 1.713 + if (outertype.hasTag(TypeTag.METHOD)) { 1.714 + // we have a local inner class 1.715 + outertype = m.owner.owner.owner.type; 1.716 + } 1.717 + if (outertype.hasTag(TypeTag.CLASS)) { 1.718 + checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); 1.719 + checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); 1.720 + } else { 1.721 + log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); 1.722 + } 1.723 + } else { 1.724 + checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); 1.725 + checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); 1.726 + } 1.727 + } 1.728 + 1.729 + public boolean needsLazyConstValue(JCTree tree) { 1.730 + InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); 1.731 + tree.accept(initTreeVisitor); 1.732 + return initTreeVisitor.result; 1.733 + } 1.734 + 1.735 + /** Visitor class for expressions which might be constant expressions. 1.736 + */ 1.737 + static class InitTreeVisitor extends JCTree.Visitor { 1.738 + 1.739 + private boolean result = true; 1.740 + 1.741 + @Override 1.742 + public void visitTree(JCTree tree) {} 1.743 + 1.744 + @Override 1.745 + public void visitNewClass(JCNewClass that) { 1.746 + result = false; 1.747 + } 1.748 + 1.749 + @Override 1.750 + public void visitNewArray(JCNewArray that) { 1.751 + result = false; 1.752 + } 1.753 + 1.754 + @Override 1.755 + public void visitLambda(JCLambda that) { 1.756 + result = false; 1.757 + } 1.758 + 1.759 + @Override 1.760 + public void visitReference(JCMemberReference that) { 1.761 + result = false; 1.762 + } 1.763 + 1.764 + @Override 1.765 + public void visitApply(JCMethodInvocation that) { 1.766 + result = false; 1.767 + } 1.768 + 1.769 + @Override 1.770 + public void visitSelect(JCFieldAccess tree) { 1.771 + tree.selected.accept(this); 1.772 + } 1.773 + 1.774 + @Override 1.775 + public void visitConditional(JCConditional tree) { 1.776 + tree.cond.accept(this); 1.777 + tree.truepart.accept(this); 1.778 + tree.falsepart.accept(this); 1.779 + } 1.780 + 1.781 + @Override 1.782 + public void visitParens(JCParens tree) { 1.783 + tree.expr.accept(this); 1.784 + } 1.785 + 1.786 + @Override 1.787 + public void visitTypeCast(JCTypeCast tree) { 1.788 + tree.expr.accept(this); 1.789 + } 1.790 + } 1.791 + 1.792 + /** Create a fresh environment for a variable's initializer. 1.793 + * If the variable is a field, the owner of the environment's scope 1.794 + * is be the variable itself, otherwise the owner is the method 1.795 + * enclosing the variable definition. 1.796 + * 1.797 + * @param tree The variable definition. 1.798 + * @param env The environment current outside of the variable definition. 1.799 + */ 1.800 + Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) { 1.801 + Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup())); 1.802 + if (tree.sym.owner.kind == TYP) { 1.803 + localEnv.info.scope = env.info.scope.dupUnshared(); 1.804 + localEnv.info.scope.owner = tree.sym; 1.805 + } 1.806 + if ((tree.mods.flags & STATIC) != 0 || 1.807 + ((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null)) 1.808 + localEnv.info.staticLevel++; 1.809 + return localEnv; 1.810 + } 1.811 + 1.812 + /** Default member enter visitor method: do nothing 1.813 + */ 1.814 + public void visitTree(JCTree tree) { 1.815 + } 1.816 + 1.817 + public void visitErroneous(JCErroneous tree) { 1.818 + if (tree.errs != null) 1.819 + memberEnter(tree.errs, env); 1.820 + } 1.821 + 1.822 + public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) { 1.823 + Env<AttrContext> mEnv = methodEnv(tree, env); 1.824 + mEnv.info.lint = mEnv.info.lint.augment(tree.sym); 1.825 + for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) 1.826 + mEnv.info.scope.enterIfAbsent(l.head.type.tsym); 1.827 + for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) 1.828 + mEnv.info.scope.enterIfAbsent(l.head.sym); 1.829 + return mEnv; 1.830 + } 1.831 + 1.832 + public Env<AttrContext> getInitEnv(JCVariableDecl tree, Env<AttrContext> env) { 1.833 + Env<AttrContext> iEnv = initEnv(tree, env); 1.834 + return iEnv; 1.835 + } 1.836 + 1.837 +/* ******************************************************************** 1.838 + * Type completion 1.839 + *********************************************************************/ 1.840 + 1.841 + Type attribImportType(JCTree tree, Env<AttrContext> env) { 1.842 + Assert.check(completionEnabled); 1.843 + try { 1.844 + // To prevent deep recursion, suppress completion of some 1.845 + // types. 1.846 + completionEnabled = false; 1.847 + return attr.attribType(tree, env); 1.848 + } finally { 1.849 + completionEnabled = true; 1.850 + } 1.851 + } 1.852 + 1.853 +/* ******************************************************************** 1.854 + * Annotation processing 1.855 + *********************************************************************/ 1.856 + 1.857 + /** Queue annotations for later processing. */ 1.858 + void annotateLater(final List<JCAnnotation> annotations, 1.859 + final Env<AttrContext> localEnv, 1.860 + final Symbol s, 1.861 + final DiagnosticPosition deferPos) { 1.862 + if (annotations.isEmpty()) { 1.863 + return; 1.864 + } 1.865 + if (s.kind != PCK) { 1.866 + s.resetAnnotations(); // mark Annotations as incomplete for now 1.867 + } 1.868 + annotate.normal(new Annotate.Worker() { 1.869 + @Override 1.870 + public String toString() { 1.871 + return "annotate " + annotations + " onto " + s + " in " + s.owner; 1.872 + } 1.873 + 1.874 + @Override 1.875 + public void run() { 1.876 + Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); 1.877 + JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); 1.878 + DiagnosticPosition prevLintPos = 1.879 + deferPos != null 1.880 + ? deferredLintHandler.setPos(deferPos) 1.881 + : deferredLintHandler.immediate(); 1.882 + Lint prevLint = deferPos != null ? null : chk.setLint(lint); 1.883 + try { 1.884 + if (s.hasAnnotations() && 1.885 + annotations.nonEmpty()) 1.886 + log.error(annotations.head.pos, 1.887 + "already.annotated", 1.888 + kindName(s), s); 1.889 + actualEnterAnnotations(annotations, localEnv, s); 1.890 + } finally { 1.891 + if (prevLint != null) 1.892 + chk.setLint(prevLint); 1.893 + deferredLintHandler.setPos(prevLintPos); 1.894 + log.useSource(prev); 1.895 + } 1.896 + } 1.897 + }); 1.898 + 1.899 + annotate.validate(new Annotate.Worker() { //validate annotations 1.900 + @Override 1.901 + public void run() { 1.902 + JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); 1.903 + try { 1.904 + chk.validateAnnotations(annotations, s); 1.905 + } finally { 1.906 + log.useSource(prev); 1.907 + } 1.908 + } 1.909 + }); 1.910 + } 1.911 + 1.912 + /** 1.913 + * Check if a list of annotations contains a reference to 1.914 + * java.lang.Deprecated. 1.915 + **/ 1.916 + private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) { 1.917 + for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { 1.918 + JCAnnotation a = al.head; 1.919 + if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty()) 1.920 + return true; 1.921 + } 1.922 + return false; 1.923 + } 1.924 + 1.925 + /** Enter a set of annotations. */ 1.926 + private void actualEnterAnnotations(List<JCAnnotation> annotations, 1.927 + Env<AttrContext> env, 1.928 + Symbol s) { 1.929 + Map<TypeSymbol, ListBuffer<Attribute.Compound>> annotated = 1.930 + new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.Compound>>(); 1.931 + Map<Attribute.Compound, DiagnosticPosition> pos = 1.932 + new HashMap<Attribute.Compound, DiagnosticPosition>(); 1.933 + 1.934 + for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { 1.935 + JCAnnotation a = al.head; 1.936 + Attribute.Compound c = annotate.enterAnnotation(a, 1.937 + syms.annotationType, 1.938 + env); 1.939 + if (c == null) { 1.940 + continue; 1.941 + } 1.942 + 1.943 + if (annotated.containsKey(a.type.tsym)) { 1.944 + if (!allowRepeatedAnnos) { 1.945 + log.error(a.pos(), "repeatable.annotations.not.supported.in.source"); 1.946 + allowRepeatedAnnos = true; 1.947 + } 1.948 + ListBuffer<Attribute.Compound> l = annotated.get(a.type.tsym); 1.949 + l = l.append(c); 1.950 + annotated.put(a.type.tsym, l); 1.951 + pos.put(c, a.pos()); 1.952 + } else { 1.953 + annotated.put(a.type.tsym, ListBuffer.of(c)); 1.954 + pos.put(c, a.pos()); 1.955 + } 1.956 + 1.957 + // Note: @Deprecated has no effect on local variables and parameters 1.958 + if (!c.type.isErroneous() 1.959 + && s.owner.kind != MTH 1.960 + && types.isSameType(c.type, syms.deprecatedType)) { 1.961 + s.flags_field |= Flags.DEPRECATED; 1.962 + } 1.963 + } 1.964 + 1.965 + s.setDeclarationAttributesWithCompletion( 1.966 + annotate.new AnnotateRepeatedContext<Attribute.Compound>(env, annotated, pos, log, false)); 1.967 + } 1.968 + 1.969 + /** Queue processing of an attribute default value. */ 1.970 + void annotateDefaultValueLater(final JCExpression defaultValue, 1.971 + final Env<AttrContext> localEnv, 1.972 + final MethodSymbol m) { 1.973 + annotate.normal(new Annotate.Worker() { 1.974 + @Override 1.975 + public String toString() { 1.976 + return "annotate " + m.owner + "." + 1.977 + m + " default " + defaultValue; 1.978 + } 1.979 + 1.980 + @Override 1.981 + public void run() { 1.982 + JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); 1.983 + try { 1.984 + enterDefaultValue(defaultValue, localEnv, m); 1.985 + } finally { 1.986 + log.useSource(prev); 1.987 + } 1.988 + } 1.989 + }); 1.990 + annotate.validate(new Annotate.Worker() { //validate annotations 1.991 + @Override 1.992 + public void run() { 1.993 + JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); 1.994 + try { 1.995 + // if default value is an annotation, check it is a well-formed 1.996 + // annotation value (e.g. no duplicate values, no missing values, etc.) 1.997 + chk.validateAnnotationTree(defaultValue); 1.998 + } finally { 1.999 + log.useSource(prev); 1.1000 + } 1.1001 + } 1.1002 + }); 1.1003 + } 1.1004 + 1.1005 + /** Enter a default value for an attribute method. */ 1.1006 + private void enterDefaultValue(final JCExpression defaultValue, 1.1007 + final Env<AttrContext> localEnv, 1.1008 + final MethodSymbol m) { 1.1009 + m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(), 1.1010 + defaultValue, 1.1011 + localEnv); 1.1012 + } 1.1013 + 1.1014 +/* ******************************************************************** 1.1015 + * Source completer 1.1016 + *********************************************************************/ 1.1017 + 1.1018 + /** Complete entering a class. 1.1019 + * @param sym The symbol of the class to be completed. 1.1020 + */ 1.1021 + public void complete(Symbol sym) throws CompletionFailure { 1.1022 + // Suppress some (recursive) MemberEnter invocations 1.1023 + if (!completionEnabled) { 1.1024 + // Re-install same completer for next time around and return. 1.1025 + Assert.check((sym.flags() & Flags.COMPOUND) == 0); 1.1026 + sym.completer = this; 1.1027 + return; 1.1028 + } 1.1029 + 1.1030 + ClassSymbol c = (ClassSymbol)sym; 1.1031 + ClassType ct = (ClassType)c.type; 1.1032 + Env<AttrContext> env = typeEnvs.get(c); 1.1033 + JCClassDecl tree = (JCClassDecl)env.tree; 1.1034 + boolean wasFirst = isFirst; 1.1035 + isFirst = false; 1.1036 + 1.1037 + JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 1.1038 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 1.1039 + try { 1.1040 + // Save class environment for later member enter (2) processing. 1.1041 + halfcompleted.append(env); 1.1042 + 1.1043 + // Mark class as not yet attributed. 1.1044 + c.flags_field |= UNATTRIBUTED; 1.1045 + 1.1046 + // If this is a toplevel-class, make sure any preceding import 1.1047 + // clauses have been seen. 1.1048 + if (c.owner.kind == PCK) { 1.1049 + memberEnter(env.toplevel, env.enclosing(TOPLEVEL)); 1.1050 + todo.append(env); 1.1051 + } 1.1052 + 1.1053 + if (c.owner.kind == TYP) 1.1054 + c.owner.complete(); 1.1055 + 1.1056 + // create an environment for evaluating the base clauses 1.1057 + Env<AttrContext> baseEnv = baseEnv(tree, env); 1.1058 + 1.1059 + if (tree.extending != null) 1.1060 + typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); 1.1061 + for (JCExpression impl : tree.implementing) 1.1062 + typeAnnotate(impl, baseEnv, sym, tree.pos()); 1.1063 + annotate.flush(); 1.1064 + 1.1065 + // Determine supertype. 1.1066 + Type supertype = 1.1067 + (tree.extending != null) 1.1068 + ? attr.attribBase(tree.extending, baseEnv, true, false, true) 1.1069 + : ((tree.mods.flags & Flags.ENUM) != 0) 1.1070 + ? attr.attribBase(enumBase(tree.pos, c), baseEnv, 1.1071 + true, false, false) 1.1072 + : (c.fullname == names.java_lang_Object) 1.1073 + ? Type.noType 1.1074 + : syms.objectType; 1.1075 + ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); 1.1076 + 1.1077 + // Determine interfaces. 1.1078 + ListBuffer<Type> interfaces = new ListBuffer<Type>(); 1.1079 + ListBuffer<Type> all_interfaces = null; // lazy init 1.1080 + Set<Type> interfaceSet = new HashSet<Type>(); 1.1081 + List<JCExpression> interfaceTrees = tree.implementing; 1.1082 + for (JCExpression iface : interfaceTrees) { 1.1083 + Type i = attr.attribBase(iface, baseEnv, false, true, true); 1.1084 + if (i.hasTag(CLASS)) { 1.1085 + interfaces.append(i); 1.1086 + if (all_interfaces != null) all_interfaces.append(i); 1.1087 + chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet); 1.1088 + } else { 1.1089 + if (all_interfaces == null) 1.1090 + all_interfaces = new ListBuffer<Type>().appendList(interfaces); 1.1091 + all_interfaces.append(modelMissingTypes(i, iface, true)); 1.1092 + } 1.1093 + } 1.1094 + if ((c.flags_field & ANNOTATION) != 0) { 1.1095 + ct.interfaces_field = List.of(syms.annotationType); 1.1096 + ct.all_interfaces_field = ct.interfaces_field; 1.1097 + } else { 1.1098 + ct.interfaces_field = interfaces.toList(); 1.1099 + ct.all_interfaces_field = (all_interfaces == null) 1.1100 + ? ct.interfaces_field : all_interfaces.toList(); 1.1101 + } 1.1102 + 1.1103 + if (c.fullname == names.java_lang_Object) { 1.1104 + if (tree.extending != null) { 1.1105 + chk.checkNonCyclic(tree.extending.pos(), 1.1106 + supertype); 1.1107 + ct.supertype_field = Type.noType; 1.1108 + } 1.1109 + else if (tree.implementing.nonEmpty()) { 1.1110 + chk.checkNonCyclic(tree.implementing.head.pos(), 1.1111 + ct.interfaces_field.head); 1.1112 + ct.interfaces_field = List.nil(); 1.1113 + } 1.1114 + } 1.1115 + 1.1116 + // Annotations. 1.1117 + // In general, we cannot fully process annotations yet, but we 1.1118 + // can attribute the annotation types and then check to see if the 1.1119 + // @Deprecated annotation is present. 1.1120 + attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); 1.1121 + if (hasDeprecatedAnnotation(tree.mods.annotations)) 1.1122 + c.flags_field |= DEPRECATED; 1.1123 + annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); 1.1124 + // class type parameters use baseEnv but everything uses env 1.1125 + 1.1126 + chk.checkNonCyclicDecl(tree); 1.1127 + 1.1128 + attr.attribTypeVariables(tree.typarams, baseEnv); 1.1129 + // Do this here, where we have the symbol. 1.1130 + for (JCTypeParameter tp : tree.typarams) 1.1131 + typeAnnotate(tp, baseEnv, sym, tree.pos()); 1.1132 + 1.1133 + // Add default constructor if needed. 1.1134 + if ((c.flags() & INTERFACE) == 0 && 1.1135 + !TreeInfo.hasConstructors(tree.defs)) { 1.1136 + List<Type> argtypes = List.nil(); 1.1137 + List<Type> typarams = List.nil(); 1.1138 + List<Type> thrown = List.nil(); 1.1139 + long ctorFlags = 0; 1.1140 + boolean based = false; 1.1141 + boolean addConstructor = true; 1.1142 + JCNewClass nc = null; 1.1143 + if (c.name.isEmpty()) { 1.1144 + nc = (JCNewClass)env.next.tree; 1.1145 + if (nc.constructor != null) { 1.1146 + addConstructor = nc.constructor.kind != ERR; 1.1147 + Type superConstrType = types.memberType(c.type, 1.1148 + nc.constructor); 1.1149 + argtypes = superConstrType.getParameterTypes(); 1.1150 + typarams = superConstrType.getTypeArguments(); 1.1151 + ctorFlags = nc.constructor.flags() & VARARGS; 1.1152 + if (nc.encl != null) { 1.1153 + argtypes = argtypes.prepend(nc.encl.type); 1.1154 + based = true; 1.1155 + } 1.1156 + thrown = superConstrType.getThrownTypes(); 1.1157 + } 1.1158 + } 1.1159 + if (addConstructor) { 1.1160 + MethodSymbol basedConstructor = nc != null ? 1.1161 + (MethodSymbol)nc.constructor : null; 1.1162 + JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, 1.1163 + basedConstructor, 1.1164 + typarams, argtypes, thrown, 1.1165 + ctorFlags, based); 1.1166 + tree.defs = tree.defs.prepend(constrDef); 1.1167 + } 1.1168 + } 1.1169 + 1.1170 + // enter symbols for 'this' into current scope. 1.1171 + VarSymbol thisSym = 1.1172 + new VarSymbol(FINAL | HASINIT, names._this, c.type, c); 1.1173 + thisSym.pos = Position.FIRSTPOS; 1.1174 + env.info.scope.enter(thisSym); 1.1175 + // if this is a class, enter symbol for 'super' into current scope. 1.1176 + if ((c.flags_field & INTERFACE) == 0 && 1.1177 + ct.supertype_field.hasTag(CLASS)) { 1.1178 + VarSymbol superSym = 1.1179 + new VarSymbol(FINAL | HASINIT, names._super, 1.1180 + ct.supertype_field, c); 1.1181 + superSym.pos = Position.FIRSTPOS; 1.1182 + env.info.scope.enter(superSym); 1.1183 + } 1.1184 + 1.1185 + // check that no package exists with same fully qualified name, 1.1186 + // but admit classes in the unnamed package which have the same 1.1187 + // name as a top-level package. 1.1188 + if (checkClash && 1.1189 + c.owner.kind == PCK && c.owner != syms.unnamedPackage && 1.1190 + reader.packageExists(c.fullname)) { 1.1191 + log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c); 1.1192 + } 1.1193 + if (c.owner.kind == PCK && (c.flags_field & PUBLIC) == 0 && 1.1194 + !env.toplevel.sourcefile.isNameCompatible(c.name.toString(),JavaFileObject.Kind.SOURCE)) { 1.1195 + c.flags_field |= AUXILIARY; 1.1196 + } 1.1197 + } catch (CompletionFailure ex) { 1.1198 + chk.completionError(tree.pos(), ex); 1.1199 + } finally { 1.1200 + deferredLintHandler.setPos(prevLintPos); 1.1201 + log.useSource(prev); 1.1202 + } 1.1203 + 1.1204 + // Enter all member fields and methods of a set of half completed 1.1205 + // classes in a second phase. 1.1206 + if (wasFirst) { 1.1207 + try { 1.1208 + while (halfcompleted.nonEmpty()) { 1.1209 + Env<AttrContext> toFinish = halfcompleted.next(); 1.1210 + finish(toFinish); 1.1211 + if (allowTypeAnnos) { 1.1212 + typeAnnotations.organizeTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); 1.1213 + typeAnnotations.validateTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); 1.1214 + } 1.1215 + } 1.1216 + } finally { 1.1217 + isFirst = true; 1.1218 + } 1.1219 + } 1.1220 + } 1.1221 + 1.1222 + /* 1.1223 + * If the symbol is non-null, attach the type annotation to it. 1.1224 + */ 1.1225 + private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations, 1.1226 + final Env<AttrContext> env, 1.1227 + final Symbol s) { 1.1228 + Map<TypeSymbol, ListBuffer<Attribute.TypeCompound>> annotated = 1.1229 + new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.TypeCompound>>(); 1.1230 + Map<Attribute.TypeCompound, DiagnosticPosition> pos = 1.1231 + new HashMap<Attribute.TypeCompound, DiagnosticPosition>(); 1.1232 + 1.1233 + for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { 1.1234 + JCAnnotation a = al.head; 1.1235 + Attribute.TypeCompound tc = annotate.enterTypeAnnotation(a, 1.1236 + syms.annotationType, 1.1237 + env); 1.1238 + if (tc == null) { 1.1239 + continue; 1.1240 + } 1.1241 + 1.1242 + if (annotated.containsKey(a.type.tsym)) { 1.1243 + if (source.allowRepeatedAnnotations()) { 1.1244 + ListBuffer<Attribute.TypeCompound> l = annotated.get(a.type.tsym); 1.1245 + l = l.append(tc); 1.1246 + annotated.put(a.type.tsym, l); 1.1247 + pos.put(tc, a.pos()); 1.1248 + } else { 1.1249 + log.error(a.pos(), "repeatable.annotations.not.supported.in.source"); 1.1250 + } 1.1251 + } else { 1.1252 + annotated.put(a.type.tsym, ListBuffer.of(tc)); 1.1253 + pos.put(tc, a.pos()); 1.1254 + } 1.1255 + } 1.1256 + 1.1257 + if (s != null) { 1.1258 + s.appendTypeAttributesWithCompletion( 1.1259 + annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true)); 1.1260 + } 1.1261 + } 1.1262 + 1.1263 + public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) { 1.1264 + if (allowTypeAnnos) { 1.1265 + tree.accept(new TypeAnnotate(env, sym, deferPos)); 1.1266 + } 1.1267 + } 1.1268 + 1.1269 + /** 1.1270 + * We need to use a TreeScanner, because it is not enough to visit the top-level 1.1271 + * annotations. We also need to visit type arguments, etc. 1.1272 + */ 1.1273 + private class TypeAnnotate extends TreeScanner { 1.1274 + private Env<AttrContext> env; 1.1275 + private Symbol sym; 1.1276 + private DiagnosticPosition deferPos; 1.1277 + 1.1278 + public TypeAnnotate(final Env<AttrContext> env, final Symbol sym, DiagnosticPosition deferPos) { 1.1279 + this.env = env; 1.1280 + this.sym = sym; 1.1281 + this.deferPos = deferPos; 1.1282 + } 1.1283 + 1.1284 + void annotateTypeLater(final List<JCAnnotation> annotations) { 1.1285 + if (annotations.isEmpty()) { 1.1286 + return; 1.1287 + } 1.1288 + 1.1289 + final DiagnosticPosition deferPos = this.deferPos; 1.1290 + 1.1291 + annotate.normal(new Annotate.Worker() { 1.1292 + @Override 1.1293 + public String toString() { 1.1294 + return "type annotate " + annotations + " onto " + sym + " in " + sym.owner; 1.1295 + } 1.1296 + @Override 1.1297 + public void run() { 1.1298 + JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 1.1299 + DiagnosticPosition prevLintPos = null; 1.1300 + 1.1301 + if (deferPos != null) { 1.1302 + prevLintPos = deferredLintHandler.setPos(deferPos); 1.1303 + } 1.1304 + try { 1.1305 + actualEnterTypeAnnotations(annotations, env, sym); 1.1306 + } finally { 1.1307 + if (prevLintPos != null) 1.1308 + deferredLintHandler.setPos(prevLintPos); 1.1309 + log.useSource(prev); 1.1310 + } 1.1311 + } 1.1312 + }); 1.1313 + } 1.1314 + 1.1315 + @Override 1.1316 + public void visitAnnotatedType(final JCAnnotatedType tree) { 1.1317 + annotateTypeLater(tree.annotations); 1.1318 + super.visitAnnotatedType(tree); 1.1319 + } 1.1320 + 1.1321 + @Override 1.1322 + public void visitTypeParameter(final JCTypeParameter tree) { 1.1323 + annotateTypeLater(tree.annotations); 1.1324 + super.visitTypeParameter(tree); 1.1325 + } 1.1326 + 1.1327 + @Override 1.1328 + public void visitNewArray(final JCNewArray tree) { 1.1329 + annotateTypeLater(tree.annotations); 1.1330 + for (List<JCAnnotation> dimAnnos : tree.dimAnnotations) 1.1331 + annotateTypeLater(dimAnnos); 1.1332 + super.visitNewArray(tree); 1.1333 + } 1.1334 + 1.1335 + @Override 1.1336 + public void visitMethodDef(final JCMethodDecl tree) { 1.1337 + scan(tree.mods); 1.1338 + scan(tree.restype); 1.1339 + scan(tree.typarams); 1.1340 + scan(tree.recvparam); 1.1341 + scan(tree.params); 1.1342 + scan(tree.thrown); 1.1343 + scan(tree.defaultValue); 1.1344 + // Do not annotate the body, just the signature. 1.1345 + // scan(tree.body); 1.1346 + } 1.1347 + 1.1348 + @Override 1.1349 + public void visitVarDef(final JCVariableDecl tree) { 1.1350 + DiagnosticPosition prevPos = deferPos; 1.1351 + deferPos = tree.pos(); 1.1352 + try { 1.1353 + if (sym != null && sym.kind == Kinds.VAR) { 1.1354 + // Don't visit a parameter once when the sym is the method 1.1355 + // and once when the sym is the parameter. 1.1356 + scan(tree.mods); 1.1357 + scan(tree.vartype); 1.1358 + } 1.1359 + scan(tree.init); 1.1360 + } finally { 1.1361 + deferPos = prevPos; 1.1362 + } 1.1363 + } 1.1364 + 1.1365 + @Override 1.1366 + public void visitClassDef(JCClassDecl tree) { 1.1367 + // We can only hit a classdef if it is declared within 1.1368 + // a method. Ignore it - the class will be visited 1.1369 + // separately later. 1.1370 + } 1.1371 + 1.1372 + @Override 1.1373 + public void visitNewClass(JCNewClass tree) { 1.1374 + if (tree.def == null) { 1.1375 + // For an anonymous class instantiation the class 1.1376 + // will be visited separately. 1.1377 + super.visitNewClass(tree); 1.1378 + } 1.1379 + } 1.1380 + } 1.1381 + 1.1382 + 1.1383 + private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) { 1.1384 + Scope baseScope = new Scope(tree.sym); 1.1385 + //import already entered local classes into base scope 1.1386 + for (Scope.Entry e = env.outer.info.scope.elems ; e != null ; e = e.sibling) { 1.1387 + if (e.sym.isLocal()) { 1.1388 + baseScope.enter(e.sym); 1.1389 + } 1.1390 + } 1.1391 + //import current type-parameters into base scope 1.1392 + if (tree.typarams != null) 1.1393 + for (List<JCTypeParameter> typarams = tree.typarams; 1.1394 + typarams.nonEmpty(); 1.1395 + typarams = typarams.tail) 1.1396 + baseScope.enter(typarams.head.type.tsym); 1.1397 + Env<AttrContext> outer = env.outer; // the base clause can't see members of this class 1.1398 + Env<AttrContext> localEnv = outer.dup(tree, outer.info.dup(baseScope)); 1.1399 + localEnv.baseClause = true; 1.1400 + localEnv.outer = outer; 1.1401 + localEnv.info.isSelfCall = false; 1.1402 + return localEnv; 1.1403 + } 1.1404 + 1.1405 + /** Enter member fields and methods of a class 1.1406 + * @param env the environment current for the class block. 1.1407 + */ 1.1408 + private void finish(Env<AttrContext> env) { 1.1409 + JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 1.1410 + try { 1.1411 + JCClassDecl tree = (JCClassDecl)env.tree; 1.1412 + finishClass(tree, env); 1.1413 + } finally { 1.1414 + log.useSource(prev); 1.1415 + } 1.1416 + } 1.1417 + 1.1418 + /** Generate a base clause for an enum type. 1.1419 + * @param pos The position for trees and diagnostics, if any 1.1420 + * @param c The class symbol of the enum 1.1421 + */ 1.1422 + private JCExpression enumBase(int pos, ClassSymbol c) { 1.1423 + JCExpression result = make.at(pos). 1.1424 + TypeApply(make.QualIdent(syms.enumSym), 1.1425 + List.<JCExpression>of(make.Type(c.type))); 1.1426 + return result; 1.1427 + } 1.1428 + 1.1429 + Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) { 1.1430 + if (!t.hasTag(ERROR)) 1.1431 + return t; 1.1432 + 1.1433 + return new ErrorType(t.getOriginalType(), t.tsym) { 1.1434 + private Type modelType; 1.1435 + 1.1436 + @Override 1.1437 + public Type getModelType() { 1.1438 + if (modelType == null) 1.1439 + modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree); 1.1440 + return modelType; 1.1441 + } 1.1442 + }; 1.1443 + } 1.1444 + // where 1.1445 + private class Synthesizer extends JCTree.Visitor { 1.1446 + Type originalType; 1.1447 + boolean interfaceExpected; 1.1448 + List<ClassSymbol> synthesizedSymbols = List.nil(); 1.1449 + Type result; 1.1450 + 1.1451 + Synthesizer(Type originalType, boolean interfaceExpected) { 1.1452 + this.originalType = originalType; 1.1453 + this.interfaceExpected = interfaceExpected; 1.1454 + } 1.1455 + 1.1456 + Type visit(JCTree tree) { 1.1457 + tree.accept(this); 1.1458 + return result; 1.1459 + } 1.1460 + 1.1461 + List<Type> visit(List<? extends JCTree> trees) { 1.1462 + ListBuffer<Type> lb = new ListBuffer<Type>(); 1.1463 + for (JCTree t: trees) 1.1464 + lb.append(visit(t)); 1.1465 + return lb.toList(); 1.1466 + } 1.1467 + 1.1468 + @Override 1.1469 + public void visitTree(JCTree tree) { 1.1470 + result = syms.errType; 1.1471 + } 1.1472 + 1.1473 + @Override 1.1474 + public void visitIdent(JCIdent tree) { 1.1475 + if (!tree.type.hasTag(ERROR)) { 1.1476 + result = tree.type; 1.1477 + } else { 1.1478 + result = synthesizeClass(tree.name, syms.unnamedPackage).type; 1.1479 + } 1.1480 + } 1.1481 + 1.1482 + @Override 1.1483 + public void visitSelect(JCFieldAccess tree) { 1.1484 + if (!tree.type.hasTag(ERROR)) { 1.1485 + result = tree.type; 1.1486 + } else { 1.1487 + Type selectedType; 1.1488 + boolean prev = interfaceExpected; 1.1489 + try { 1.1490 + interfaceExpected = false; 1.1491 + selectedType = visit(tree.selected); 1.1492 + } finally { 1.1493 + interfaceExpected = prev; 1.1494 + } 1.1495 + ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym); 1.1496 + result = c.type; 1.1497 + } 1.1498 + } 1.1499 + 1.1500 + @Override 1.1501 + public void visitTypeApply(JCTypeApply tree) { 1.1502 + if (!tree.type.hasTag(ERROR)) { 1.1503 + result = tree.type; 1.1504 + } else { 1.1505 + ClassType clazzType = (ClassType) visit(tree.clazz); 1.1506 + if (synthesizedSymbols.contains(clazzType.tsym)) 1.1507 + synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size()); 1.1508 + final List<Type> actuals = visit(tree.arguments); 1.1509 + result = new ErrorType(tree.type, clazzType.tsym) { 1.1510 + @Override 1.1511 + public List<Type> getTypeArguments() { 1.1512 + return actuals; 1.1513 + } 1.1514 + }; 1.1515 + } 1.1516 + } 1.1517 + 1.1518 + ClassSymbol synthesizeClass(Name name, Symbol owner) { 1.1519 + int flags = interfaceExpected ? INTERFACE : 0; 1.1520 + ClassSymbol c = new ClassSymbol(flags, name, owner); 1.1521 + c.members_field = new Scope.ErrorScope(c); 1.1522 + c.type = new ErrorType(originalType, c) { 1.1523 + @Override 1.1524 + public List<Type> getTypeArguments() { 1.1525 + return typarams_field; 1.1526 + } 1.1527 + }; 1.1528 + synthesizedSymbols = synthesizedSymbols.prepend(c); 1.1529 + return c; 1.1530 + } 1.1531 + 1.1532 + void synthesizeTyparams(ClassSymbol sym, int n) { 1.1533 + ClassType ct = (ClassType) sym.type; 1.1534 + Assert.check(ct.typarams_field.isEmpty()); 1.1535 + if (n == 1) { 1.1536 + TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType); 1.1537 + ct.typarams_field = ct.typarams_field.prepend(v); 1.1538 + } else { 1.1539 + for (int i = n; i > 0; i--) { 1.1540 + TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType); 1.1541 + ct.typarams_field = ct.typarams_field.prepend(v); 1.1542 + } 1.1543 + } 1.1544 + } 1.1545 + } 1.1546 + 1.1547 + 1.1548 +/* *************************************************************************** 1.1549 + * tree building 1.1550 + ****************************************************************************/ 1.1551 + 1.1552 + /** Generate default constructor for given class. For classes different 1.1553 + * from java.lang.Object, this is: 1.1554 + * 1.1555 + * c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { 1.1556 + * super(x_0, ..., x_n) 1.1557 + * } 1.1558 + * 1.1559 + * or, if based == true: 1.1560 + * 1.1561 + * c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { 1.1562 + * x_0.super(x_1, ..., x_n) 1.1563 + * } 1.1564 + * 1.1565 + * @param make The tree factory. 1.1566 + * @param c The class owning the default constructor. 1.1567 + * @param argtypes The parameter types of the constructor. 1.1568 + * @param thrown The thrown exceptions of the constructor. 1.1569 + * @param based Is first parameter a this$n? 1.1570 + */ 1.1571 + JCTree DefaultConstructor(TreeMaker make, 1.1572 + ClassSymbol c, 1.1573 + MethodSymbol baseInit, 1.1574 + List<Type> typarams, 1.1575 + List<Type> argtypes, 1.1576 + List<Type> thrown, 1.1577 + long flags, 1.1578 + boolean based) { 1.1579 + JCTree result; 1.1580 + if ((c.flags() & ENUM) != 0 && 1.1581 + (types.supertype(c.type).tsym == syms.enumSym)) { 1.1582 + // constructors of true enums are private 1.1583 + flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR; 1.1584 + } else 1.1585 + flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR; 1.1586 + if (c.name.isEmpty()) { 1.1587 + flags |= ANONCONSTR; 1.1588 + } 1.1589 + Type mType = new MethodType(argtypes, null, thrown, c); 1.1590 + Type initType = typarams.nonEmpty() ? 1.1591 + new ForAll(typarams, mType) : 1.1592 + mType; 1.1593 + MethodSymbol init = new MethodSymbol(flags, names.init, 1.1594 + initType, c); 1.1595 + init.params = createDefaultConstructorParams(make, baseInit, init, 1.1596 + argtypes, based); 1.1597 + List<JCVariableDecl> params = make.Params(argtypes, init); 1.1598 + List<JCStatement> stats = List.nil(); 1.1599 + if (c.type != syms.objectType) { 1.1600 + stats = stats.prepend(SuperCall(make, typarams, params, based)); 1.1601 + } 1.1602 + result = make.MethodDef(init, make.Block(0, stats)); 1.1603 + return result; 1.1604 + } 1.1605 + 1.1606 + private List<VarSymbol> createDefaultConstructorParams( 1.1607 + TreeMaker make, 1.1608 + MethodSymbol baseInit, 1.1609 + MethodSymbol init, 1.1610 + List<Type> argtypes, 1.1611 + boolean based) { 1.1612 + List<VarSymbol> initParams = null; 1.1613 + List<Type> argTypesList = argtypes; 1.1614 + if (based) { 1.1615 + /* In this case argtypes will have an extra type, compared to baseInit, 1.1616 + * corresponding to the type of the enclosing instance i.e.: 1.1617 + * 1.1618 + * Inner i = outer.new Inner(1){} 1.1619 + * 1.1620 + * in the above example argtypes will be (Outer, int) and baseInit 1.1621 + * will have parameter's types (int). So in this case we have to add 1.1622 + * first the extra type in argtypes and then get the names of the 1.1623 + * parameters from baseInit. 1.1624 + */ 1.1625 + initParams = List.nil(); 1.1626 + VarSymbol param = new VarSymbol(PARAMETER, make.paramName(0), argtypes.head, init); 1.1627 + initParams = initParams.append(param); 1.1628 + argTypesList = argTypesList.tail; 1.1629 + } 1.1630 + if (baseInit != null && baseInit.params != null && 1.1631 + baseInit.params.nonEmpty() && argTypesList.nonEmpty()) { 1.1632 + initParams = (initParams == null) ? List.<VarSymbol>nil() : initParams; 1.1633 + List<VarSymbol> baseInitParams = baseInit.params; 1.1634 + while (baseInitParams.nonEmpty() && argTypesList.nonEmpty()) { 1.1635 + VarSymbol param = new VarSymbol(baseInitParams.head.flags() | PARAMETER, 1.1636 + baseInitParams.head.name, argTypesList.head, init); 1.1637 + initParams = initParams.append(param); 1.1638 + baseInitParams = baseInitParams.tail; 1.1639 + argTypesList = argTypesList.tail; 1.1640 + } 1.1641 + } 1.1642 + return initParams; 1.1643 + } 1.1644 + 1.1645 + /** Generate call to superclass constructor. This is: 1.1646 + * 1.1647 + * super(id_0, ..., id_n) 1.1648 + * 1.1649 + * or, if based == true 1.1650 + * 1.1651 + * id_0.super(id_1,...,id_n) 1.1652 + * 1.1653 + * where id_0, ..., id_n are the names of the given parameters. 1.1654 + * 1.1655 + * @param make The tree factory 1.1656 + * @param params The parameters that need to be passed to super 1.1657 + * @param typarams The type parameters that need to be passed to super 1.1658 + * @param based Is first parameter a this$n? 1.1659 + */ 1.1660 + JCExpressionStatement SuperCall(TreeMaker make, 1.1661 + List<Type> typarams, 1.1662 + List<JCVariableDecl> params, 1.1663 + boolean based) { 1.1664 + JCExpression meth; 1.1665 + if (based) { 1.1666 + meth = make.Select(make.Ident(params.head), names._super); 1.1667 + params = params.tail; 1.1668 + } else { 1.1669 + meth = make.Ident(names._super); 1.1670 + } 1.1671 + List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null; 1.1672 + return make.Exec(make.Apply(typeargs, meth, make.Idents(params))); 1.1673 + } 1.1674 +}