[java] highlighting for deprecated module usages

This commit is contained in:
Roman Shevchenko
2017-02-20 13:47:09 +01:00
parent 1344f56dcb
commit 68a6a503da
3 changed files with 24 additions and 0 deletions
@@ -25,6 +25,7 @@ import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
import com.intellij.psi.util.PsiTreeUtil;
@@ -216,6 +217,19 @@ public class DeprecationInspection extends BaseJavaBatchLocalInspectionTool {
}
}
}
@Override
public void visitRequiresStatement(PsiRequiresStatement statement) {
PsiJavaModuleReferenceElement refElement = statement.getReferenceElement();
if (refElement != null) {
PsiPolyVariantReference ref = refElement.getReference();
PsiElement target = ref != null ? ref.resolve() : null;
if (target instanceof PsiJavaModule && PsiImplUtil.isDeprecatedByAnnotation((PsiJavaModule)target)) {
String message = JavaErrorMessages.message("deprecated.symbol", HighlightMessageUtil.getSymbolName(target));
myHolder.registerProblem(refElement, message, ProblemHighlightType.LIKE_DEPRECATED);
}
}
}
}
private static boolean hasDefaultDeprecatedConstructor(PsiClass superClass) {
@@ -69,6 +69,9 @@ public class HighlightMessageUtil {
else if (symbol instanceof PsiDirectory) {
symbolName = ((PsiDirectory)symbol).getName();
}
else if (symbol instanceof PsiJavaModule) {
symbolName = ((PsiJavaModule)symbol).getName();
}
return symbolName;
}
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.daemon
import com.intellij.codeInsight.daemon.impl.JavaHighlightInfoTypes
import com.intellij.codeInspection.deprecation.DeprecationInspection
import com.intellij.openapi.util.TextRange
import com.intellij.testFramework.fixtures.LightJava9ModulesCodeInsightFixtureTestCase
import com.intellij.testFramework.fixtures.MultiModuleJava9ProjectDescriptor.ModuleDescriptor.*
@@ -215,6 +216,12 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() {
highlight("module M { requires M6; }")
}
fun testDeprecations() {
myFixture.enableInspections(DeprecationInspection())
addFile("module-info.java", "@Deprecated module M2 { }", M2)
highlight("""module M { requires <warning descr="'M2' is deprecated">M2</warning>; }""")
}
//<editor-fold desc="Helpers.">
private fun highlight(text: String) = highlight("module-info.java", text)