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

Print this page

        

*** 242,254 **** --- 242,258 ---- ((v.flags() & HASINIT) != 0 || !((base == null || (base.getTag() == JCTree.IDENT && TreeInfo.name(base) == names._this)) && isAssignableAsBlankFinal(v, env)))) { + if (types.asSuper(v.type, syms.autoCloseableType.tsym) != null) { //ARM resource + log.error(pos, "arm.resource.may.not.be.assigned", v); + } else { log.error(pos, "cant.assign.val.to.final.var", v); } } + } /** Does tree represent a static reference to an identifier? * It is assumed that tree is either a SELECT or an IDENT. * We have to weed out selects from non-type names here. * @param tree The candidate tree.
*** 979,996 **** attribStat(tree.body, env); result = null; } public void visitTry(JCTry tree) { // Attribute body ! attribStat(tree.body, env.dup(tree, env.info.dup())); // Attribute catch clauses for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { JCCatch c = l.head; Env<AttrContext> catchEnv = ! env.dup(c, env.info.dup(env.info.scope.dup())); Type ctype = attribStat(c.param, catchEnv); if (TreeInfo.isMultiCatch(c)) { //check that multi-catch parameter is marked as final if ((c.param.sym.flags() & FINAL) == 0) { log.error(c.param.pos(), "multicatch.param.must.be.final", c.param.sym); --- 983,1019 ---- attribStat(tree.body, env); result = null; } public void visitTry(JCTry tree) { + // Create a new local environment with a local scope. + Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup())); + // Attribute resource declarations + ListBuffer<VarSymbol> resourceVars = ListBuffer.lb(); + for (JCTree resource : tree.resources) { + attribExpr(resource, localEnv); + chk.checkArmResource(resource); + if (resource.getTag() == JCTree.VARDEF) { + VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); + var.setData(ElementKind.RESOURCE_VARIABLE); + resourceVars.append(var); + } + } // Attribute body ! attribStat(tree.body, localEnv.dup(tree, localEnv.info.dup())); ! ! //remove arm resource vars from local scope - such variables cannot be ! //accessed from catch/finally clauses ! for (VarSymbol resourceVar : resourceVars) { ! localEnv.info.scope.remove(resourceVar); ! } // Attribute catch clauses for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { JCCatch c = l.head; Env<AttrContext> catchEnv = ! localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); Type ctype = attribStat(c.param, catchEnv); if (TreeInfo.isMultiCatch(c)) { //check that multi-catch parameter is marked as final if ((c.param.sym.flags() & FINAL) == 0) { log.error(c.param.pos(), "multicatch.param.must.be.final", c.param.sym);
*** 1006,1016 **** attribStat(c.body, catchEnv); catchEnv.info.scope.leave(); } // Attribute finalizer ! if (tree.finalizer != null) attribStat(tree.finalizer, env); result = null; } public void visitConditional(JCConditional tree) { attribExpr(tree.cond, env, syms.booleanType); --- 1029,1041 ---- attribStat(c.body, catchEnv); catchEnv.info.scope.leave(); } // Attribute finalizer ! if (tree.finalizer != null) attribStat(tree.finalizer, localEnv); ! ! localEnv.info.scope.leave(); result = null; } public void visitConditional(JCConditional tree) { attribExpr(tree.cond, env, syms.booleanType);