diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index 289ffd35827f..6ec03454d990 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -264,21 +264,21 @@ public class JavaCompletionContributor extends CompletionContributor { result.stopHere(); } - List referenceSuggestions = parent instanceof PsiJavaCodeReferenceElement && mayCompleteReference + List 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; } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java index cebab85c5d19..d73a183e7bdd 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java @@ -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 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)); } } diff --git a/java/java-tests/testData/codeInsight/completion/normal/OneElementArray.java b/java/java-tests/testData/codeInsight/completion/normal/OneElementArray.java new file mode 100644 index 000000000000..5bb5c964829b --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/OneElementArray.java @@ -0,0 +1,8 @@ +public class SomeClass { + + { + int[] aaa = new int[1]; + int bbb = a + } + +} diff --git a/java/java-tests/testData/codeInsight/completion/normal/OneElementArray_after.java b/java/java-tests/testData/codeInsight/completion/normal/OneElementArray_after.java new file mode 100644 index 000000000000..c49930be2610 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/OneElementArray_after.java @@ -0,0 +1,8 @@ +public class SomeClass { + + { + int[] aaa = new int[1]; + int bbb = aaa[0] + } + +} diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy index 3d49a9a90e0d..78a8517e5fa2 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/NormalCompletionTest.groovy @@ -2005,4 +2005,11 @@ class Abc { } void testCaseColonAfterStringConstant() { doTest() } + + void testOneElementArray() { + configureByTestName() + myFixture.assertPreferredCompletionItems 0, 'aaa', 'aaa[0]' + selectItem(myItems[1]) + checkResult() + } }