[java, highlighting] Fix module conflict highlighting for exported packages IDEA-352819

GitOrigin-RevId: d4479fb863280674ae8960c930e6e8b1628b7321
This commit is contained in:
Aleksey Dobrynin
2024-09-12 16:28:26 +03:00
committed by intellij-monorepo-bot
parent 25cb51da31
commit f590114d83
3 changed files with 21 additions and 5 deletions

View File

@@ -80,9 +80,14 @@ final class ModuleHighlightUtil {
if (rootForFile != null && JavaCompilerConfigurationProxy.isPatchedModuleRoot(anotherJavaModule.getName(), module, rootForFile)) {
return null;
}
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(reference)
.descriptionAndTooltip(JavaErrorBundle.message("module.conflicting.packages", pack.getName(), anotherJavaModule.getName()));
for (PsiPackageAccessibilityStatement export : anotherJavaModule.getExports()) {
String exportPackageName = export.getPackageName();
if (exportPackageName != null && exportPackageName.equals(pack.getQualifiedName())) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(reference)
.descriptionAndTooltip(JavaErrorBundle.message("module.conflicting.packages", pack.getQualifiedName(), anotherJavaModule.getName()));
}
}
}
}
}

View File

@@ -1,4 +1,4 @@
package <error descr="Package 'stream' exists in another module: java.base">java.util.stream</error>;
package <error descr="Package 'java.util.stream' exists in another module: java.base">java.util.stream</error>;
import java.util.List;
import java.util.Iterator;

View File

@@ -481,7 +481,7 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() {
fun testPatchingJavaBase() {
highlight("Main.java", """
package <error descr="Package 'lang' exists in another module: java.base">java.lang</error>;
package <error descr="Package 'java.lang' exists in another module: java.base">java.lang</error>;
public class Main {}
""".trimIndent())
withCompileArguments(module, "--patch-module=java.base=/src") {
@@ -490,6 +490,17 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() {
public class Main {}
""".trimIndent())
}
highlight("Main.java", """
package java;
public class Main {}
""".trimIndent())
highlight("Main.java", """
package java.lang.my;
public class Main {}
""".trimIndent())
}
fun testAddReadsDependingOnSourceModule() {