deprecated member is still used: ignore usages in javadocs (IDEA-204787)

This commit is contained in:
Anna.Kozlova
2018-12-27 17:37:30 +01:00
parent 25f7cfbb74
commit a1e5fff940
5 changed files with 66 additions and 75 deletions
@@ -3,9 +3,11 @@ package com.intellij.codeInspection;
import com.intellij.codeInspection.deprecation.DeprecationInspectionBase;
import com.intellij.psi.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiSearchHelper;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
/**
@@ -57,6 +59,10 @@ public class DeprecatedIsStillUsedInspection extends LocalInspectionTool {
}
return ReferencesSearch.search(element, searchScope, false)
.anyMatch(reference -> !DeprecationInspectionBase.isElementInsideDeprecated(reference.getElement()));
.anyMatch(reference -> {
PsiElement referenceElement = reference.getElement();
return !DeprecationInspectionBase.isElementInsideDeprecated(referenceElement) &&
PsiTreeUtil.getParentOfType(referenceElement, PsiDocComment.class) == null;
});
}
}
@@ -0,0 +1,51 @@
public class Simple {
/**
* @deprecated
*/
int <warning descr="Deprecated member 'bbb' is still used">bbb</warning>;
@Deprecated
int <warning descr="Deprecated member 'bbb2' is still used">bbb2</warning>;
@Deprecated
int <warning descr="Deprecated member 'bbb3' is still used">bbb3</warning>() {
return 0;
}
@Deprecated
class <warning descr="Deprecated member 'Bbb4' is still used">Bbb4</warning> {
}
int use(){
return bbb + bbb2 + bbb3() + Bbb4.class.toString().hashCode();
}
//////////////////////////////
@Deprecated
int ddd2;
@Deprecated
int ddd3() {
return 0;
}
@Deprecated
class Ddd4 {
}
@Deprecated
int useFromDeprecated(){
return ddd2 + ddd3() + Ddd4.class.toString().hashCode();
}
/**
* {@link #useFromJavadoc}
*/
void withJavadocReference() {}
@Deprecated
void useFromJavadoc() { }
}
@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>5</line>
<description>Deprecated member 'bbb' is still used</description>
</problem>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Deprecated member 'bbb2' is still used</description>
</problem>
<problem>
<file>Test.java</file>
<line>11</line>
<description>Deprecated member 'bbb3' is still used</description>
</problem>
<problem>
<file>Test.java</file>
<line>16</line>
<description>Deprecated member 'Bbb4' is still used</description>
</problem>
</problems>
@@ -1,44 +0,0 @@
public class Test{
/**
* @deprecated
*/
int bbb;
@Deprecated
int bbb2;
@Deprecated
int bbb3() {
return 0;
}
@Deprecated
class Bbb4 {
}
int use(){
return bbb + bbb2 + bbb3() + Bbb4.class.toString().hashCode();
}
//////////////////////////////
@Deprecated
int ddd2;
@Deprecated
int ddd3() {
return 0;
}
@Deprecated
class Ddd4 {
}
@Deprecated
int useFromDeprecated(){
return ddd2 + ddd3() + Ddd4.class.toString().hashCode();
}
}
@@ -18,19 +18,21 @@ package com.intellij.java.codeInspection;
import com.intellij.JavaTestUtil;
import com.intellij.codeInspection.DeprecatedIsStillUsedInspection;
import com.intellij.testFramework.InspectionTestCase;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
public class DeprecatedIsStillUsedInspectionTest extends InspectionTestCase {
public class DeprecatedIsStillUsedInspectionTest extends LightCodeInsightFixtureTestCase {
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath() + "/inspection";
return JavaTestUtil.getJavaTestDataPath() + "/inspection/deprecatedIsStillUsed";
}
private void doTest() {
doTest("deprecatedIsStillUsed/" + getTestName(true), new DeprecatedIsStillUsedInspection());
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.enableInspections(new DeprecatedIsStillUsedInspection());
}
public void testSimple() {
doTest();
myFixture.testHighlighting(getTestName(false) + ".java");
}
}