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

changeset 905
e9b8fbb30f5a
parent 880
0c24826853b2
child 906
c15d788cb381
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Wed Mar 02 21:13:55 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Thu Mar 03 09:43:24 2011 +0000
     1.3 @@ -272,7 +272,7 @@
     1.4  
     1.5      /** The list of unreferenced automatic resources.
     1.6       */
     1.7 -    Map<VarSymbol, JCVariableDecl> unrefdResources;
     1.8 +    Scope unrefdResources;
     1.9  
    1.10      /** Set when processing a loop body the second time for DU analysis. */
    1.11      boolean loopPassTwo = false;
    1.12 @@ -992,7 +992,6 @@
    1.13      public void visitTry(JCTry tree) {
    1.14          List<Type> caughtPrev = caught;
    1.15          List<Type> thrownPrev = thrown;
    1.16 -        Map<VarSymbol, JCVariableDecl> unrefdResourcesPrev = unrefdResources;
    1.17          thrown = List.nil();
    1.18          for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
    1.19              List<JCExpression> subClauses = TreeInfo.isMultiCatch(l.head) ?
    1.20 @@ -1002,17 +1001,18 @@
    1.21                  caught = chk.incl(ct.type, caught);
    1.22              }
    1.23          }
    1.24 +        ListBuffer<JCVariableDecl> resourceVarDecls = ListBuffer.lb();
    1.25          Bits uninitsTryPrev = uninitsTry;
    1.26          ListBuffer<PendingExit> prevPendingExits = pendingExits;
    1.27          pendingExits = new ListBuffer<PendingExit>();
    1.28          Bits initsTry = inits.dup();
    1.29          uninitsTry = uninits.dup();
    1.30 -        unrefdResources = new LinkedHashMap<VarSymbol, JCVariableDecl>();
    1.31          for (JCTree resource : tree.resources) {
    1.32              if (resource instanceof JCVariableDecl) {
    1.33                  JCVariableDecl vdecl = (JCVariableDecl) resource;
    1.34                  visitVarDef(vdecl);
    1.35 -                unrefdResources.put(vdecl.sym, vdecl);
    1.36 +                unrefdResources.enter(vdecl.sym);
    1.37 +                resourceVarDecls.append(vdecl);
    1.38              } else if (resource instanceof JCExpression) {
    1.39                  scanExpr((JCExpression) resource);
    1.40              } else {
    1.41 @@ -1049,11 +1049,14 @@
    1.42          Bits uninitsEnd = uninits;
    1.43          int nextadrCatch = nextadr;
    1.44  
    1.45 -        if (!unrefdResources.isEmpty() &&
    1.46 +        if (!resourceVarDecls.isEmpty() &&
    1.47                  lint.isEnabled(Lint.LintCategory.TRY)) {
    1.48 -            for (Map.Entry<VarSymbol, JCVariableDecl> e : unrefdResources.entrySet()) {
    1.49 -                log.warning(Lint.LintCategory.TRY, e.getValue().pos(),
    1.50 -                            "try.resource.not.referenced", e.getKey());
    1.51 +            for (JCVariableDecl resVar : resourceVarDecls) {
    1.52 +                if (unrefdResources.includes(resVar.sym)) {
    1.53 +                    log.warning(Lint.LintCategory.TRY, resVar.pos(),
    1.54 +                                "try.resource.not.referenced", resVar.sym);
    1.55 +                    unrefdResources.remove(resVar.sym);
    1.56 +                }
    1.57              }
    1.58          }
    1.59  
    1.60 @@ -1143,7 +1146,6 @@
    1.61              while (exits.nonEmpty()) pendingExits.append(exits.next());
    1.62          }
    1.63          uninitsTry.andSet(uninitsTryPrev).andSet(uninits);
    1.64 -        unrefdResources = unrefdResourcesPrev;
    1.65      }
    1.66  
    1.67      public void visitConditional(JCConditional tree) {
    1.68 @@ -1369,9 +1371,7 @@
    1.69      }
    1.70  
    1.71      void referenced(Symbol sym) {
    1.72 -        if (unrefdResources != null && unrefdResources.containsKey(sym)) {
    1.73 -            unrefdResources.remove(sym);
    1.74 -        }
    1.75 +        unrefdResources.remove(sym);
    1.76      }
    1.77  
    1.78      public void visitTypeCast(JCTypeCast tree) {
    1.79 @@ -1430,6 +1430,7 @@
    1.80              alive = true;
    1.81              this.thrown = this.caught = null;
    1.82              this.classDef = null;
    1.83 +            unrefdResources = new Scope(env.enclClass.sym);
    1.84              scan(tree);
    1.85          } finally {
    1.86              // note that recursive invocations of this method fail hard
    1.87 @@ -1444,6 +1445,7 @@
    1.88              this.make = null;
    1.89              this.thrown = this.caught = null;
    1.90              this.classDef = null;
    1.91 +            unrefdResources = null;
    1.92          }
    1.93      }
    1.94  }

mercurial