6970016: Clean up ARM/try-with-resources implementation
Changed Xlint option name from -Xlint:arm to -Xlint:try Reviewed-by: jjg
This commit is contained in:
parent
bb03754fd1
commit
64789c2491
@ -212,9 +212,9 @@ public class Lint
|
||||
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);
|
||||
|
@ -252,7 +252,7 @@ public class Attr extends JCTree.Visitor {
|
||||
(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 @@ public class Attr extends JCTree.Visitor {
|
||||
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 @@ public class Attr extends JCTree.Visitor {
|
||||
((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
|
||||
|
@ -1037,10 +1037,10 @@ public class Flow extends TreeScanner {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1712,7 +1712,7 @@ public class JavacParser implements Parser {
|
||||
S.nextToken();
|
||||
List<JCTree> resources = List.<JCTree>nil();
|
||||
if (S.token() == LPAREN) {
|
||||
checkAutomaticResourceManagement();
|
||||
checkTryWithResources();
|
||||
S.nextToken();
|
||||
resources = resources();
|
||||
accept(RPAREN);
|
||||
@ -2970,9 +2970,9 @@ public class JavacParser implements Parser {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,6 @@ compiler.err.anon.class.impl.intf.no.typeargs=\
|
||||
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.except.never.thrown.in.try=\
|
||||
|
||||
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.unclosed.type.files=\
|
||||
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.misc.assignment.to.extends-bound=\
|
||||
# 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 @@ compiler.err.unsupported.exotic.id=\
|
||||
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\
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -2,15 +2,15 @@
|
||||
* @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
|
||||
* @summary Check that -Xlint:twr warnings are generated as expected
|
||||
* @compile/ref=TwrLint.out -Xlint:try,deprecation -XDrawDiagnostics TwrLint.java
|
||||
*/
|
||||
|
||||
class ArmLint implements AutoCloseable {
|
||||
class TwrLint implements AutoCloseable {
|
||||
private static void test1() {
|
||||
try(ArmLint r1 = new ArmLint();
|
||||
ArmLint r2 = new ArmLint();
|
||||
ArmLint r3 = new ArmLint()) {
|
||||
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
|
||||
@ -18,11 +18,11 @@ class ArmLint implements AutoCloseable {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("arm")
|
||||
@SuppressWarnings("try")
|
||||
private static void test2() {
|
||||
try(@SuppressWarnings("deprecation") AutoCloseable r4 =
|
||||
new DeprecatedAutoCloseable()) {
|
||||
// r4 not referenced
|
||||
// r4 not referenced - but no warning is generated because of @SuppressWarnings
|
||||
} catch(Exception e) {
|
||||
;
|
||||
}
|
3
langtools/test/tools/javac/TryWithResources/TwrLint.out
Normal file
3
langtools/test/tools/javac/TryWithResources/TwrLint.out
Normal file
@ -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
|
@ -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
|
||||
|
@ -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.*;
|
||||
|
||||
|
@ -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.*;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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.*;
|
||||
|
||||
|
@ -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.*;
|
||||
|
Loading…
Reference in New Issue
Block a user