[java-completion] Lower 'else' when there's already 'else' afterwards

GitOrigin-RevId: 8093446ec8641a763810e3346125919f22a8ec08
This commit is contained in:
Tagir Valeev
2021-12-22 04:14:13 +00:00
committed by intellij-monorepo-bot
parent 577cee1e9b
commit 7e9975d69e
@@ -230,7 +230,18 @@ public class JavaKeywordCompletion {
if (psiElement().withText(";").withSuperParent(2, PsiIfStatement.class).accepts(myPrevLeaf) ||
psiElement().withText("}").withSuperParent(3, PsiIfStatement.class).accepts(myPrevLeaf)) {
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.ELSE), TailType.HUMBLE_SPACE_BEFORE_WORD));
LookupElement elseKeyword = new OverridableSpace(createKeyword(PsiKeyword.ELSE), TailType.HUMBLE_SPACE_BEFORE_WORD);
CharSequence text = myParameters.getEditor().getDocument().getCharsSequence();
int offset = myParameters.getOffset();
while (text.length() > offset && Character.isWhitespace(text.charAt(offset))) {
offset++;
}
if (text.length() > offset + PsiKeyword.ELSE.length() &&
text.subSequence(offset, offset + PsiKeyword.ELSE.length()).toString().equals(PsiKeyword.ELSE) &&
Character.isWhitespace(text.charAt(offset + PsiKeyword.ELSE.length()))) {
elseKeyword = PrioritizedLookupElement.withPriority(elseKeyword, -1);
}
addKeyword(elseKeyword);
}
}