mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
IDEA-157893 Autocompletion should not use static import in case of conflict
This commit is contained in:
@@ -51,6 +51,12 @@ public class JavaStaticMemberProcessor extends StaticMemberProcessor {
|
||||
protected LookupElement createLookupElement(@NotNull PsiMember member, @NotNull final PsiClass containingClass, boolean shouldImport) {
|
||||
shouldImport |= myOriginalPosition != null && PsiTreeUtil.isAncestor(containingClass, myOriginalPosition, false);
|
||||
|
||||
String exprText = member.getName() + (member instanceof PsiMethod ? "()" : "");
|
||||
PsiReference ref = JavaPsiFacade.getElementFactory(member.getProject()).createExpressionFromText(exprText, myOriginalPosition).findReferenceAt(0);
|
||||
if (ref instanceof PsiReferenceExpression && ((PsiReferenceExpression)ref).multiResolve(true).length > 0) {
|
||||
shouldImport = false;
|
||||
}
|
||||
|
||||
if (member instanceof PsiMethod) {
|
||||
return AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(new GlobalMethodCallElement((PsiMethod)member, shouldImport, false));
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import static foo.Foo.foo;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
System.out.println(foo);
|
||||
System.out.println(ba<caret>x);
|
||||
}
|
||||
|
||||
int bar = 42;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import foo.Foo;
|
||||
|
||||
import static foo.Foo.foo;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
System.out.println(foo);
|
||||
System.out.println(Foo.bar<caret>);
|
||||
}
|
||||
|
||||
int bar = 42;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import static foo.Foo.foo;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
foo();
|
||||
ba<caret>x
|
||||
}
|
||||
|
||||
void bar();
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import foo.Foo;
|
||||
|
||||
import static foo.Foo.foo;
|
||||
|
||||
class Bar {
|
||||
{
|
||||
foo();
|
||||
Foo.bar();<caret>
|
||||
}
|
||||
|
||||
void bar();
|
||||
}
|
||||
+29
@@ -1219,6 +1219,35 @@ public class ListUtils {
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testSuggestMembersOfStaticallyImportedClassesConflictWithLocalMethod() throws Exception {
|
||||
myFixture.addClass("""package foo;
|
||||
public class Foo {
|
||||
public static void foo() {}
|
||||
public static void bar() {}
|
||||
}
|
||||
""")
|
||||
configure()
|
||||
myFixture.assertPreferredCompletionItems 0, 'bar', 'bar'
|
||||
assert LookupElementPresentation.renderElement(myFixture.lookupElements[1]).itemText == 'Foo.bar'
|
||||
myFixture.lookup.currentItem = myFixture.lookupElements[1]
|
||||
myFixture.type '\t'
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testSuggestMembersOfStaticallyImportedClassesConflictWithLocalField() throws Exception {
|
||||
myFixture.addClass("""package foo;
|
||||
public class Foo {
|
||||
public static int foo = 1;
|
||||
public static int bar = 2;
|
||||
}
|
||||
""")
|
||||
configure()
|
||||
myFixture.assertPreferredCompletionItems 0, 'bar', 'Foo.bar'
|
||||
myFixture.lookup.currentItem = myFixture.lookupElements[1]
|
||||
myFixture.type '\t'
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testInstanceMagicMethod() throws Exception { doTest() }
|
||||
|
||||
void testNoDotOverwrite() throws Exception { doTest('.') }
|
||||
|
||||
Reference in New Issue
Block a user