java basic completion: move chain suggestions (IDEA-145958) lower, restore static-after-instance on second invocation

GitOrigin-RevId: ca35702dc948b2f77168e21e268b8b48abb7e25a
This commit is contained in:
Peter Gromov
2020-06-15 16:56:30 +03:00
committed by intellij-monorepo-bot
parent a209cdf062
commit cd53bdd099
6 changed files with 22 additions and 11 deletions
@@ -274,7 +274,7 @@ public class JavaCompletionContributor extends CompletionContributor {
List<LookupElement> refSuggestions = Collections.emptyList();
if (parent instanceof PsiJavaCodeReferenceElement && mayCompleteReference) {
refSuggestions = completeReference(parameters, (PsiJavaCodeReferenceElement)parent, session, expectedInfos);
List<LookupElement> filtered = filterReferenceSuggestions(smart, result, (PsiJavaCodeReferenceElement)parent, expectedInfos, refSuggestions);
List<LookupElement> filtered = filterReferenceSuggestions(parameters, result, (PsiJavaCodeReferenceElement)parent, expectedInfos, refSuggestions);
hasTypeMatchingSuggestions |= ContainerUtil.exists(filtered, item ->
ReferenceExpressionCompletionContributor.matchesExpectedType(item, expectedInfos));
session.registerBatchItems(filtered);
@@ -337,15 +337,16 @@ public class JavaCompletionContributor extends CompletionContributor {
}
}
private static List<LookupElement> filterReferenceSuggestions(boolean smart,
private static List<LookupElement> filterReferenceSuggestions(CompletionParameters parameters,
CompletionResultSet result,
PsiJavaCodeReferenceElement parent,
Set<ExpectedTypeInfo> expectedInfos,
List<LookupElement> refSuggestions) {
if (smart) {
if (parameters.getCompletionType() == CompletionType.SMART) {
refSuggestions = ReferenceExpressionCompletionContributor.smartCompleteReference(refSuggestions, expectedInfos);
}
List<LookupElement> matching = ContainerUtil.findAll(refSuggestions, result.getPrefixMatcher()::prefixMatches);
if (parameters.getInvocationCount() >= 2) return matching;
return JavaCompletionProcessor.dispreferStaticAfterInstance(parent, matching);
}
@@ -169,6 +169,7 @@ public class PreferByKindWeigher extends LookupElementWeigher {
getterQualifiedByMethod,
accessibleFieldGetter,
normal,
basicChain,
collectionFactory,
expectedTypeMethod,
verySuitableClass,
@@ -236,6 +237,9 @@ public class PreferByKindWeigher extends LookupElementWeigher {
}
final JavaChainLookupElement chain = item.as(JavaChainLookupElement.CLASS_CONDITION_KEY);
if (chain != null) {
if (myCompletionType == CompletionType.BASIC) {
return MyResult.basicChain;
}
Object qualifier = chain.getQualifier().getObject();
if (qualifier instanceof PsiVariable && PsiUtil.isJvmLocalVariable((PsiVariable)qualifier)) {
return MyResult.variable;
@@ -1,6 +1,6 @@
public class KeyVO {
{
this.fo<caret>
this.<caret>
}
static void foo() {}
}
@@ -4,10 +4,9 @@ class Bar {
class Goo {}
class Foo {
Bar getBar() {}
Bar bar() {}
void x(Goo unmatched) {
Goo g = getG<caret>
Goo g = ba<caret>
}
}
@@ -4,10 +4,9 @@ class Bar {
class Goo {}
class Foo {
Bar getBar() {}
Bar bar() {}
void x(Goo unmatched) {
Goo g = getBar().getGoo();<caret>
Goo g = bar().getGoo();<caret>
}
}
@@ -531,7 +531,10 @@ public class Outer {
void testAccessStaticViaInstanceSecond() throws Throwable {
configure()
assert !('foo' in myFixture.lookupElementStrings)
myFixture.complete(CompletionType.BASIC, 2)
myFixture.assertPreferredCompletionItems 0, 'foo'
myFixture.type('\n')
checkResult()
}
@@ -2020,5 +2023,10 @@ class Abc {
checkResult()
}
void testSuggestChainsOfExpectedType() { doTest() }
void testSuggestChainsOfExpectedType() {
configure()
myFixture.assertPreferredCompletionItems 0, 'bar', 'bar().getGoo'
selectItem(myItems[1])
checkResult()
}
}