From 3dcbdd89825d6a9a33f1fd50fd96e7e10b08bf50 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 28 Nov 2016 13:38:07 +0100 Subject: [PATCH] [java] ambiguous module refs highlighting (IDEA-164553) --- .../impl/analysis/ModuleHighlightUtil.java | 17 ++++++++++++----- .../src/messages/JavaErrorMessages.properties | 1 + .../daemon/ModuleHighlightingTest.kt | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java index 16333fd2df4e..b9c77368001c 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/ModuleHighlightUtil.java @@ -413,13 +413,20 @@ public class ModuleHighlightUtil { } private static HighlightInfo moduleResolveError(PsiJavaModuleReferenceElement refElement, PsiPolyVariantReference ref) { - boolean missing = ref.multiResolve(true).length == 0; - String message = JavaErrorMessages.message(missing ? "module.not.found" : "module.not.on.path", refElement.getReferenceText()); - HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(refElement).description(message).create(); - if (!missing) { + if (ref.multiResolve(true).length == 0) { + String message = JavaErrorMessages.message("module.not.found", refElement.getReferenceText()); + return HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(refElement).description(message).create(); + } + else if (ref.multiResolve(false).length > 1) { + String message = JavaErrorMessages.message("module.ambiguous", refElement.getReferenceText()); + return HighlightInfo.newHighlightInfo(HighlightInfoType.WARNING).range(refElement).description(message).create(); + } + else { + String message = JavaErrorMessages.message("module.not.on.path", refElement.getReferenceText()); + HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(refElement).description(message).create(); factory().registerOrderEntryFixes(new QuickFixActionRegistrarImpl(info), ref); + return info; } - return info; } private static QuickFixFactory factory() { diff --git a/java/java-psi-impl/src/messages/JavaErrorMessages.properties b/java/java-psi-impl/src/messages/JavaErrorMessages.properties index cae0654cb54f..fbe8ff23eb40 100644 --- a/java/java-psi-impl/src/messages/JavaErrorMessages.properties +++ b/java/java-psi-impl/src/messages/JavaErrorMessages.properties @@ -400,6 +400,7 @@ module.duplicate.provides=Duplicate provides: {0} module.file.wrong.location=Module declaration should be located in a module's source root module.open.duplicate.text=Go to duplicate module.not.found=Module not found: {0} +module.ambiguous=Ambiguous module reference: {0} module.not.on.path=Module is not in dependencies: {0} module.cyclic.dependence=Cyclic dependence: {0} package.not.found=Package not found: {0} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ModuleHighlightingTest.kt b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ModuleHighlightingTest.kt index 6c48b7100ab8..50186729027a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ModuleHighlightingTest.kt +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ModuleHighlightingTest.kt @@ -72,6 +72,7 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() { requires M1; requires M2; requires M3; + requires lib.auto; }""".trimIndent()) }