Smart completion of inheritors: correct filtering of duplicates

This commit is contained in:
Valentin Kipyatkov
2014-11-26 22:17:32 +03:00
parent 85825e0ab1
commit 4acf668ab8
5 changed files with 49 additions and 2 deletions
@@ -204,7 +204,8 @@ class TypeInstantiationItems(
lookupElement = lookupElement.assignSmartCompletionPriority(SmartCompletionItemPriority.INSTANTIATION)
}
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
//TODO: cannot use lookupElement from context due to KT-6344
class InstantiationLookupElement(lookupElement: LookupElement) : LookupElementDecorator<LookupElement>(lookupElement) {
override fun getLookupString() = lookupString
override fun getAllLookupStrings() = allLookupStrings
@@ -223,9 +224,20 @@ class TypeInstantiationItems(
override fun handleInsert(context: InsertionContext) {
insertHandler.handleInsert(context, getDelegate())
}
override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is InstantiationLookupElement) return false
if (getLookupString() != other.getLookupString()) return false
val presentation1 = LookupElementPresentation()
val presentation2 = LookupElementPresentation()
renderElement(presentation1)
other.renderElement(presentation2)
return presentation1.getItemText() == presentation2.getItemText() && presentation1.getTailText() == presentation2.getTailText()
}
}
return lookupElement.addTail(tail)
return InstantiationLookupElement(lookupElement).addTail(tail)
}
private fun addSamConstructorItem(collection: MutableCollection<LookupElement>, `class`: ClassDescriptor, tail: Tail?) {
@@ -0,0 +1,16 @@
class X
class Y
trait T1
trait T2<T>
trait T3<T>
class C1 : T1
class C2<T> : T2<T>, T3<T>
class C3 : T1, T2<X>
fun foo(p: T1){}
fun foo(p: T2<X>){}
fun foo(p: T3<Y>){}
// ALLOW_AST_ACCESS
@@ -0,0 +1,12 @@
fun bar() {
foo(<caret>)
}
// EXIST: { lookupString: "object", itemText: "object: T1{...}" }
// EXIST: { lookupString: "object", itemText: "object: T2<X>{...}" }
// EXIST: { lookupString: "object", itemText: "object: T3<Y>{...}" }
// EXIST: { lookupString: "C1", itemText: "C1" }
// EXIST: { lookupString: "C2", itemText: "C2<X>" }
// EXIST: { lookupString: "C2", itemText: "C2<Y>" }
// EXIST: { lookupString: "C3", itemText: "C3" }
// NUMBER: 7
@@ -19,6 +19,7 @@ package org.jetbrains.jet.completion;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -72,6 +72,12 @@ public class MultiFileSmartCompletionTestGenerated extends AbstractMultiFileSmar
doTest(fileName);
}
@TestMetadata("InheritorsAndMultipleExpectedTypes")
public void testInheritorsAndMultipleExpectedTypes() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smartMultiFile/InheritorsAndMultipleExpectedTypes/");
doTest(fileName);
}
@TestMetadata("JavaStaticMethodArgument")
public void testJavaStaticMethodArgument() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smartMultiFile/JavaStaticMethodArgument/");