8032211: Don't issue deprecation warnings on import statements

6598104: javac should not warn about imports of deprecated classes

Suppressing the deprecation warnings when importing a deprecated element (deprecations in import qualifier will be produced).

Reviewed-by: darcy, jjg, mcimadamore
This commit is contained in:
Jan Lahoda 2014-11-24 16:02:35 +01:00
parent 590188542e
commit 26298f1124
14 changed files with 97 additions and 13 deletions

View File

@ -80,6 +80,16 @@ public class Lint
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<LintCategory> values;

View File

@ -152,6 +152,9 @@ public enum Source {
public boolean allowStringsInSwitch() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowDeprecationOnImport() {
return compareTo(JDK1_9) < 0;
}
public boolean allowSimplifiedVarargs() {
return compareTo(JDK1_7) >= 0;
}

View File

@ -33,6 +33,7 @@ import java.util.Set;
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 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
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 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
Type attribImportType(JCTree tree, Env<AttrContext> 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 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
return attr.attribType(tree, env);
} finally {
completionEnabled = true;
chk.setLint(prevLint);
}
}

View File

@ -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 {

View File

@ -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
{

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;
}
}

View File

@ -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

View File

@ -0,0 +1,12 @@
package p;
class Dep1 {
@Deprecated
static class A { }
@Deprecated
static class B { }
@Deprecated
static void method() { }
@Deprecated
static String field;
}

View File

@ -0,0 +1,8 @@
package p;
@Deprecated
class Dep2 {
class C { }
@Deprecated
class D { }
}

View File

@ -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
*/

View File

@ -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
*/