Fix NPE on conversion: run/apply with explicit signature -> let/also
So #KT-22949 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f93b21eaa2
commit
55c93bc8b6
@@ -154,6 +154,9 @@ abstract class ConvertScopeFunctionFix(private val counterpartName: String) : Lo
|
||||
val functionLiteral = lambda.getLambdaExpression()?.functionLiteral ?: return
|
||||
val lambdaDescriptor = bindingContext[FUNCTION, functionLiteral] ?: return
|
||||
|
||||
functionLiteral.valueParameterList?.delete()
|
||||
functionLiteral.arrow?.delete()
|
||||
|
||||
val replacements = ReplacementCollection()
|
||||
analyzeLambda(bindingContext, lambda, lambdaDescriptor, replacements)
|
||||
callee.replace(KtPsiFactory(project).createExpression(counterpartName) as KtNameReferenceExpression)
|
||||
@@ -205,6 +208,7 @@ class ConvertScopeFunctionToParameter(counterpartName: String) : ConvertScopeFun
|
||||
lambda.accept(object : KtTreeVisitorVoid() {
|
||||
override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) {
|
||||
super.visitSimpleNameExpression(expression)
|
||||
if (expression is KtOperationReferenceExpression) return
|
||||
val resolvedCall = expression.getResolvedCall(bindingContext) ?: return
|
||||
val dispatchReceiverTarget = resolvedCall.dispatchReceiver?.getReceiverTargetDescriptor(bindingContext)
|
||||
val extensionReceiverTarget = resolvedCall.extensionReceiver?.getReceiverTargetDescriptor(bindingContext)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// FIX: Convert to 'also'
|
||||
|
||||
fun foo() {
|
||||
"".<caret>apply {
|
||||
->
|
||||
println(this)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// FIX: Convert to 'also'
|
||||
|
||||
fun foo() {
|
||||
"".<caret>also {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// FIX: Convert to 'also'
|
||||
|
||||
fun foo() {
|
||||
"".<caret>apply {
|
||||
println(this + this)
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
// FIX: Convert to 'also'
|
||||
|
||||
fun foo() {
|
||||
"".<caret>also {
|
||||
println(it + it)
|
||||
}
|
||||
}
|
||||
+12
@@ -3653,6 +3653,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("arrow.kt")
|
||||
public void testArrow() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/arrow.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("doubleNestedLambdas.kt")
|
||||
public void testDoubleNestedLambdas() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/doubleNestedLambdas.kt");
|
||||
@@ -3689,6 +3695,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("thisInOperation.kt")
|
||||
public void testThisInOperation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/thisInOperation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("thisQualifier.kt")
|
||||
public void testThisQualifier() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/thisQualifier.kt");
|
||||
|
||||
Reference in New Issue
Block a user