Smart completion works in initializer of variable with unknown type (the same as ordinary completion)
#KT-8691 Fixed
This commit is contained in:
+4
-7
@@ -110,12 +110,7 @@ class SmartCompletion(
|
||||
val asTypePositionResult = buildForAsTypePosition()
|
||||
if (asTypePositionResult != null) return asTypePositionResult
|
||||
|
||||
val expressionWithType = if (receiver != null) {
|
||||
expression.getParent() as? JetExpression ?: return null
|
||||
}
|
||||
else {
|
||||
expression
|
||||
}
|
||||
val expressionWithType = expression.toExpressionWithType()
|
||||
|
||||
var originalExpectedInfos = calcExpectedInfos(expressionWithType) ?: return null
|
||||
originalExpectedInfos = originalExpectedInfos.filterNot { it.fuzzyType?.type?.isError ?: false }
|
||||
@@ -207,7 +202,9 @@ class SmartCompletion(
|
||||
if (originalDeclaration != null) {
|
||||
val originalDescriptor = originalDeclaration.resolveToDescriptor() as? CallableDescriptor
|
||||
val returnType = originalDescriptor?.getReturnType()
|
||||
return if (returnType != null) listOf(ExpectedInfo(returnType, declaration.getName(), null)) else null
|
||||
if (returnType != null && !returnType.isError) {
|
||||
return listOf(ExpectedInfo(returnType, declaration.getName(), null))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class C
|
||||
|
||||
fun foo(p1: String, p2: Int) {
|
||||
val v = <caret>
|
||||
}
|
||||
|
||||
// EXIST: p1
|
||||
// EXIST: p2
|
||||
// ABSENT: C
|
||||
@@ -0,0 +1,13 @@
|
||||
interface I {
|
||||
fun takeXxx(): Int = 0
|
||||
fun takeYyy(): Int = 0
|
||||
fun takeZzz(): Int = 0
|
||||
}
|
||||
|
||||
fun foo(i: I) {
|
||||
val yyy = i.take<caret>
|
||||
}
|
||||
|
||||
// ORDER: takeYyy
|
||||
// ORDER: takeXxx
|
||||
// ORDER: takeZzz
|
||||
+6
@@ -179,6 +179,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ImplicitlyTypedValInitializerUnknownType.kt")
|
||||
public void testImplicitlyTypedValInitializerUnknownType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/ImplicitlyTypedValInitializerUnknownType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("InClassObject.kt")
|
||||
public void testInClassObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/smart/InClassObject.kt");
|
||||
|
||||
+6
@@ -185,6 +185,12 @@ public class SmartCompletionWeigherTestGenerated extends AbstractSmartCompletion
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoExpectedType.kt")
|
||||
public void testNoExpectedType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/smart/NoExpectedType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoNameSimilarityForQualifier.kt")
|
||||
public void testNoNameSimilarityForQualifier() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/smart/NoNameSimilarityForQualifier.kt");
|
||||
|
||||
Reference in New Issue
Block a user