6970016: Clean up ARM/try-with-resources implementation
authormcimadamore
Fri, 12 Nov 2010 12:34:18 +0000
changeset 7211 163fe60f63de
parent 7210 8dd5f907461e
child 7212 a3d2fea48d58
6970016: Clean up ARM/try-with-resources implementation Summary: changed Xlint option name from -Xlint:arm to -Xlint:try Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/code/Lint.java
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java
langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/test/tools/javac/TryWithResources/ArmLint.java
langtools/test/tools/javac/TryWithResources/ArmLint.out
langtools/test/tools/javac/TryWithResources/ImplicitFinal.out
langtools/test/tools/javac/TryWithResources/TwrLint.java
langtools/test/tools/javac/TryWithResources/TwrLint.out
langtools/test/tools/javac/TryWithResources/TwrOnNonResource.out
langtools/test/tools/javac/diags/examples/ResourceClosed.java
langtools/test/tools/javac/diags/examples/ResourceMayNotBeAssigned.java
langtools/test/tools/javac/diags/examples/ResourceNotApplicableToType.java
langtools/test/tools/javac/diags/examples/ResourceNotReferenced.java
langtools/test/tools/javac/diags/examples/TryResourceNotSupported.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Lint.java	Fri Nov 12 12:34:18 2010 +0000
@@ -212,9 +212,9 @@
         VARARGS("varargs"),
 
         /**
-         * Warn about arm resources
+         * Warn about issues relating to use of try blocks (i.e. try-with-resources)
          */
-        ARM("arm");
+        TRY("try");
 
         LintCategory(String option) {
             this(option, false);
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Nov 12 12:34:18 2010 +0000
@@ -252,7 +252,7 @@
                (base.getTag() == JCTree.IDENT && TreeInfo.name(base) == names._this)) &&
                isAssignableAsBlankFinal(v, env)))) {
             if (v.isResourceVariable()) { //TWR resource
-                log.error(pos, "twr.resource.may.not.be.assigned", v);
+                log.error(pos, "try.resource.may.not.be.assigned", v);
             } else {
                 log.error(pos, "cant.assign.val.to.final.var", v);
             }
@@ -1045,11 +1045,11 @@
         for (JCTree resource : tree.resources) {
             if (resource.getTag() == JCTree.VARDEF) {
                 attribStat(resource, tryEnv);
-                chk.checkType(resource, resource.type, syms.autoCloseableType, "twr.not.applicable.to.type");
+                chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type");
                 VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource);
                 var.setData(ElementKind.RESOURCE_VARIABLE);
             } else {
-                attribExpr(resource, tryEnv, syms.autoCloseableType, "twr.not.applicable.to.type");
+                attribExpr(resource, tryEnv, syms.autoCloseableType, "try.not.applicable.to.type");
             }
         }
         // Attribute body
@@ -2258,8 +2258,8 @@
                 ((VarSymbol)sitesym).isResourceVariable() &&
                 sym.kind == MTH &&
                 sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) &&
-                env.info.lint.isEnabled(Lint.LintCategory.ARM)) {
-            log.warning(tree, "twr.explicit.close.call");
+                env.info.lint.isEnabled(Lint.LintCategory.TRY)) {
+            log.warning(Lint.LintCategory.TRY, tree, "try.explicit.close.call");
         }
 
         // Disallow selecting a type from an expression
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java	Fri Nov 12 12:34:18 2010 +0000
@@ -1037,10 +1037,10 @@
         int nextadrCatch = nextadr;
 
         if (!unrefdResources.isEmpty() &&
-                lint.isEnabled(Lint.LintCategory.ARM)) {
+                lint.isEnabled(Lint.LintCategory.TRY)) {
             for (Map.Entry<VarSymbol, JCVariableDecl> e : unrefdResources.entrySet()) {
-                log.warning(e.getValue().pos(),
-                            "automatic.resource.not.referenced", e.getKey());
+                log.warning(Lint.LintCategory.TRY, e.getValue().pos(),
+                            "try.resource.not.referenced", e.getKey());
             }
         }
 
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Nov 12 12:34:18 2010 +0000
@@ -1712,7 +1712,7 @@
             S.nextToken();
             List<JCTree> resources = List.<JCTree>nil();
             if (S.token() == LPAREN) {
-                checkAutomaticResourceManagement();
+                checkTryWithResources();
                 S.nextToken();
                 resources = resources();
                 accept(RPAREN);
@@ -2970,9 +2970,9 @@
             allowMulticatch = true;
         }
     }
-    void checkAutomaticResourceManagement() {
+    void checkTryWithResources() {
         if (!allowTWR) {
-            error(S.pos(), "automatic.resource.management.not.supported.in.source", source.name);
+            error(S.pos(), "try.with.resources.not.supported.in.source", source.name);
             allowTWR = true;
         }
     }
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Nov 12 12:34:18 2010 +0000
@@ -63,8 +63,6 @@
     anonymous class implements interface; cannot have type arguments
 compiler.err.anon.class.impl.intf.no.qual.for.new=\
     anonymous class implements interface; cannot have qualifier for new
-compiler.misc.twr.not.applicable.to.type=\
-    automatic resource management not applicable to variable type
 compiler.err.array.and.varargs=\
     cannot declare both {0} and {1} in {2}
 compiler.err.array.dimension.missing=\
@@ -183,8 +181,8 @@
 
 compiler.err.final.parameter.may.not.be.assigned=\
     final parameter {0} may not be assigned
-compiler.err.twr.resource.may.not.be.assigned=\
-    automatic resource {0} may not be assigned
+compiler.err.try.resource.may.not.be.assigned=\
+    auto-closeable resource {0} may not be assigned
 compiler.err.multicatch.parameter.may.not.be.assigned=\
     multi-catch parameter {0} may not be assigned
 compiler.err.finally.without.try=\
@@ -823,10 +821,10 @@
 compiler.warn.proc.unmatched.processor.options=\
     The following options were not recognized by any processor: ''{0}''
 
-compiler.warn.twr.explicit.close.call=\
-    [arm] explicit call to close() on an automatic resource
-compiler.warn.automatic.resource.not.referenced=\
-    [arm] automatic resource {0} is never referenced in body of corresponding try statement
+compiler.warn.try.explicit.close.call=\
+    explicit call to close() on an auto-closeable resource
+compiler.warn.try.resource.not.referenced=\
+    auto-closeable resource {0} is never referenced in body of corresponding try statement
 compiler.warn.unchecked.assign=\
     unchecked assignment: {0} to {1}
 compiler.warn.unchecked.assign.to.var=\
@@ -1050,6 +1048,9 @@
 # compiler.err.no.elem.type=\
 #     \[\*\] cannot have a type
 
+compiler.misc.try.not.applicable.to.type=\
+    try-with-resources not applicable to variable type
+
 #####
 
 compiler.err.type.found.req=\
@@ -1272,9 +1273,9 @@
     exotic identifiers #"___" are not supported in -source {0}\n\
 (use -source 7 or higher to enable exotic identifiers)
 
-compiler.err.automatic.resource.management.not.supported.in.source=\
-    automatic resource management is not supported in -source {0}\n\
-(use -source 7 or higher to enable automatic resource management)
+compiler.err.try.with.resources.not.supported.in.source=\
+    try-with-resources is not supported in -source {0}\n\
+(use -source 7 or higher to enable try-with-resources)
 
 compiler.warn.enum.as.identifier=\
     as of release 5, ''enum'' is a keyword, and may not be used as an identifier\n\
--- a/langtools/test/tools/javac/TryWithResources/ArmLint.java	Fri Nov 12 12:33:52 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * @test  /nodynamiccopyright/
- * @bug 6911256 6964740 6965277 6967065
- * @author Joseph D. Darcy
- * @summary Check that -Xlint:arm warnings are generated as expected
- * @compile/ref=ArmLint.out -Xlint:arm,deprecation -XDrawDiagnostics ArmLint.java
- */
-
-class ArmLint implements AutoCloseable {
-    private static void test1() {
-        try(ArmLint r1 = new ArmLint();
-            ArmLint r2 = new ArmLint();
-            ArmLint r3 = new ArmLint()) {
-            r1.close();   // The resource's close
-            r2.close(42); // *Not* the resource's close
-            // r3 not referenced
-        }
-
-    }
-
-    @SuppressWarnings("arm")
-    private static void test2() {
-        try(@SuppressWarnings("deprecation") AutoCloseable r4 =
-            new DeprecatedAutoCloseable()) {
-            // r4 not referenced
-        } catch(Exception e) {
-            ;
-        }
-    }
-
-    /**
-     * The AutoCloseable method of a resource.
-     */
-    @Override
-    public void close () {
-        return;
-    }
-
-    /**
-     * <em>Not</em> the AutoCloseable method of a resource.
-     */
-    public void close (int arg) {
-        return;
-    }
-}
-
-@Deprecated
-class DeprecatedAutoCloseable implements AutoCloseable {
-    public DeprecatedAutoCloseable(){super();}
-
-    @Override
-    public void close () {
-        return;
-    }
-}
--- a/langtools/test/tools/javac/TryWithResources/ArmLint.out	Fri Nov 12 12:33:52 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-ArmLint.java:14:15: compiler.warn.twr.explicit.close.call
-ArmLint.java:13:13: compiler.warn.automatic.resource.not.referenced: r3
-2 warnings
--- a/langtools/test/tools/javac/TryWithResources/ImplicitFinal.out	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/test/tools/javac/TryWithResources/ImplicitFinal.out	Fri Nov 12 12:34:18 2010 +0000
@@ -1,2 +1,2 @@
-ImplicitFinal.java:14:13: compiler.err.twr.resource.may.not.be.assigned: r
+ImplicitFinal.java:14:13: compiler.err.try.resource.may.not.be.assigned: r
 1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/TryWithResources/TwrLint.java	Fri Nov 12 12:34:18 2010 +0000
@@ -0,0 +1,55 @@
+/*
+ * @test  /nodynamiccopyright/
+ * @bug 6911256 6964740 6965277 6967065
+ * @author Joseph D. Darcy
+ * @summary Check that -Xlint:twr warnings are generated as expected
+ * @compile/ref=TwrLint.out -Xlint:try,deprecation -XDrawDiagnostics TwrLint.java
+ */
+
+class TwrLint implements AutoCloseable {
+    private static void test1() {
+        try(TwrLint r1 = new TwrLint();
+            TwrLint r2 = new TwrLint();
+            TwrLint r3 = new TwrLint()) {
+            r1.close();   // The resource's close
+            r2.close(42); // *Not* the resource's close
+            // r3 not referenced
+        }
+
+    }
+
+    @SuppressWarnings("try")
+    private static void test2() {
+        try(@SuppressWarnings("deprecation") AutoCloseable r4 =
+            new DeprecatedAutoCloseable()) {
+            // r4 not referenced - but no warning is generated because of @SuppressWarnings
+        } catch(Exception e) {
+            ;
+        }
+    }
+
+    /**
+     * The AutoCloseable method of a resource.
+     */
+    @Override
+    public void close () {
+        return;
+    }
+
+    /**
+     * <em>Not</em> the AutoCloseable method of a resource.
+     */
+    public void close (int arg) {
+        return;
+    }
+}
+
+@Deprecated
+class DeprecatedAutoCloseable implements AutoCloseable {
+    public DeprecatedAutoCloseable(){super();}
+
+    @Override
+    public void close () {
+        return;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/TryWithResources/TwrLint.out	Fri Nov 12 12:34:18 2010 +0000
@@ -0,0 +1,3 @@
+TwrLint.java:14:15: compiler.warn.try.explicit.close.call
+TwrLint.java:13:13: compiler.warn.try.resource.not.referenced: r3
+2 warnings
--- a/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.out	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.out	Fri Nov 12 12:34:18 2010 +0000
@@ -1,7 +1,7 @@
-TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
-TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
-TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
-TwrOnNonResource.java:24:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
-TwrOnNonResource.java:27:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
-TwrOnNonResource.java:30:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
+TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
+TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
+TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
+TwrOnNonResource.java:24:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
+TwrOnNonResource.java:27:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
+TwrOnNonResource.java:30:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
 6 errors
--- a/langtools/test/tools/javac/diags/examples/ResourceClosed.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/test/tools/javac/diags/examples/ResourceClosed.java	Fri Nov 12 12:34:18 2010 +0000
@@ -21,8 +21,8 @@
  * questions.
  */
 
-// key: compiler.warn.twr.explicit.close.call
-// options: -Xlint:arm
+// key: compiler.warn.try.explicit.close.call
+// options: -Xlint:try
 
 import java.io.*;
 
--- a/langtools/test/tools/javac/diags/examples/ResourceMayNotBeAssigned.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/test/tools/javac/diags/examples/ResourceMayNotBeAssigned.java	Fri Nov 12 12:34:18 2010 +0000
@@ -21,7 +21,7 @@
  * questions.
  */
 
-// key: compiler.err.twr.resource.may.not.be.assigned
+// key: compiler.err.try.resource.may.not.be.assigned
 
 import java.io.*;
 
--- a/langtools/test/tools/javac/diags/examples/ResourceNotApplicableToType.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/test/tools/javac/diags/examples/ResourceNotApplicableToType.java	Fri Nov 12 12:34:18 2010 +0000
@@ -21,7 +21,7 @@
  * questions.
  */
 
-// key: compiler.misc.twr.not.applicable.to.type
+// key: compiler.misc.try.not.applicable.to.type
 // key: compiler.err.prob.found.req
 
 class ResourceNotApplicableToType {
--- a/langtools/test/tools/javac/diags/examples/ResourceNotReferenced.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/test/tools/javac/diags/examples/ResourceNotReferenced.java	Fri Nov 12 12:34:18 2010 +0000
@@ -21,8 +21,8 @@
  * questions.
  */
 
-// key: compiler.warn.automatic.resource.not.referenced
-// options: -Xlint:arm
+// key: compiler.warn.try.resource.not.referenced
+// options: -Xlint:try
 
 import java.io.*;
 
--- a/langtools/test/tools/javac/diags/examples/TryResourceNotSupported.java	Fri Nov 12 12:33:52 2010 +0000
+++ b/langtools/test/tools/javac/diags/examples/TryResourceNotSupported.java	Fri Nov 12 12:34:18 2010 +0000
@@ -21,7 +21,7 @@
  * questions.
  */
 
-// key: compiler.err.automatic.resource.management.not.supported.in.source
+// key: compiler.err.try.with.resources.not.supported.in.source
 // options: -source 1.6
 
 import java.io.*;