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,
|
val type: JetType,
|
||||||
freeParameters: Collection<TypeParameterDescriptor>
|
freeParameters: Collection<TypeParameterDescriptor>
|
||||||
) {
|
) {
|
||||||
private val usedTypeParameters: HashSet<TypeParameterDescriptor>?
|
|
||||||
public val freeParameters: Set<TypeParameterDescriptor>
|
public val freeParameters: Set<TypeParameterDescriptor>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (freeParameters.isNotEmpty()) {
|
if (freeParameters.isNotEmpty()) {
|
||||||
usedTypeParameters = HashSet()
|
val usedTypeParameters = HashSet<TypeParameterDescriptor>()
|
||||||
usedTypeParameters.addUsedTypeParameters(type)
|
usedTypeParameters.addUsedTypeParameters(type)
|
||||||
this.freeParameters = freeParameters.filter { it in usedTypeParameters }.toSet()
|
this.freeParameters = freeParameters.filter { it in usedTypeParameters }.toSet()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
usedTypeParameters = null
|
this.freeParameters = emptySet()
|
||||||
this.freeParameters = setOf()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +65,11 @@ class FuzzyType(
|
|||||||
override fun hashCode() = type.hashCode()
|
override fun hashCode() = type.hashCode()
|
||||||
|
|
||||||
private fun MutableSet<TypeParameterDescriptor>.addUsedTypeParameters(type: JetType) {
|
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()) {
|
for (argument in type.getArguments()) {
|
||||||
addUsedTypeParameters(argument.getType())
|
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
|
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())
|
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
|
// currently ConstraintSystem return successful status in case there are problems with nullability
|
||||||
// that's why we have to check subtyping manually
|
// that's why we have to check subtyping manually
|
||||||
val substitutor = constraintSystem.getResultingSubstitutor()
|
val substitutor = constraintSystem.getResultingSubstitutor()
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
interface D<T>
|
||||||
|
|
||||||
|
fun <T1, T2 : D<T1>> T2.ext() {}
|
||||||
|
|
||||||
|
class C : D<String> {
|
||||||
|
fun foo() {
|
||||||
|
this.<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: ext
|
||||||
+12
@@ -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);
|
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")
|
@TestMetadata("ExtensionInExtendedClass.kt")
|
||||||
public void testExtensionInExtendedClass() throws Exception {
|
public void testExtensionInExtendedClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
||||||
|
|||||||
+12
@@ -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);
|
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")
|
@TestMetadata("ExtensionInExtendedClass.kt")
|
||||||
public void testExtensionInExtendedClass() throws Exception {
|
public void testExtensionInExtendedClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/extensions/ExtensionInExtendedClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user