/** Finds a declaration with the given name and type that is in scope at the current location. */ @Nullable public static Symbol findIdent(String name, VisitorState state, KindSelector kind) { ClassType enclosingClass = ASTHelpers.getType(state.findEnclosing(ClassTree.class)); if (enclosingClass == null || enclosingClass.tsym == null) { return null; } Env<AttrContext> env = Enter.instance(state.context).getClassEnv(enclosingClass.tsym); MethodTree enclosingMethod = state.findEnclosing(MethodTree.class); if (enclosingMethod != null) { env = MemberEnter.instance(state.context).getMethodEnv((JCMethodDecl) enclosingMethod, env); } try { Method method = Resolve.class.getDeclaredMethod("findIdent", Env.class, Name.class, KindSelector.class); method.setAccessible(true); Symbol result = (Symbol) method.invoke(Resolve.instance(state.context), env, state.getName(name), kind); return result.exists() ? result : null; } catch (ReflectiveOperationException e) { throw new LinkageError(e.getMessage(), e); } }
memberEnter(env.toplevel, env.enclosing(TOPLEVEL)); todo.append(env); Env<AttrContext> baseEnv = baseEnv(tree, env); typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); for (JCExpression impl : tree.implementing) typeAnnotate(impl, baseEnv, sym, tree.pos()); annotate.flush(); ? attr.attribBase(tree.extending, baseEnv, true, false, true) : ((tree.mods.flags & Flags.ENUM) != 0) ? attr.attribBase(enumBase(tree.pos, c), baseEnv, true, false, false) : (c.fullname == names.java_lang_Object) ? Type.noType : syms.objectType; ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); if (all_interfaces == null) all_interfaces = new ListBuffer<Type>().appendList(interfaces); all_interfaces.append(modelMissingTypes(i, iface, true)); if (hasDeprecatedAnnotation(tree.mods.annotations)) c.flags_field |= DEPRECATED; annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); typeAnnotate(tp, baseEnv, sym, tree.pos());
public void visitImport(JCImport tree) { JCFieldAccess imp = (JCFieldAccess)tree.qualid; Name name = TreeInfo.name(imp); // Create a local environment pointing to this tree to disable // effects of other imports in Resolve.findGlobalType Env<AttrContext> localEnv = env.dup(tree); TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; if (name == names.asterisk) { // Import on demand. chk.checkCanonical(imp.selected); if (tree.staticImport) importStaticAll(tree.pos, p, env); else importAll(tree.pos, p, env); } else { // Named type import. if (tree.staticImport) { importNamedStatic(tree.pos(), p, name, localEnv); chk.checkCanonical(imp.selected); } else { TypeSymbol c = attribImportType(imp, localEnv).tsym; chk.checkCanonical(imp); importNamed(tree.pos(), c, env); } } }
memberEnter(env.toplevel, env.enclosing(JCTree.TOPLEVEL)); todo.append(env); Env<AttrContext> baseEnv = baseEnv(tree, env); ? attr.attribBase(tree.extending, baseEnv, true, false, true) : ((tree.mods.flags & Flags.ENUM) != 0 && !target.compilerBootstrap(c)) ? attr.attribBase(enumBase(tree.pos, c), baseEnv, true, false, false) : (c.fullname == names.java_lang_Object) if (hasDeprecatedAnnotation(tree.mods.annotations)) c.flags_field |= DEPRECATED; annotateLater(tree.mods.annotations, baseEnv, c); JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, typarams, argtypes, thrown, ctorFlags, based); try { while (halfcompleted.nonEmpty()) { finish(halfcompleted.next());
public void visitMethodDef(JCMethodDecl tree) { Scope enclScope = enter.enterScope(env); MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner); m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree); tree.sym = m; Env<AttrContext> localEnv = methodEnv(tree, env); // Compute the method type m.type = signature(tree.typarams, tree.params, tree.restype, tree.thrown, localEnv); // Set m.params ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>(); JCVariableDecl lastParam = null; for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl param = lastParam = l.head; assert param.sym != null; params.append(param.sym); } m.params = params.toList(); // mark the method varargs, if necessary if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) m.flags_field |= Flags.VARARGS; localEnv.info.scope.leave(); if (chk.checkUnique(tree.pos(), m, enclScope)) { enclScope.enter(m); } annotateLater(tree.mods.annotations, localEnv, m); if (tree.defaultValue != null) annotateDefaultValueLater(tree.defaultValue, localEnv, m); }
Type outertype = m.owner.owner.type; if (outertype.hasTag(TypeTag.CLASS)) { checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); } else { log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); v.flags_field |= HASINIT; if ((v.flags_field & FINAL) != 0 && needsLazyConstValue(tree.init)) { Env<AttrContext> initEnv = getInitEnv(tree, env); initEnv.info.enclVar = v; v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); enclScope.enter(v); annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); typeAnnotate(tree.vartype, env, v, tree.pos()); v.pos = tree.pos; } finally {
public void visitTopLevel(JCCompilationUnit tree) { if (tree.starImportScope.elems != null) { // we must have already processed this toplevel return; } // check that no class exists with same fully qualified name as // toplevel package if (checkClash && tree.pid != null) { Symbol p = tree.packge; while (p.owner != syms.rootPackage) { p.owner.complete(); // enter all class members of p if (syms.classes.get(p.getQualifiedName()) != null) { log.error(tree.pos, "pkg.clashes.with.class.of.same.name", p); } p = p.owner; } } // process package annotations annotateLater(tree.packageAnnotations, env, tree.packge); // Import-on-demand java.lang. importAll(tree.pos, reader.enterPackage(names.java_lang), env); // Process all import clauses. memberEnter(tree.defs, env); }
attr.attribType(tree.vartype, localEnv); if (TreeInfo.isReceiverParam(tree)) checkReceiver(tree, localEnv); v.flags_field |= HASINIT; if ((v.flags_field & FINAL) != 0 && needsLazyConstValue(tree.init)) { Env<AttrContext> initEnv = getInitEnv(tree, env); initEnv.info.enclVar = v; v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); enclScope.enter(v); annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); typeAnnotate(tree.vartype, env, v, tree.pos()); v.pos = tree.pos;
private JavacTrees(Context context) { context.put(JavacTrees.class, this); attr = Attr.instance(context); enter = Enter.instance(context); elements = JavacElements.instance(context); log = Log.instance(context); resolve = Resolve.instance(context); treeMaker = TreeMaker.instance(context); memberEnter = MemberEnter.instance(context); javacTaskImpl = context.get(JavacTaskImpl.class); }
env = memberEnter.getMethodEnv(method, env); JCTree body = copier.copy((JCTree)tree, (JCTree) path.getLeaf()); env = attribStatToTree(body, env, copier.leafCopy); env = memberEnter.getInitEnv(field, env); JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf()); env = attribExprToTree(expr, env, copier.leafCopy); return field != null ? memberEnter.getInitEnv(field, env) : env;
/** Enter members for a class. */ void finishClass(JCClassDecl tree, Env<AttrContext> env) { if ((tree.mods.flags & Flags.ENUM) != 0 && (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { addEnumMembers(tree, env); } memberEnter(tree.defs, env); }
Env<AttrContext> localEnv = memberEnter.methodEnv(tree, env); localEnv.info.lint = lint; Env<AttrContext> newEnv = memberEnter.methodEnv(tree, env); attribType(tree.recvparam, newEnv); chk.validate(tree.recvparam, newEnv); !TreeInfo.isSelfCall(body.stats.head)) { body.stats = body.stats. prepend(memberEnter.SuperCall(make.at(body.pos), List.<Type>nil(), List.<JCVariableDecl>nil(), memberEnter.typeAnnotate(tree.body, localEnv, m, null); annotate.flush();
public void visitVarDef(JCVariableDecl tree) { Env<AttrContext> localEnv = env; if ((tree.mods.flags & STATIC) != 0 || (env.info.scope.owner.flags() & INTERFACE) != 0) { localEnv = env.dup(tree, env.info.dup()); localEnv.info.staticLevel++; } attr.attribType(tree.vartype, localEnv); Scope enclScope = enter.enterScope(env); VarSymbol v = new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); tree.sym = v; if (tree.init != null) { v.flags_field |= HASINIT; if ((v.flags_field & FINAL) != 0 && tree.init.tag != JCTree.NEWCLASS) v.setLazyConstValue(initEnv(tree, env), log, attr, tree.init); } if (chk.checkUnique(tree.pos(), v, enclScope)) { chk.checkTransparentVar(tree.pos(), v, enclScope); enclScope.enter(v); } annotateLater(tree.mods.annotations, localEnv, v); v.pos = tree.pos; }
MethodSymbol init = new MethodSymbol(flags, names.init, initType, c); init.params = createDefaultConstructorParams(make, baseInit, init, argtypes, based); List<JCVariableDecl> params = make.Params(argtypes, init); List<JCStatement> stats = List.nil(); if (c.type != syms.objectType) { stats = stats.prepend(SuperCall(make, typarams, params, based));
public static MemberEnter instance(Context context) { MemberEnter instance = context.get(memberEnterKey); if (instance == null) instance = new MemberEnter(context); return instance; }
List<JCStatement> stats = List.nil(); if (c.type != syms.objectType) stats = stats.prepend(SuperCall(make, typarams, params, based)); if ((c.flags() & ENUM) != 0 && (types.supertype(c.type).tsym == syms.enumSym ||
memberEnter(env.toplevel, env.enclosing(TOPLEVEL)); todo.append(env); Env<AttrContext> baseEnv = baseEnv(tree, env); typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); for (JCExpression impl : tree.implementing) typeAnnotate(impl, baseEnv, sym, tree.pos()); annotate.flush(); ? attr.attribBase(tree.extending, baseEnv, true, false, true) : ((tree.mods.flags & Flags.ENUM) != 0) ? attr.attribBase(enumBase(tree.pos, c), baseEnv, true, false, false) : (c.fullname == names.java_lang_Object) ? Type.noType : syms.objectType; ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); if (all_interfaces == null) all_interfaces = new ListBuffer<Type>().appendList(interfaces); all_interfaces.append(modelMissingTypes(i, iface, true)); if (hasDeprecatedAnnotation(tree.mods.annotations)) c.flags_field |= DEPRECATED; annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); typeAnnotate(tp, baseEnv, sym, tree.pos());
public void visitImport(JCImport tree) { JCFieldAccess imp = (JCFieldAccess)tree.qualid; Name name = TreeInfo.name(imp); // Create a local environment pointing to this tree to disable // effects of other imports in Resolve.findGlobalType Env<AttrContext> localEnv = env.dup(tree); TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; if (name == names.asterisk) { // Import on demand. chk.checkCanonical(imp.selected); if (tree.staticImport) importStaticAll(tree.pos, p, env); else importAll(tree.pos, p, env); } else { // Named type import. if (tree.staticImport) { importNamedStatic(tree.pos(), p, name, localEnv); chk.checkCanonical(imp.selected); } else { TypeSymbol c = attribImportType(imp, localEnv).tsym; chk.checkCanonical(imp); importNamed(tree.pos(), c, env); } } }
memberEnter(env.toplevel, env.enclosing(JCTree.TOPLEVEL)); todo.append(env); Env<AttrContext> baseEnv = baseEnv(tree, env); ? attr.attribBase(tree.extending, baseEnv, true, false, true) : ((tree.mods.flags & Flags.ENUM) != 0 && !target.compilerBootstrap(c)) ? attr.attribBase(enumBase(tree.pos, c), baseEnv, true, false, false) : (c.fullname == names.java_lang_Object) if (hasDeprecatedAnnotation(tree.mods.annotations)) c.flags_field |= DEPRECATED; annotateLater(tree.mods.annotations, baseEnv, c); JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, typarams, argtypes, thrown, ctorFlags, based); try { while (halfcompleted.nonEmpty()) { finish(halfcompleted.next());