diff --git a/java/java-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspection.java index ab940b08e54e..6016b5cf72de 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspection.java @@ -45,10 +45,11 @@ public class DeprecationInspection extends BaseJavaLocalInspectionTool { public boolean IGNORE_INSIDE_DEPRECATED = false; public boolean IGNORE_ABSTRACT_DEPRECATED_OVERRIDES = true; + public boolean IGNORE_IMPORT_STATEMENTS = true; @NotNull public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { - return new DeprecationElementVisitor(holder, IGNORE_INSIDE_DEPRECATED, IGNORE_ABSTRACT_DEPRECATED_OVERRIDES); + return new DeprecationElementVisitor(holder, IGNORE_INSIDE_DEPRECATED, IGNORE_ABSTRACT_DEPRECATED_OVERRIDES, IGNORE_IMPORT_STATEMENTS); } @NotNull @@ -80,6 +81,7 @@ public class DeprecationInspection extends BaseJavaLocalInspectionTool { public JComponent createOptionsPanel() { final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this); panel.addCheckbox("Ignore inside deprecated members", "IGNORE_INSIDE_DEPRECATED"); + panel.addCheckbox("Ignore inside non-static imports", "IGNORE_IMPORT_STATEMENTS"); panel.addCheckbox("Ignore overrides of deprecated abstract methods from non-deprecated supers", "IGNORE_ABSTRACT_DEPRECATED_OVERRIDES"); return panel; @@ -89,20 +91,32 @@ public class DeprecationInspection extends BaseJavaLocalInspectionTool { private final ProblemsHolder myHolder; private final boolean myIgnoreInsideDeprecated; private final boolean myIgnoreAbstractDeprecatedOverrides; + private final boolean myIgnoreImportStatements; public DeprecationElementVisitor(final ProblemsHolder holder, boolean ignoreInsideDeprecated, - boolean ignoreAbstractDeprecatedOverrides) { + boolean ignoreAbstractDeprecatedOverrides, + boolean ignoreImportStatements) { myHolder = holder; myIgnoreInsideDeprecated = ignoreInsideDeprecated; myIgnoreAbstractDeprecatedOverrides = ignoreAbstractDeprecatedOverrides; + myIgnoreImportStatements = ignoreImportStatements; } - @Override public void visitReferenceElement(PsiJavaCodeReferenceElement reference) { - JavaResolveResult result = reference.advancedResolve(true); - PsiElement resolved = result.getElement(); - checkDeprecated(resolved, reference.getReferenceNameElement(), null, myIgnoreInsideDeprecated, myHolder); + @Override + public void visitReferenceElement(PsiJavaCodeReferenceElement reference) { + JavaResolveResult result = reference.advancedResolve(true); + PsiElement resolved = result.getElement(); + checkDeprecated(resolved, reference.getReferenceNameElement(), null, myIgnoreInsideDeprecated, myIgnoreImportStatements, myHolder); + } + + @Override + public void visitImportStaticStatement(PsiImportStaticStatement statement) { + final PsiJavaCodeReferenceElement importReference = statement.getImportReference(); + if (importReference != null) { + checkDeprecated(importReference.resolve(), importReference.getReferenceNameElement(), null, myIgnoreInsideDeprecated, false, myHolder); } + } @Override public void visitReferenceExpression(PsiReferenceExpression expression) { visitReferenceElement(expression); @@ -131,7 +145,7 @@ public class DeprecationInspection extends BaseJavaLocalInspectionTool { PsiMethod constructor = result == null ? null : result.getElement(); if (constructor != null && expression.getClassOrAnonymousClassReference() != null) { if (expression.getClassReference() == null && constructor.getParameterList().getParametersCount() == 0) return; - checkDeprecated(constructor, expression.getClassOrAnonymousClassReference(), null, myIgnoreInsideDeprecated, myHolder); + checkDeprecated(constructor, expression.getClassOrAnonymousClassReference(), null, myIgnoreInsideDeprecated, myIgnoreImportStatements, myHolder); } } } @@ -223,13 +237,14 @@ public class DeprecationInspection extends BaseJavaLocalInspectionTool { PsiElement elementToHighlight, @Nullable TextRange rangeInElement, ProblemsHolder holder) { - checkDeprecated(refElement, elementToHighlight, rangeInElement, false, holder); + checkDeprecated(refElement, elementToHighlight, rangeInElement, false, false, holder); } public static void checkDeprecated(PsiElement refElement, PsiElement elementToHighlight, @Nullable TextRange rangeInElement, boolean ignoreInsideDeprecated, + boolean ignoreImportStatements, ProblemsHolder holder) { if (!(refElement instanceof PsiDocCommentOwner)) return; if (!((PsiDocCommentOwner)refElement).isDeprecated()) return; @@ -241,7 +256,7 @@ public class DeprecationInspection extends BaseJavaLocalInspectionTool { } } - if (PsiTreeUtil.getParentOfType(elementToHighlight, PsiImportStatementBase.class) != null) { + if (ignoreImportStatements && PsiTreeUtil.getParentOfType(elementToHighlight, PsiImportStatementBase.class) != null) { return; } diff --git a/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/expected.xml b/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/expected.xml new file mode 100644 index 000000000000..2c84938abc79 --- /dev/null +++ b/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/expected.xml @@ -0,0 +1,9 @@ + + + + Test.java + 1 + Deprecated API usage + 'a.A' is deprecated + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/src/Test.java b/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/src/Test.java new file mode 100644 index 000000000000..10c59da27ad7 --- /dev/null +++ b/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/src/Test.java @@ -0,0 +1,6 @@ +import static a.A.*; +public class Test { + { + foo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/src/a/A.java b/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/src/a/A.java new file mode 100644 index 000000000000..80b85e4c60b0 --- /dev/null +++ b/java/java-tests/testData/inspection/deprecation/deprecatedInStaticImport/src/a/A.java @@ -0,0 +1,5 @@ +package a; +@Deprecated +public class A { + public static void foo(){} +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DeprecationInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DeprecationInspectionTest.java index 41a802df93cf..e3a4f92db573 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DeprecationInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DeprecationInspectionTest.java @@ -29,6 +29,10 @@ public class DeprecationInspectionTest extends InspectionTestCase { doTest(); } + public void testDeprecatedInStaticImport() throws Exception{ + doTest(); + } + public void testDeprecatedInner() throws Exception { doTest(); }