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:
Valentin Kipyatkov
2015-06-12 01:07:53 +03:00
parent 0877c09b80
commit 4deefce603
5 changed files with 58 additions and 7 deletions

View File

@@ -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()

View 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

View 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

View File

@@ -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");

View File

@@ -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");