mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
8068626
: Add javac lint warning when the @Deprecated annotation is used where it is a no-op
Reviewed-by: mcimadamore, ksrini
This commit is contained in:
parent
4eedc33696
commit
37028f8abc
10 changed files with 107 additions and 4 deletions
|
@ -4282,6 +4282,9 @@ public class Attr extends JCTree.Visitor {
|
||||||
case TOPLEVEL:
|
case TOPLEVEL:
|
||||||
attribTopLevel(env);
|
attribTopLevel(env);
|
||||||
break;
|
break;
|
||||||
|
case PACKAGEDEF:
|
||||||
|
attribPackage(env.tree.pos(), ((JCPackageDecl) env.tree).packge);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
attribClass(env.tree.pos(), env.enclClass.sym);
|
attribClass(env.tree.pos(), env.enclClass.sym);
|
||||||
}
|
}
|
||||||
|
@ -4300,6 +4303,20 @@ public class Attr extends JCTree.Visitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void attribPackage(DiagnosticPosition pos, PackageSymbol p) {
|
||||||
|
try {
|
||||||
|
annotate.flush();
|
||||||
|
attribPackage(p);
|
||||||
|
} catch (CompletionFailure ex) {
|
||||||
|
chk.completionError(pos, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void attribPackage(PackageSymbol p) {
|
||||||
|
Env<AttrContext> env = typeEnvs.get(p);
|
||||||
|
chk.checkDeprecatedAnnotation(((JCPackageDecl) env.tree).pid.pos(), p);
|
||||||
|
}
|
||||||
|
|
||||||
public void attribModule(DiagnosticPosition pos, ModuleSymbol m) {
|
public void attribModule(DiagnosticPosition pos, ModuleSymbol m) {
|
||||||
try {
|
try {
|
||||||
annotate.flush();
|
annotate.flush();
|
||||||
|
|
|
@ -3197,6 +3197,21 @@ public class Check {
|
||||||
log.warning(LintCategory.DEP_ANN,
|
log.warning(LintCategory.DEP_ANN,
|
||||||
pos, "missing.deprecated.annotation");
|
pos, "missing.deprecated.annotation");
|
||||||
}
|
}
|
||||||
|
// Note: @Deprecated has no effect on local variables, parameters and package decls.
|
||||||
|
if (lint.isEnabled(LintCategory.DEPRECATION)) {
|
||||||
|
if (!syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) != null) {
|
||||||
|
switch (s.getKind()) {
|
||||||
|
case LOCAL_VARIABLE:
|
||||||
|
case PACKAGE:
|
||||||
|
case PARAMETER:
|
||||||
|
case RESOURCE_VARIABLE:
|
||||||
|
case EXCEPTION_PARAMETER:
|
||||||
|
log.warning(LintCategory.DEPRECATION, pos,
|
||||||
|
"deprecated.annotation.has.no.effect", Kinds.kindName(s));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Symbol s) {
|
void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Symbol s) {
|
||||||
|
|
|
@ -1654,6 +1654,10 @@ compiler.warn.varargs.unsafe.use.varargs.param=\
|
||||||
compiler.warn.missing.deprecated.annotation=\
|
compiler.warn.missing.deprecated.annotation=\
|
||||||
deprecated item is not annotated with @Deprecated
|
deprecated item is not annotated with @Deprecated
|
||||||
|
|
||||||
|
# 0: symbol kind
|
||||||
|
compiler.warn.deprecated.annotation.has.no.effect=\
|
||||||
|
@Deprecated annotation has no effect on this {0} declaration
|
||||||
|
|
||||||
compiler.warn.invalid.archive.file=\
|
compiler.warn.invalid.archive.file=\
|
||||||
Unexpected file on path: {0}
|
Unexpected file on path: {0}
|
||||||
|
|
||||||
|
|
|
@ -150,5 +150,4 @@ producing output like:
|
||||||
@see com.sun.javadoc.Doclet
|
@see com.sun.javadoc.Doclet
|
||||||
@see com.sun.javadoc.RootDoc
|
@see com.sun.javadoc.RootDoc
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
package com.sun.javadoc;
|
package com.sun.javadoc;
|
||||||
|
|
|
@ -32,5 +32,4 @@
|
||||||
* {@code javax.tools.DocumentationTool}
|
* {@code javax.tools.DocumentationTool}
|
||||||
* for replacement functionality.
|
* for replacement functionality.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
T6404756.java:10:28: compiler.warn.deprecated.annotation.has.no.effect: kindname.variable
|
||||||
T6404756.java:10:34: compiler.warn.has.been.deprecated: foo, Foo
|
T6404756.java:10:34: compiler.warn.has.been.deprecated: foo, Foo
|
||||||
- compiler.err.warnings.and.werror
|
- compiler.err.warnings.and.werror
|
||||||
1 error
|
1 error
|
||||||
1 warning
|
2 warnings
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package-info.java:10:9: compiler.warn.deprecated.annotation.has.no.effect: kindname.package
|
||||||
|
- compiler.err.warnings.and.werror
|
||||||
|
package-info.java:14:30: compiler.warn.deprecated.annotation.has.no.effect: kindname.variable
|
||||||
|
package-info.java:16:25: compiler.warn.deprecated.annotation.has.no.effect: kindname.variable
|
||||||
|
package-info.java:18:51: compiler.warn.deprecated.annotation.has.no.effect: kindname.variable
|
||||||
|
package-info.java:20:40: compiler.warn.deprecated.annotation.has.no.effect: kindname.variable
|
||||||
|
1 error
|
||||||
|
5 warnings
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* @test /nodynamiccopyright/
|
||||||
|
* @bug 8068626
|
||||||
|
* @summary Add javac lint warning when the Deprecated annotation is used where it is a no-op
|
||||||
|
*
|
||||||
|
* @compile/fail/ref=DeprecatedAnnotationTest.out -Werror -Xlint:deprecation -XDrawDiagnostics package-info.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
package p;
|
||||||
|
|
||||||
|
class DeprecatedAnnotationTest implements AutoCloseable {
|
||||||
|
|
||||||
|
void foo(@Deprecated int p) {
|
||||||
|
|
||||||
|
@Deprecated int l;
|
||||||
|
|
||||||
|
try (@Deprecated DeprecatedAnnotationTest r = new DeprecatedAnnotationTest()) {
|
||||||
|
// ...
|
||||||
|
} catch (@Deprecated Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
@SuppressWarnings("deprecation") // verify that we are able to suppress.
|
||||||
|
@Deprecated int x;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// options: -Xlint:deprecation
|
||||||
|
// key: compiler.warn.deprecated.annotation.has.no.effect
|
||||||
|
|
||||||
|
class DeprecatedAnnotationHasNoEffect {
|
||||||
|
void foo(@Deprecated int p) {}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ T6480588.java:18:35: compiler.warn.has.been.deprecated: DeprecatedClass, compile
|
||||||
T6480588.java:19:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
T6480588.java:19:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
||||||
T6480588.java:19:34: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
T6480588.java:19:34: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
||||||
T6480588.java:21:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
T6480588.java:21:9: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
||||||
|
T6480588.java:21:25: compiler.warn.deprecated.annotation.has.no.effect: kindname.variable
|
||||||
T6480588.java:21:35: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
T6480588.java:21:35: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
||||||
T6480588.java:30:5: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
T6480588.java:30:5: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
||||||
T6480588.java:29:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package
|
T6480588.java:29:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package
|
||||||
|
@ -15,4 +16,4 @@ T6480588.java:30:33: compiler.warn.has.been.deprecated: DeprecatedClass, compile
|
||||||
T6480588.java:33:25: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
T6480588.java:33:25: compiler.warn.has.been.deprecated: DeprecatedClass, compiler.misc.unnamed.package
|
||||||
T6480588.java:33:52: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package
|
T6480588.java:33:52: compiler.warn.has.been.deprecated: DeprecatedInterface, compiler.misc.unnamed.package
|
||||||
T6480588.java:32:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package
|
T6480588.java:32:6: compiler.warn.has.been.deprecated: DeprecatedAnnotation, compiler.misc.unnamed.package
|
||||||
17 warnings
|
18 warnings
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue