[java-psi] PsiModifierListImpl: put new keyword next to the existing one

Avoid having annotations between modifiers
Fixes IDEA-274153 Make final inspection nullability issue

GitOrigin-RevId: 19d44fc864f5be2c3ca39460744620f6c21bf074
This commit is contained in:
Tagir Valeev
2021-08-03 12:10:29 +07:00
committed by intellij-monorepo-bot
parent 4d201ad256
commit 03232bfa8d
3 changed files with 24 additions and 0 deletions

View File

@@ -74,13 +74,17 @@ public class ModifierListElement extends CompositeElement {
private static ASTNode getDefaultAnchor(PsiModifierList modifierList, PsiKeyword modifier) {
Integer order = ourModifierToOrderMap.get(modifier.getText());
if (order == null) return null;
boolean hasKeyword = false;
for (ASTNode child = SourceTreeToPsiMap.psiToTreeNotNull(modifierList).getFirstChildNode(); child != null; child = child.getTreeNext()) {
if (ElementType.KEYWORD_BIT_SET.contains(child.getElementType())) {
hasKeyword = true;
Integer order1 = ourModifierToOrderMap.get(child.getText());
if (order1 == null) continue;
if (order1.intValue() > order.intValue()) {
return child;
}
} else if (child.getElementType() == JavaElementType.ANNOTATION && hasKeyword) {
return child;
}
}
return null;

View File

@@ -0,0 +1,10 @@
// "Make 'foo' static" "true"
import java.lang.annotation.*;
interface I {
public static @Anno int foo() {
System.out.println();
}
}
@Target(ElementType.TYPE_USE)
@interface Anno {}

View File

@@ -0,0 +1,10 @@
// "Make 'foo' static" "true"
import java.lang.annotation.*;
interface I {
public @Anno int f<caret>oo() {
System.out.println();
}
}
@Target(ElementType.TYPE_USE)
@interface Anno {}