[java] ambiguous module refs highlighting (IDEA-164553)

This commit is contained in:
Roman Shevchenko
2016-11-28 13:38:26 +01:00
parent 1c79521d54
commit 3dcbdd8982
3 changed files with 14 additions and 5 deletions
@@ -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() {
@@ -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}
@@ -72,6 +72,7 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() {
requires <error descr="Cyclic dependence: M1">M1</error>;
requires <error descr="Cyclic dependence: M1, M2">M2</error>;
requires <error descr="Module is not in dependencies: M3">M3</error>;
requires <warning descr="Ambiguous module reference: lib.auto">lib.auto</warning>;
}""".trimIndent())
}