Create from Usage: Infer expected type from base declarations
#KT-17480 Fixed
This commit is contained in:
+7
-1
@@ -222,7 +222,13 @@ fun KtExpression.guessTypes(
|
|||||||
parent is KtNamedFunction && parent.name == null -> parent
|
parent is KtNamedFunction && parent.name == null -> parent
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
if (functionalExpression == null) return arrayOf()
|
if (functionalExpression == null) {
|
||||||
|
functionDescriptor.overriddenDescriptors
|
||||||
|
.mapNotNull { it.returnType }
|
||||||
|
.firstOrNull { isAcceptable(it) }
|
||||||
|
?.let { return arrayOf(it) }
|
||||||
|
return arrayOf()
|
||||||
|
}
|
||||||
val lambdaTypes = functionalExpression.guessTypes(context, module, pseudocode?.parent, coerceUnusedToUnit)
|
val lambdaTypes = functionalExpression.guessTypes(context, module, pseudocode?.parent, coerceUnusedToUnit)
|
||||||
lambdaTypes.mapNotNull { it.getFunctionType()?.arguments?.lastOrNull()?.type }.toTypedArray()
|
lambdaTypes.mapNotNull { it.getFunctionType()?.arguments?.lastOrNull()?.type }.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// "Create class 'XImpl'" "true"
|
||||||
|
interface X
|
||||||
|
interface A {
|
||||||
|
fun f(): X
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A {
|
||||||
|
override fun f() = <caret>XImpl()
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// "Create class 'XImpl'" "true"
|
||||||
|
interface X
|
||||||
|
interface A {
|
||||||
|
fun f(): X
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A {
|
||||||
|
override fun f() = XImpl()
|
||||||
|
}
|
||||||
|
|
||||||
|
class XImpl : X {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1647,6 +1647,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("expectedTypeBySuperFunction.kt")
|
||||||
|
public void testExpectedTypeBySuperFunction() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/expectedTypeBySuperFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("quotedName.kt")
|
@TestMetadata("quotedName.kt")
|
||||||
public void testQuotedName() throws Exception {
|
public void testQuotedName() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/quotedName.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/quotedName.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user