mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java completion: suggest ref[0] in basic completion as we do in smart one (towards IDEA-145958)
GitOrigin-RevId: 26c336f486c3e7c8a94bee43df52d559821807f9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
113c6a7fd2
commit
040a0b2d7e
+6
-3
@@ -264,21 +264,21 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
result.stopHere();
|
||||
}
|
||||
|
||||
List<LookupElement> referenceSuggestions = parent instanceof PsiJavaCodeReferenceElement && mayCompleteReference
|
||||
List<LookupElement> refBasedSuggestions = parent instanceof PsiJavaCodeReferenceElement && mayCompleteReference
|
||||
? completeReference(parameters, (PsiJavaCodeReferenceElement)parent, session)
|
||||
: Collections.emptyList();
|
||||
if (!smart) {
|
||||
TailType switchLabelTail = IN_SWITCH_LABEL.accepts(position)
|
||||
? TailTypes.forSwitchLabel(Objects.requireNonNull(PsiTreeUtil.getParentOfType(position, PsiSwitchBlock.class)))
|
||||
: null;
|
||||
session.registerBatchItems(ContainerUtil.map(referenceSuggestions, e -> switchLabelTail != null ? new IndentingDecorator(TailTypeDecorator.withTail(e, switchLabelTail)) : e));
|
||||
session.registerBatchItems(ContainerUtil.map(refBasedSuggestions, e -> switchLabelTail != null ? new IndentingDecorator(TailTypeDecorator.withTail(e, switchLabelTail)) : e));
|
||||
result.stopHere();
|
||||
}
|
||||
|
||||
session.flushBatchItems();
|
||||
|
||||
if (smart) {
|
||||
addSmartCompletionSuggestions(parameters, result, referenceSuggestions);
|
||||
addSmartCompletionSuggestions(parameters, result, refBasedSuggestions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,6 +573,9 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
items.add(element);
|
||||
|
||||
ContainerUtil.addIfNotNull(items, ArrayMemberAccess.accessFirstElement(position, element));
|
||||
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
+1
-13
@@ -3,7 +3,6 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
|
||||
import com.intellij.codeInsight.lookup.ExpressionLookupItem;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.patterns.StandardPatterns;
|
||||
@@ -79,8 +78,6 @@ public class ReferenceExpressionCompletionContributor {
|
||||
ElementFilter filter = getReferenceFilter(element, false);
|
||||
allRefSuggestions = ContainerUtil.filter(allRefSuggestions, item -> filter.isAcceptable(item.getObject(), element));
|
||||
|
||||
Set<LookupElement> base = new HashSet<>(allRefSuggestions);
|
||||
|
||||
for (ExpectedTypeInfo info : infos) {
|
||||
for (LookupElement item : allRefSuggestions) {
|
||||
if (matchesExpectedType(item, info.getType())) {
|
||||
@@ -89,19 +86,10 @@ public class ReferenceExpressionCompletionContributor {
|
||||
}
|
||||
result.consume(item);
|
||||
}
|
||||
|
||||
ExpressionLookupItem access = ArrayMemberAccess.accessFirstElement(element, item);
|
||||
if (access != null) {
|
||||
base.add(access);
|
||||
PsiType type = access.getType();
|
||||
if (type != null && info.getType().isAssignableFrom(type)) {
|
||||
result.consume(access);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parameters.getInvocationCount() >= 2) {
|
||||
chainedEtc.add(new SlowerTypeConversions(base, element, (PsiJavaCodeReferenceElement) element.getParent(),
|
||||
chainedEtc.add(new SlowerTypeConversions(new HashSet<>(allRefSuggestions), element, (PsiJavaCodeReferenceElement) element.getParent(),
|
||||
new JavaSmartCompletionParameters(parameters, info), result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
public class SomeClass {
|
||||
|
||||
{
|
||||
int[] aaa = new int[1];
|
||||
int bbb = a<caret>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class SomeClass {
|
||||
|
||||
{
|
||||
int[] aaa = new int[1];
|
||||
int bbb = aaa[0]<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -2005,4 +2005,11 @@ class Abc {
|
||||
}
|
||||
|
||||
void testCaseColonAfterStringConstant() { doTest() }
|
||||
|
||||
void testOneElementArray() {
|
||||
configureByTestName()
|
||||
myFixture.assertPreferredCompletionItems 0, 'aaa', 'aaa[0]'
|
||||
selectItem(myItems[1])
|
||||
checkResult()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user