# HG changeset patch # User jlahoda # Date 1416841355 -3600 # Node ID 22b4bfc4e22f2300a1f2a0540da99935ba933058 # Parent 746c658e8d358bda041799ff6f6d8bd614ec6273 8032211: Don't issue deprecation warnings on import statements 6598104: javac should not warn about imports of deprecated classes Summary: Suppressing the deprecation warnings when importing a deprecated element (deprecations in import qualifier will be produced). Reviewed-by: darcy, jjg, mcimadamore diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java Mon Nov 24 16:02:35 2014 +0100 @@ -80,6 +80,16 @@ return l; } + /** + * Returns a new Lint that has the given LintCategory suppressed. + */ + public Lint suppress(LintCategory lc) { + Lint l = new Lint(this); + l.values.remove(lc); + l.suppressedValues.add(lc); + return l; + } + private final AugmentVisitor augmentor; private final EnumSet values; diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java Mon Nov 24 16:02:35 2014 +0100 @@ -152,6 +152,9 @@ public boolean allowStringsInSwitch() { return compareTo(JDK1_7) >= 0; } + public boolean allowDeprecationOnImport() { + return compareTo(JDK1_9) < 0; + } public boolean allowSimplifiedVarargs() { return compareTo(JDK1_7) >= 0; } diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java Mon Nov 24 16:02:35 2014 +0100 @@ -33,6 +33,7 @@ import javax.tools.JavaFileObject; import com.sun.tools.javac.code.*; +import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Scope.ImportFilter; import com.sun.tools.javac.code.Scope.NamedImportScope; import com.sun.tools.javac.code.Scope.StarImportScope; @@ -123,12 +124,18 @@ typeEnvs = TypeEnvs.instance(context); dependencies = Dependencies.instance(context); allowTypeAnnos = source.allowTypeAnnotations(); + allowDeprecationOnImport = source.allowDeprecationOnImport(); } /** Switch: support type annotations. */ boolean allowTypeAnnos; + /** + * Switch: should deprecation warnings be issued on import + */ + boolean allowDeprecationOnImport; + /** A queue for classes whose members still need to be entered into the * symbol table. */ @@ -771,6 +778,8 @@ Type attribImportType(JCTree tree, Env env) { Assert.check(completionEnabled); + Lint prevLint = chk.setLint(allowDeprecationOnImport ? + lint : lint.suppress(LintCategory.DEPRECATION)); try { // To prevent deep recursion, suppress completion of some // types. @@ -778,6 +787,7 @@ return attr.attribType(tree, env); } finally { completionEnabled = true; + chk.setLint(prevLint); } } diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/6594914/ImplicitCompilation.java --- a/langtools/test/tools/javac/warnings/6594914/ImplicitCompilation.java Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/test/tools/javac/warnings/6594914/ImplicitCompilation.java Mon Nov 24 16:02:35 2014 +0100 @@ -3,9 +3,9 @@ * @bug 8020586 * @summary Warnings in the imports section should be attributed to the correct source file * @clean Auxiliary ImplicitCompilation - * @compile/ref=ImplicitCompilation.out -XDrawDiagnostics -Xlint:deprecation -sourcepath . ImplicitCompilation.java + * @compile/ref=ImplicitCompilation.out -source 8 -XDrawDiagnostics -Xlint:deprecation,-options -sourcepath . ImplicitCompilation.java * @clean Auxiliary ImplicitCompilation - * @compile/ref=ExplicitCompilation.out -XDrawDiagnostics -Xlint:deprecation ImplicitCompilation.java Auxiliary.java + * @compile/ref=ExplicitCompilation.out -source 8 -XDrawDiagnostics -Xlint:deprecation,-options ImplicitCompilation.java Auxiliary.java */ public class ImplicitCompilation { diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/Deprecation.java --- a/langtools/test/tools/javac/warnings/Deprecation.java Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/test/tools/javac/warnings/Deprecation.java Mon Nov 24 16:02:35 2014 +0100 @@ -1,11 +1,13 @@ /** * @test /nodynamiccopyright/ - * @bug 4986256 - * @compile/ref=Deprecation.noLint.out -XDrawDiagnostics Deprecation.java - * @compile/ref=Deprecation.lintDeprecation.out -Xlint:deprecation -XDrawDiagnostics Deprecation.java - * @compile/ref=Deprecation.lintAll.out -Xlint:all,-path -XDrawDiagnostics Deprecation.java + * @bug 4986256 6598104 8032211 + * @compile/ref=Deprecation.noLint.out -XDrawDiagnostics Deprecation.java + * @compile/ref=Deprecation.lintDeprecation.out -Xlint:deprecation -XDrawDiagnostics Deprecation.java + * @compile/ref=Deprecation.lintDeprecation8.out -Xlint:deprecation,-options -source 8 -XDrawDiagnostics Deprecation.java */ +import java.io.StringBufferInputStream; + @Deprecated class Deprecation { diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/Deprecation.lintAll.out --- a/langtools/test/tools/javac/warnings/Deprecation.lintAll.out Fri Nov 21 16:36:39 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -Deprecation.java:18:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package -Deprecation.java:55:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package -2 warnings diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/Deprecation.lintDeprecation.out --- a/langtools/test/tools/javac/warnings/Deprecation.lintDeprecation.out Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/test/tools/javac/warnings/Deprecation.lintDeprecation.out Mon Nov 24 16:02:35 2014 +0100 @@ -1,3 +1,3 @@ -Deprecation.java:18:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package -Deprecation.java:55:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package +Deprecation.java:20:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package +Deprecation.java:57:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package 2 warnings diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/Deprecation.lintDeprecation8.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/Deprecation.lintDeprecation8.out Mon Nov 24 16:02:35 2014 +0100 @@ -0,0 +1,4 @@ +Deprecation.java:9:15: compiler.warn.has.been.deprecated: java.io.StringBufferInputStream, java.io +Deprecation.java:20:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package +Deprecation.java:57:24: compiler.warn.has.been.deprecated: Deprecation, compiler.misc.unnamed.package +3 warnings diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/NestedDeprecation/NestedDeprecation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/NestedDeprecation/NestedDeprecation.java Mon Nov 24 16:02:35 2014 +0100 @@ -0,0 +1,29 @@ +/** + * @test /nodynamiccopyright/ + * @bug 6598104 8032211 + * @build p.Dep1 p.Dep2 + * @compile/ref=NestedDeprecation.out -Xlint:deprecation -XDrawDiagnostics NestedDeprecation.java + */ + +package p; + +import p.Dep1.A; +import static p.Dep1.B; +import static p.Dep1.method; +import static p.Dep1.field; +import p.Dep2.C; +import p.Dep2.D; + +class NestedDeprecation { + Dep1 f1; + A f2; + Dep2 f3; + B f4; + C f5; + D f6; + + static { + method(); + String f = field; + } +} diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/NestedDeprecation/NestedDeprecation.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/NestedDeprecation/NestedDeprecation.out Mon Nov 24 16:02:35 2014 +0100 @@ -0,0 +1,9 @@ +NestedDeprecation.java:14:9: compiler.warn.has.been.deprecated: p.Dep2, p +NestedDeprecation.java:15:9: compiler.warn.has.been.deprecated: p.Dep2, p +NestedDeprecation.java:19:5: compiler.warn.has.been.deprecated: p.Dep1.A, p.Dep1 +NestedDeprecation.java:20:5: compiler.warn.has.been.deprecated: p.Dep2, p +NestedDeprecation.java:21:5: compiler.warn.has.been.deprecated: p.Dep1.B, p.Dep1 +NestedDeprecation.java:23:5: compiler.warn.has.been.deprecated: p.Dep2.D, p.Dep2 +NestedDeprecation.java:26:9: compiler.warn.has.been.deprecated: method(), p.Dep1 +NestedDeprecation.java:27:20: compiler.warn.has.been.deprecated: field, p.Dep1 +8 warnings diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/NestedDeprecation/p/Dep1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/NestedDeprecation/p/Dep1.java Mon Nov 24 16:02:35 2014 +0100 @@ -0,0 +1,12 @@ +package p; + +class Dep1 { + @Deprecated + static class A { } + @Deprecated + static class B { } + @Deprecated + static void method() { } + @Deprecated + static String field; +} diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/NestedDeprecation/p/Dep2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/NestedDeprecation/p/Dep2.java Mon Nov 24 16:02:35 2014 +0100 @@ -0,0 +1,8 @@ +package p; + +@Deprecated +class Dep2 { + class C { } + @Deprecated + class D { } +} diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/suppress/ImplicitTest.java --- a/langtools/test/tools/javac/warnings/suppress/ImplicitTest.java Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/test/tools/javac/warnings/suppress/ImplicitTest.java Mon Nov 24 16:02:35 2014 +0100 @@ -27,5 +27,5 @@ * @summary Verify that deprecated warning is printed correctly for import * statement when processing a file on demand while attributing another file. * @clean pack.ImplicitUse pack.ImplicitMain pack.Dep - * @compile/ref=ImplicitTest.out -XDrawDiagnostics -Xlint:deprecation pack/ImplicitMain.java + * @compile/ref=ImplicitTest.out -source 8 -XDrawDiagnostics -Xlint:deprecation,-options pack/ImplicitMain.java */ diff -r 746c658e8d35 -r 22b4bfc4e22f langtools/test/tools/javac/warnings/suppress/PackageInfo.java --- a/langtools/test/tools/javac/warnings/suppress/PackageInfo.java Fri Nov 21 16:36:39 2014 -0500 +++ b/langtools/test/tools/javac/warnings/suppress/PackageInfo.java Mon Nov 24 16:02:35 2014 +0100 @@ -26,5 +26,5 @@ * @bug 8021112 * @summary Verify that deprecated warnings are printed correctly for package-info.java * @clean pack.package-info pack.DeprecatedClass - * @compile/ref=PackageInfo.out -XDrawDiagnostics -Xlint:deprecation pack/package-info.java pack/DeprecatedClass.java + * @compile/ref=PackageInfo.out -source 8 -XDrawDiagnostics -Xlint:deprecation,-options pack/package-info.java pack/DeprecatedClass.java */