[java-highlighting] Avoid highlighting outside of PsiField psi element

Fixes IDEA-368916 IAE in error highlighting when several fields are declared with shared modifier list

GitOrigin-RevId: 012b6564f9ca1a775894a3fc2b003c4feb2477e6
This commit is contained in:
Tagir Valeev
2025-03-10 16:56:52 +01:00
committed by intellij-monorepo-bot
parent f3ac3c8925
commit 830860950b
3 changed files with 7 additions and 1 deletions

View File

@@ -158,7 +158,8 @@ final class JavaErrorFormatUtil {
static @NotNull TextRange getFieldDeclarationTextRange(@NotNull PsiField field) {
PsiModifierList modifierList = field.getModifierList();
TextRange range = field.getTextRange();
int start = modifierList == null ? range.getStartOffset() : stripAnnotationsFromModifierList(modifierList);
int start = modifierList == null || modifierList.getParent() != field ?
range.getStartOffset() : stripAnnotationsFromModifierList(modifierList);
int end = field.getNameIdentifier().getTextRange().getEndOffset();
return new TextRange(start, end).shiftLeft(range.getStartOffset());
}