mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-145768 MagicConstant completion in incomplete code
This commit is contained in:
+7
-11
@@ -45,7 +45,7 @@ public class MagicCompletionContributor extends CompletionContributor {
|
||||
private static final ElementPattern<PsiElement> IN_METHOD_CALL_ARGUMENT =
|
||||
psiElement().withParent(psiElement(PsiReferenceExpression.class).inside(psiElement(PsiExpressionList.class).withParent(PsiCall.class)));
|
||||
private static final ElementPattern<PsiElement> IN_BINARY_COMPARISON =
|
||||
psiElement().withParent(psiElement(PsiReferenceExpression.class).inside(psiElement(PsiBinaryExpression.class)));
|
||||
psiElement().withParent(psiElement(PsiReferenceExpression.class).inside(psiElement(PsiPolyadicExpression.class)));
|
||||
private static final ElementPattern<PsiElement> IN_ASSIGNMENT =
|
||||
psiElement().withParent(psiElement(PsiReferenceExpression.class).inside(psiElement(PsiAssignmentExpression.class)));
|
||||
private static final ElementPattern<PsiElement> IN_RETURN =
|
||||
@@ -129,17 +129,13 @@ public class MagicCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
else if (IN_BINARY_COMPARISON.accepts(pos)) {
|
||||
PsiBinaryExpression exp = PsiTreeUtil.getParentOfType(pos, PsiBinaryExpression.class);
|
||||
PsiPolyadicExpression exp = PsiTreeUtil.getParentOfType(pos, PsiPolyadicExpression.class);
|
||||
if (exp != null && (exp.getOperationTokenType() == JavaTokenType.EQEQ || exp.getOperationTokenType() == JavaTokenType.NE)) {
|
||||
PsiExpression l = exp.getLOperand();
|
||||
PsiModifierListOwner resolved = resolveExpression(l);
|
||||
if (resolved != null) {
|
||||
result.add(Pair.create(resolved, l.getType()));
|
||||
}
|
||||
PsiExpression r = exp.getROperand();
|
||||
resolved = resolveExpression(r);
|
||||
if (r != null && resolved != null) {
|
||||
result.add(Pair.create(resolved, r.getType()));
|
||||
for (PsiExpression operand : exp.getOperands()) {
|
||||
PsiModifierListOwner resolved = resolveExpression(operand);
|
||||
if (resolved != null) {
|
||||
result.add(Pair.create(resolved, operand.getType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-1
@@ -54,7 +54,7 @@ class Foo {
|
||||
|
||||
myFixture.configureByText "a.java", """
|
||||
class Bar {
|
||||
static void foo(ModifierList ml) {
|
||||
static void foo() {
|
||||
if (getConstant() == <caret>) {}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,28 @@ interface Foo {
|
||||
myFixture.assertPreferredCompletionItems 0, 'BAR', 'FOO'
|
||||
}
|
||||
|
||||
public void "test magic constant in equality before another equality"() {
|
||||
addMagicConstant()
|
||||
|
||||
myFixture.configureByText "a.java", """
|
||||
class Bar {
|
||||
static void foo() {
|
||||
if (getConstant() == <caret>getConstant() == 2) {}
|
||||
}
|
||||
|
||||
@org.intellij.lang.annotations.MagicConstant(flagsFromClass = Foo.class)
|
||||
public native int getConstant();
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
int FOO = 1;
|
||||
int BAR = 2;
|
||||
}
|
||||
"""
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
myFixture.assertPreferredCompletionItems 0, 'BAR', 'FOO'
|
||||
}
|
||||
|
||||
private PsiClass addModifierList() {
|
||||
addMagicConstant()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user