[java-highlighting] IDEA-357214 'Module' is highlighted as an error when module name is expected

GitOrigin-RevId: c7ca9de1821e79b96a05ab74a3cbad7052ceb827
This commit is contained in:
Mikhail Pyltsin
2024-10-10 14:06:10 +02:00
committed by intellij-monorepo-bot
parent 59cadbb09a
commit 7e9f1978a2
8 changed files with 161 additions and 1 deletions

View File

@@ -3537,6 +3537,20 @@ public final class HighlightUtil {
return null;
}
//do not highlight module keyword if the statement is not complete
//see com.intellij.lang.java.parser.BasicFileParser.parseImportStatement
if (PsiKeyword.MODULE.equals(ref.getText()) && refParent instanceof PsiImportStatement &&
PsiUtil.isAvailable(JavaFeature.MODULE_IMPORT_DECLARATIONS, ref)) {
PsiElement importKeywordExpected = PsiTreeUtil.skipWhitespacesAndCommentsBackward(ref);
PsiElement errorElementExpected = PsiTreeUtil.skipWhitespacesAndCommentsForward(ref);
if (importKeywordExpected instanceof PsiKeyword keyword &&
keyword.textMatches(PsiKeyword.IMPORT) &&
errorElementExpected instanceof PsiErrorElement errorElement &&
JavaPsiBundle.message("expected.identifier.or.semicolon").equals(errorElement.getErrorDescription())) {
return null;
}
}
JavaResolveResult[] results = ref.multiResolve(true);
String description;
if (results.length > 1) {