Java: No deprecation warning when declaration and usage are within the same top-level class, JLS 9.6.4.6 (IDEA-131480)

This commit is contained in:
Pavel Dolgov
2019-02-26 14:45:45 +03:00
parent 3a749059e8
commit 974a946128
8 changed files with 65 additions and 9 deletions

View File

@@ -31,7 +31,7 @@ import java.util.Objects;
import java.util.stream.Stream;
public abstract class DeprecationInspectionBase extends LocalInspectionTool {
public boolean IGNORE_IN_SAME_OUTERMOST_CLASS;
public boolean IGNORE_IN_SAME_OUTERMOST_CLASS = true;
@Override
public boolean isEnabledByDefault() {

View File

@@ -21,10 +21,6 @@ import javax.swing.*;
public class MarkedForRemovalInspection extends DeprecationInspectionBase {
{
IGNORE_IN_SAME_OUTERMOST_CLASS = true;
}
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {

View File

@@ -26,7 +26,7 @@ class b extends a {
}
b() {
<warning descr="'b(int)' is deprecated">this</warning>(1);
this(1);
}
/**
@@ -39,6 +39,10 @@ class b extends a {
}
class c extends b {
c(int i) {
<warning descr="'b(int)' is deprecated">super</warning>(i);
}
// b.f is not deprecated
void f() {}
}
@@ -83,6 +87,12 @@ class Anonym {
public Anonym(String sss) {
System.out.println(sss);
}
public void foo() {
new Anonym("asdasd") {};
}
}
class UseAnonym {
public void foo() {
new <warning descr="'Anonym(java.lang.String)' is deprecated">Anonym</warning>("asdasd") {};
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>21</line>
<description>'field' is deprecated</description>
</problem>
<problem>
<file>Test.java</file>
<line>22</line>
<description>'method()' is deprecated</description>
</problem>
</problems>

View File

@@ -0,0 +1,24 @@
class C {
@Deprecated
int field;
@Deprecated
void C() { }
@Deprecated
void method() { }
static void bar() {
C c = new C();
c.field = 1;
c.method();
}
}
class AnotherTopLevel {
static void bar() {
C c = new C();
c.field = 1;
c.method();
}
}

View File

@@ -43,11 +43,14 @@ public class SuppressNonInspectionsTest extends LightQuickFixParameterizedTestCa
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
DeprecationInspection deprecationInspection = new DeprecationInspection();
deprecationInspection.IGNORE_IN_SAME_OUTERMOST_CLASS = false;
return new LocalInspectionTool[]{
new RedundantThrowsDeclarationLocalInspection(),
new SillyAssignmentInspection(),
new AccessStaticViaInstance(),
new DeprecationInspection(),
deprecationInspection,
new JavaDocReferenceInspection(),
new UncheckedWarningLocalInspection()
};

View File

@@ -24,7 +24,9 @@ public class DeprecationInspectionFixTest extends LightQuickFixParameterizedTest
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{new DeprecationInspection()};
DeprecationInspection inspection = new DeprecationInspection();
inspection.IGNORE_IN_SAME_OUTERMOST_CLASS = false;
return new LocalInspectionTool[]{inspection};
}
@Override

View File

@@ -42,7 +42,9 @@ public class DeprecationInspectionTest extends InspectionTestCase {
}
private void doTest() {
doTest("deprecation/" + getTestName(true), new DeprecationInspection());
DeprecationInspection tool = new DeprecationInspection();
tool.IGNORE_IN_SAME_OUTERMOST_CLASS = false;
doTest("deprecation/" + getTestName(true), tool);
}
public void testDeprecatedMethod() {
@@ -91,6 +93,11 @@ public class DeprecationInspectionTest extends InspectionTestCase {
doTest("deprecation/" + getTestName(true), tool);
}
public void testIgnoreInSameOutermostClass() {
final DeprecationInspection tool = new DeprecationInspection();
doTest("deprecation/" + getTestName(true), tool);
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {