IDEA-90349 Auto-completion should always prefer exact match

This commit is contained in:
peter
2012-08-27 16:44:15 +02:00
parent 31d18936b5
commit 85903981fc
3 changed files with 20 additions and 1 deletions
@@ -0,0 +1,6 @@
public class Foo {
private int size;
public int size() { return size; }
public boolean isEmpty() { return size<caret>
@@ -12,6 +12,7 @@ import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.codeInsight.lookup.impl.LookupImpl
import com.intellij.ide.ui.UISettings
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiField
import com.intellij.psi.PsiMethod
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.psi.statistics.StatisticsManager
@@ -446,4 +447,10 @@ import java.lang.annotation.Target;
assertPreferredItems(0, '_goo2', '_goo1')
}
public void testPreferFieldToMethod() {
checkPreferredItems(0, 'size', 'size')
assert lookup.items[0].object instanceof PsiField
assert lookup.items[1].object instanceof PsiMethod
}
}
@@ -144,10 +144,16 @@ public class CompletionLookupArranger extends LookupArranger {
}
classifier.addElement(element);
final String invariant = presentation.getItemText() + "###" + presentation.getTailText() + "###" + presentation.getTypeText();
final String invariant = presentation.getItemText() + "###" + getTailTextOrSpace(presentation) + "###" + presentation.getTypeText();
element.putUserData(PRESENTATION_INVARIANT, invariant);
}
@NotNull
private static String getTailTextOrSpace(LookupElementPresentation presentation) {
String tailText = presentation.getTailText();
return tailText == null || tailText.isEmpty() ? " " : tailText;
}
private static List<LookupElement> sortByPresentation(Iterable<LookupElement> source) {
ArrayList<LookupElement> result = ContainerUtil.newArrayList(source);
ContainerUtil.sort(result, new Comparator<LookupElement>() {