"too generic method" completion sorting criteria shouldn't be applied in void context...
authorpeter <peter@jetbrains.com>
Sun, 1 May 2016 16:04:18 +0000 (18:04 +0200)
committerpeter <peter@jetbrains.com>
Mon, 2 May 2016 06:58:55 +0000 (08:58 +0200)
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java
java/java-tests/testData/codeInsight/completion/normalSorting/GenericityDoesNotMatterWhenNoTypeIsExpected.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/completion/Normal8CompletionTest.groovy
java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy

index 13a66d12e9de1aa0911894f1b0d70ff8123f1157..78f869ff31febac016e9078b96a7443b9dc61d2b 100644 (file)
@@ -81,8 +81,11 @@ public class JavaCompletionSorting {
       }
     }
     ContainerUtil.addIfNotNull(afterPrefix, recursion(parameters, expectedTypes));
-    Collections.addAll(afterPrefix, new PreferSimilarlyEnding(expectedTypes),
-                       new PreferNonGeneric(), new PreferAccessible(position), new PreferSimple());
+    afterPrefix.add(new PreferSimilarlyEnding(expectedTypes));
+    if (ContainerUtil.or(expectedTypes, info -> !info.getType().equals(PsiType.VOID))) {
+      afterPrefix.add(new PreferNonGeneric());
+    }
+    Collections.addAll(afterPrefix, new PreferAccessible(position), new PreferSimple());
 
     sorter = sorter.weighAfter("prefix", afterPrefix.toArray(new LookupElementWeigher[afterPrefix.size()]));
     sorter = sorter.weighAfter("proximity", afterProximity.toArray(new LookupElementWeigher[afterProximity.size()]));
diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/GenericityDoesNotMatterWhenNoTypeIsExpected.java b/java/java-tests/testData/codeInsight/completion/normalSorting/GenericityDoesNotMatterWhenNoTypeIsExpected.java
new file mode 100644 (file)
index 0000000..2180271
--- /dev/null
@@ -0,0 +1,9 @@
+class Test {
+
+    void nonGeneric() {}
+    <T> T generic() {}
+
+    {
+        this.<caret>
+    }
+}
index 29a40fe7071c5ed3fb44f43bfee4f2314799cb5e..7cf3edae78e018cc2a1bb9dc6a34836779727686 100644 (file)
@@ -219,7 +219,7 @@ class Test88 {
 
   public void testAllCollectors() {
     configureByTestName()
-    myFixture.assertPreferredCompletionItems 0, 'collect(Collectors.toCollection())', 'collect', 'collect', 'collect(Collectors.toList())', 'collect(Collectors.toSet())'
+    myFixture.assertPreferredCompletionItems 0, 'collect', 'collect', 'collect(Collectors.toCollection())', 'collect(Collectors.toList())', 'collect(Collectors.toSet())'
     selectItem(myItems.find { it.lookupString.contains('toCollection') })
     checkResultByFile(getTestName(false) + "_after.java")
   }
index 2aeb10b51b01ad9816cf25c73c992775f5ff21c0..00fc2da57eb7ac12a5f87d9224db79303a942fae 100644 (file)
@@ -99,6 +99,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
     checkPreferredItems(0, "getService", "getService", "class");
   }
 
+  public void testGenericityDoesNotMatterWhenNoTypeIsExpected() {
+    checkPreferredItems 0, "generic", "nonGeneric", "clone", "equals"
+  }
+
   public void testClassStaticMembersInVoidContext() throws Throwable {
     checkPreferredItems(0, "booleanMethod", "voidMethod", "AN_OBJECT", "BOOLEAN", "class");
   }