mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-06 08:31:30 +00:00
KT-7901 Auto import is not suggested
KT-7229 Completion for extension functions with complex capture #KT-7901 Fixed #KT-7229 Fixed
This commit is contained in:
@@ -47,18 +47,16 @@ class FuzzyType(
|
||||
val type: JetType,
|
||||
freeParameters: Collection<TypeParameterDescriptor>
|
||||
) {
|
||||
private val usedTypeParameters: HashSet<TypeParameterDescriptor>?
|
||||
public val freeParameters: Set<TypeParameterDescriptor>
|
||||
|
||||
init {
|
||||
if (freeParameters.isNotEmpty()) {
|
||||
usedTypeParameters = HashSet()
|
||||
val usedTypeParameters = HashSet<TypeParameterDescriptor>()
|
||||
usedTypeParameters.addUsedTypeParameters(type)
|
||||
this.freeParameters = freeParameters.filter { it in usedTypeParameters }.toSet()
|
||||
}
|
||||
else {
|
||||
usedTypeParameters = null
|
||||
this.freeParameters = setOf()
|
||||
this.freeParameters = emptySet()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +65,11 @@ class FuzzyType(
|
||||
override fun hashCode() = type.hashCode()
|
||||
|
||||
private fun MutableSet<TypeParameterDescriptor>.addUsedTypeParameters(type: JetType) {
|
||||
addIfNotNull(type.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor)
|
||||
val typeParameter = type.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
if (typeParameter != null && add(typeParameter)) {
|
||||
typeParameter.getLowerBounds().forEach { addUsedTypeParameters(it) }
|
||||
typeParameter.getUpperBounds().forEach { addUsedTypeParameters(it) }
|
||||
}
|
||||
|
||||
for (argument in type.getArguments()) {
|
||||
addUsedTypeParameters(argument.getType())
|
||||
@@ -96,7 +98,7 @@ class FuzzyType(
|
||||
}
|
||||
}
|
||||
|
||||
if (usedTypeParameters == null || usedTypeParameters.isEmpty()) {
|
||||
if (freeParameters.isEmpty()) {
|
||||
return if (type.checkInheritance(otherType)) TypeSubstitutor.EMPTY else null
|
||||
}
|
||||
|
||||
@@ -112,7 +114,9 @@ class FuzzyType(
|
||||
MatchKind.IS_SUPERTYPE -> constraintSystem.addSubtypeConstraint(otherType, type, ConstraintPositionKind.SPECIAL.position())
|
||||
}
|
||||
|
||||
if (constraintSystem.getStatus().isSuccessful() && ConstraintsUtil.checkBoundsAreSatisfied(constraintSystem, true)) {
|
||||
constraintSystem.processDeclaredBoundConstraints()
|
||||
|
||||
if (!constraintSystem.getStatus().hasContradiction()) {
|
||||
// currently ConstraintSystem return successful status in case there are problems with nullability
|
||||
// that's why we have to check subtyping manually
|
||||
val substitutor = constraintSystem.getResultingSubstitutor()
|
||||
|
||||
12
idea/idea-completion/testData/basic/common/extensions/ComplexCapture.kt
vendored
Normal file
12
idea/idea-completion/testData/basic/common/extensions/ComplexCapture.kt
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
trait I<T>
|
||||
|
||||
fun <E, T : I<E>> T.ext() : T = this
|
||||
|
||||
class A<T> : I<T>
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = A<Int>()
|
||||
a.<caret>
|
||||
}
|
||||
|
||||
// EXIST: ext
|
||||
11
idea/idea-completion/testData/basic/common/extensions/ComplexCapture2.kt
vendored
Normal file
11
idea/idea-completion/testData/basic/common/extensions/ComplexCapture2.kt
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
interface D<T>
|
||||
|
||||
fun <T1, T2 : D<T1>> T2.ext() {}
|
||||
|
||||
class C : D<String> {
|
||||
fun foo() {
|
||||
this.<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// EXIST: ext
|
||||
@@ -1176,6 +1176,18 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common/extensions"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("ComplexCapture.kt")
|
||||
public void testComplexCapture() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ComplexCapture.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ComplexCapture2.kt")
|
||||
public void testComplexCapture2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ComplexCapture2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionInExtendedClass.kt")
|
||||
public void testExtensionInExtendedClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
||||
|
||||
@@ -1176,6 +1176,18 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common/extensions"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("ComplexCapture.kt")
|
||||
public void testComplexCapture() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ComplexCapture.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ComplexCapture2.kt")
|
||||
public void testComplexCapture2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ComplexCapture2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionInExtendedClass.kt")
|
||||
public void testExtensionInExtendedClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user