Smart completion: no items of unresolved types
This commit is contained in:
@@ -47,7 +47,7 @@ fun buildSmartCompletionData(expression: JetSimpleNameExpression, resolveSession
|
|||||||
|
|
||||||
val bindingContext = resolveSession.resolveToElement(expressionWithType)
|
val bindingContext = resolveSession.resolveToElement(expressionWithType)
|
||||||
val expectedType: JetType? = bindingContext.get(BindingContext.EXPECTED_EXPRESSION_TYPE, expressionWithType)
|
val expectedType: JetType? = bindingContext.get(BindingContext.EXPECTED_EXPRESSION_TYPE, expressionWithType)
|
||||||
if (expectedType == null) return null
|
if (expectedType == null || expectedType.isError()) return null
|
||||||
|
|
||||||
val itemsToSkip = calcItemsToSkip(expressionWithType, resolveSession)
|
val itemsToSkip = calcItemsToSkip(expressionWithType, resolveSession)
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ fun buildSmartCompletionData(expression: JetSimpleNameExpression, resolveSession
|
|||||||
|
|
||||||
return object: SmartCompletionData {
|
return object: SmartCompletionData {
|
||||||
override fun accepts(descriptor: DeclarationDescriptor)
|
override fun accepts(descriptor: DeclarationDescriptor)
|
||||||
= !itemsToSkip.contains(descriptor) && typesOf(descriptor).any { JetTypeChecker.INSTANCE.isSubtypeOf(it, expectedType) }
|
= !itemsToSkip.contains(descriptor) && typesOf(descriptor).any { isSubtypeOf(it, expectedType) }
|
||||||
|
|
||||||
override val additionalElements = additionalElements
|
override val additionalElements = additionalElements
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ private fun thisItems(context: JetExpression, expectedType: JetType, bindingCont
|
|||||||
for (i in 0..receivers.size - 1) {
|
for (i in 0..receivers.size - 1) {
|
||||||
val receiver = receivers[i]
|
val receiver = receivers[i]
|
||||||
val thisType = receiver.getType()
|
val thisType = receiver.getType()
|
||||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(thisType, expectedType)) {
|
if (isSubtypeOf(thisType, expectedType)) {
|
||||||
//TODO: use this code when KT-4258 fixed
|
//TODO: use this code when KT-4258 fixed
|
||||||
//val expressionText = if (i == 0) "this" else "this@" + (thisQualifierName(receiver, bindingContext) ?: continue)
|
//val expressionText = if (i == 0) "this" else "this@" + (thisQualifierName(receiver, bindingContext) ?: continue)
|
||||||
val qualifier = if (i == 0) null else thisQualifierName(receiver, bindingContext) ?: continue
|
val qualifier = if (i == 0) null else thisQualifierName(receiver, bindingContext) ?: continue
|
||||||
@@ -253,7 +253,7 @@ private fun staticMembers(context: JetExpression, expectedType: JetType, resolve
|
|||||||
val descriptors = ArrayList<DeclarationDescriptor>()
|
val descriptors = ArrayList<DeclarationDescriptor>()
|
||||||
|
|
||||||
val isSuitableCallable: (DeclarationDescriptor) -> Boolean = {
|
val isSuitableCallable: (DeclarationDescriptor) -> Boolean = {
|
||||||
it is CallableDescriptor && it.getReturnType()?.let { JetTypeChecker.INSTANCE.isSubtypeOf(it, expectedType) } ?: false
|
it is CallableDescriptor && it.getReturnType()?.let { isSubtypeOf(it, expectedType) } ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classDescriptor is JavaClassDescriptor) {
|
if (classDescriptor is JavaClassDescriptor) {
|
||||||
@@ -296,6 +296,10 @@ private fun staticMembers(context: JetExpression, expectedType: JetType, resolve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isSubtypeOf(t: JetType, expectedType: JetType): Boolean{
|
||||||
|
return !t.isError() && JetTypeChecker.INSTANCE.isSubtypeOf(t, expectedType)
|
||||||
|
}
|
||||||
|
|
||||||
private fun <T : Any> T?.toList(): List<T> = if (this != null) listOf(this) else listOf()
|
private fun <T : Any> T?.toList(): List<T> = if (this != null) listOf(this) else listOf()
|
||||||
|
|
||||||
private fun <T> MutableCollection<T>.addAll(iterator: Iterator<T>) {
|
private fun <T> MutableCollection<T>.addAll(iterator: Iterator<T>) {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
val x: XXX
|
||||||
|
|
||||||
|
val v: String = <caret>
|
||||||
|
|
||||||
|
// ABSENT: x
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
val x: String
|
||||||
|
|
||||||
|
val v: XXX = <caret>
|
||||||
|
|
||||||
|
// ABSENT: x
|
||||||
@@ -216,11 +216,21 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
|||||||
doTest("idea/testData/completion/smart/QualifiedThisOfExtensionLambda3.kt");
|
doTest("idea/testData/completion/smart/QualifiedThisOfExtensionLambda3.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("SkipUnresolvedTypes.kt")
|
||||||
|
public void testSkipUnresolvedTypes() throws Exception {
|
||||||
|
doTest("idea/testData/completion/smart/SkipUnresolvedTypes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("This.kt")
|
@TestMetadata("This.kt")
|
||||||
public void testThis() throws Exception {
|
public void testThis() throws Exception {
|
||||||
doTest("idea/testData/completion/smart/This.kt");
|
doTest("idea/testData/completion/smart/This.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("UnresolvedExpectedType.kt")
|
||||||
|
public void testUnresolvedExpectedType() throws Exception {
|
||||||
|
doTest("idea/testData/completion/smart/UnresolvedExpectedType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("VariableInitializer.kt")
|
@TestMetadata("VariableInitializer.kt")
|
||||||
public void testVariableInitializer() throws Exception {
|
public void testVariableInitializer() throws Exception {
|
||||||
doTest("idea/testData/completion/smart/VariableInitializer.kt");
|
doTest("idea/testData/completion/smart/VariableInitializer.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user