when lexicographic completion sorting is enabled, really sort the items lexicographic...
authorpeter <peter@jetbrains.com>
Mon, 9 Jan 2012 18:05:20 +0000 (19:05 +0100)
committerpeter <peter@jetbrains.com>
Mon, 9 Jan 2012 18:36:46 +0000 (19:36 +0100)
java/java-tests/testData/codeInsight/completion/normalSorting/ReallyAlphaSorting.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy [moved from java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java with 94% similarity]
platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java

diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/ReallyAlphaSorting.java b/java/java-tests/testData/codeInsight/completion/normalSorting/ReallyAlphaSorting.java
new file mode 100644 (file)
index 0000000..4fcc11b
--- /dev/null
@@ -0,0 +1,8 @@
+class Foo {
+  void zoo() {}
+
+  {
+    new Foo().<caret>
+  }
+
+}
\ No newline at end of file
similarity index 94%
rename from java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java
rename to java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy
index 739d2460116a55e173a327ed93cde36de04dce55..de77849ddd9befac6e24fe124daba5a131fd16c0 100644 (file)
@@ -4,17 +4,15 @@
 
 package com.intellij.codeInsight.completion;
 
-import com.intellij.JavaTestUtil;
-import com.intellij.codeInsight.CodeInsightSettings;
-import com.intellij.codeInsight.lookup.LookupElement;
-import com.intellij.codeInsight.lookup.impl.LookupImpl;
-import com.intellij.ide.ui.UISettings;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiMethod;
 
-import java.util.List;
+import com.intellij.JavaTestUtil
+import com.intellij.codeInsight.CodeInsightSettings
+import com.intellij.codeInsight.lookup.LookupElement
+import com.intellij.codeInsight.lookup.impl.LookupImpl
+import com.intellij.ide.ui.UISettings
+import com.intellij.psi.PsiClass
+import com.intellij.psi.PsiMethod
 
-@SuppressWarnings({"ALL"})
 public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
   private static final String BASE_PATH = "/codeInsight/completion/normalSorting";
 
@@ -273,6 +271,18 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
     }
   }
 
+  public void testReallyAlphaSorting() {
+    UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true;
+
+    try {
+      invokeCompletion(getTestName(false) + ".java");
+      assert myFixture.lookupElementStrings.sort() == myFixture.lookupElementStrings
+    }
+    finally {
+      UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false;
+    }
+  }
+
   public void testSortSameNamedVariantsByProximity() {
     myFixture.addClass("public class Bar {}");
     for (int i = 0; i < 10; i++) {
@@ -280,7 +290,6 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
       myFixture.addClass("public class Bar" + i + "Colleague {}");
     }
     myFixture.addClass("package bar; public class Bar {}");
-    final String path = getTestName(false) + ".java";
     myFixture.configureByFile(getTestName(false) + ".java");
     myFixture.complete(CompletionType.BASIC, 2);
     assertPreferredItems(0, "Bar", "Bar");
index a81472cd039a51131f83a315403c026e41b2f9a7..0c0800036a6aba1ba905b17cbcec6754da2f019a 100644 (file)
@@ -435,7 +435,14 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
     }
 
     if (isAlphaSorted()) {
-      model.addAll(items);
+      final ArrayList<LookupElement> elements = new ArrayList<LookupElement>(items);
+      Collections.sort(elements, new Comparator<LookupElement>() {
+        @Override
+        public int compare(LookupElement o1, LookupElement o2) {
+          return o1.getLookupString().compareToIgnoreCase(o2.getLookupString());
+        }
+      });
+      model.addAll(elements);
     } else if (limitRelevance()) {
       model.addAll(addRemainingItemsLexicographically(model, items));
     } else  {