mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-completion] IDEA-251394 Smart completion suggests Collections.emptyList() twice
GitOrigin-RevId: 212118424fd3418a91a969cec6a275f23aa64c8e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
18a13dd519
commit
8d8b2df997
+14
@@ -5,6 +5,7 @@ import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -35,6 +36,19 @@ class CollectionsUtilityMethodsProvider {
|
||||
final PsiClass collectionsClass =
|
||||
JavaPsiFacade.getInstance(myElement.getProject()).findClass(JAVA_UTIL_COLLECTIONS, myElement.getResolveScope());
|
||||
if (collectionsClass == null) return;
|
||||
PsiJavaFile file = ObjectUtils.tryCast(parent.getContainingFile(), PsiJavaFile.class);
|
||||
if (file == null) return;
|
||||
PsiImportList importList = file.getImportList();
|
||||
if (importList != null) {
|
||||
for (PsiImportStaticStatement statement : importList.getImportStaticStatements()) {
|
||||
PsiClass aClass = statement.resolveTargetClass();
|
||||
if (aClass != null && aClass.isEquivalentTo(collectionsClass)) {
|
||||
// The Collections class is already statically imported;
|
||||
// should be suggested anyway in JavaStaticMemberProcessor
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final PsiElement pparent = parent.getParent();
|
||||
if (showAll ||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
// IDEA-251394
|
||||
public final class SomeUtils {
|
||||
|
||||
private SomeUtils() {}
|
||||
|
||||
public static List<Integer> getEventsFor(List<String> execution) {
|
||||
List<Long> statuses = new ArrayList<>();
|
||||
if (statuses.isEmpty()) {
|
||||
return <caret>
|
||||
}
|
||||
|
||||
if (execution.size() > 1) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
+7
@@ -346,4 +346,11 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
|
||||
public void testFilterInaccessibleConstructors() { doAntiTest(); }
|
||||
|
||||
public void testCastInToArrayCallWithUnresolvedType() { doAntiTest(); }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testNoDuplicateEmptyList() {
|
||||
configureByTestName();
|
||||
Lookup lookup = getLookup();
|
||||
assertEquals(1, lookup.getItems().stream().filter(item -> item.getLookupString().equals("emptyList")).count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user