Completion: fixed filtering shadowed declarations for generic functions
This commit is contained in:
@@ -140,42 +140,6 @@ enum class CallableWeight {
|
||||
|
||||
val CALLABLE_WEIGHT_KEY = Key<CallableWeight>("CALLABLE_WEIGHT_KEY")
|
||||
|
||||
fun descriptorsEqualWithSubstitution(descriptor1: DeclarationDescriptor?, descriptor2: DeclarationDescriptor?): Boolean {
|
||||
if (descriptor1 == descriptor2) return true
|
||||
if (descriptor1 == null || descriptor2 == null) return false
|
||||
if (descriptor1.getOriginal() != descriptor2.getOriginal()) return false
|
||||
if (descriptor1 !is CallableDescriptor) return true
|
||||
descriptor2 as CallableDescriptor
|
||||
|
||||
// optimization:
|
||||
if (descriptor1 == descriptor1.getOriginal() && descriptor2 == descriptor2.getOriginal()) return true
|
||||
|
||||
val typeChecker = JetTypeChecker.withAxioms(object: JetTypeChecker.TypeConstructorEquality {
|
||||
override fun equals(a: TypeConstructor, b: TypeConstructor): Boolean {
|
||||
val typeParam1 = a.getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
val typeParam2 = b.getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
if (typeParam1 != null
|
||||
&& typeParam2 != null
|
||||
&& typeParam1.getContainingDeclaration() == descriptor1
|
||||
&& typeParam2.getContainingDeclaration() == descriptor2) {
|
||||
return typeParam1.getIndex() == typeParam2.getIndex()
|
||||
}
|
||||
|
||||
return a == b
|
||||
}
|
||||
})
|
||||
|
||||
if (!typeChecker.equalTypesOrNulls(descriptor1.getReturnType(), descriptor2.getReturnType())) return false
|
||||
|
||||
val parameters1 = descriptor1.getValueParameters()
|
||||
val parameters2 = descriptor2.getValueParameters()
|
||||
if (parameters1.size() != parameters2.size()) return false
|
||||
for ((param1, param2) in parameters1.zip(parameters2)) {
|
||||
if (!typeChecker.equalTypes(param1.getType(), param2.getType())) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun InsertionContext.isAfterDot(): Boolean {
|
||||
var offset = getStartOffset()
|
||||
val chars = getDocument().getCharsSequence()
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
|
||||
import javax.swing.Icon
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
interface I<T> {
|
||||
fun xxx(): T
|
||||
}
|
||||
|
||||
fun foo(i1: I<Int>, i2: I<String>) {
|
||||
with (i1) {
|
||||
with (i2) {
|
||||
xx<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EXIST: { lookupString: "xxx", itemText: "xxx", tailText: "()", typeText: "String" }
|
||||
// NOTHING_ELSE
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fun <T> List<T>.xxx(){}
|
||||
fun <T> Iterable<T>.xxx(){}
|
||||
|
||||
fun foo() {
|
||||
listOf(1).xx<caret>
|
||||
}
|
||||
|
||||
// EXIST: { lookupString: "xxx", itemText: "xxx", tailText: "() for List<T> in <root>", typeText: "Unit" }
|
||||
// NOTHING_ELSE
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
fun <T> List<T>.xxx(t: T){}
|
||||
fun <T> Iterable<T>.xxx(t: T){}
|
||||
|
||||
fun foo() {
|
||||
listOf(1).xx<caret>
|
||||
}
|
||||
|
||||
// EXIST: { lookupString: "xxx", itemText: "xxx", tailText: "(t: Int) for List<T> in <root>", typeText: "Unit" }
|
||||
// NOTHING_ELSE
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package dependency
|
||||
|
||||
interface Iterable<T>
|
||||
interface List<T> : Iterable<T>
|
||||
|
||||
fun <T> List<T>.xxx(t: T){}
|
||||
fun <T> Iterable<T>.xxx(t: T){}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(list: dependency.List<Int>) {
|
||||
list.xx<caret>
|
||||
}
|
||||
|
||||
// EXIST: { lookupString: "xxx", itemText: "xxx", tailText: "(t: Int) for List<T> in dependency", typeText: "Unit" }
|
||||
// NOTHING_ELSE
|
||||
+18
@@ -1650,6 +1650,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferCloserReceiverGeneric.kt")
|
||||
public void testPreferCloserReceiverGeneric() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferCloserReceiverGeneric.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferMemberExtension.kt")
|
||||
public void testPreferMemberExtension() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMemberExtension.kt");
|
||||
@@ -1673,6 +1679,18 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMoreSpecificExtension.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferMoreSpecificExtensionGeneric.kt")
|
||||
public void testPreferMoreSpecificExtensionGeneric() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMoreSpecificExtensionGeneric.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferMoreSpecificExtensionGenericWithParam.kt")
|
||||
public void testPreferMoreSpecificExtensionGenericWithParam() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMoreSpecificExtensionGenericWithParam.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/idea-completion/testData/basic/common/typeArgsOrNot")
|
||||
|
||||
+18
@@ -1650,6 +1650,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferCloserReceiverGeneric.kt")
|
||||
public void testPreferCloserReceiverGeneric() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferCloserReceiverGeneric.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferMemberExtension.kt")
|
||||
public void testPreferMemberExtension() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMemberExtension.kt");
|
||||
@@ -1673,6 +1679,18 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMoreSpecificExtension.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferMoreSpecificExtensionGeneric.kt")
|
||||
public void testPreferMoreSpecificExtensionGeneric() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMoreSpecificExtensionGeneric.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PreferMoreSpecificExtensionGenericWithParam.kt")
|
||||
public void testPreferMoreSpecificExtensionGenericWithParam() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/PreferMoreSpecificExtensionGenericWithParam.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/idea-completion/testData/basic/common/typeArgsOrNot")
|
||||
|
||||
+6
@@ -137,6 +137,12 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MoreSpecificExtensionGeneric")
|
||||
public void testMoreSpecificExtensionGeneric() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/MoreSpecificExtensionGeneric/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MoreSpecificExtensionInDifferentPackage")
|
||||
public void testMoreSpecificExtensionInDifferentPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/MoreSpecificExtensionInDifferentPackage/");
|
||||
|
||||
Reference in New Issue
Block a user