diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt index 1ed03ccfb8c..3f1bf43b4bb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/collections/SimplifyCallChainFix.kt @@ -24,8 +24,12 @@ import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty -class SimplifyCallChainFix(val newName: String) : LocalQuickFix { - override fun getName() = "Merge call chain to '$newName'" +class SimplifyCallChainFix(private val newCallText: String) : LocalQuickFix { + private val shortenedText = newCallText.split("(").joinToString(separator = "(") { + it.substringAfterLast(".") + } + + override fun getName() = "Merge call chain to '$shortenedText'" override fun getFamilyName() = name @@ -45,7 +49,7 @@ class SimplifyCallChainFix(val newName: String) : LocalQuickFix { val firstCallExpression = AbstractCallChainChecker.getCallExpression(firstExpression) ?: return val secondCallExpression = secondQualifiedExpression.selectorExpression as? KtCallExpression ?: return - val lastArgumentPrefix = if (newName.startsWith("joinTo")) "transform = " else "" + val lastArgumentPrefix = if (newCallText.startsWith("joinTo")) "transform = " else "" val arguments = secondCallExpression.valueArgumentList?.arguments.orEmpty().map { it.text } + firstCallExpression.valueArgumentList?.arguments.orEmpty().map { "$lastArgumentPrefix${it.text}" } val lambdaExpression = firstCallExpression.lambdaArguments.singleOrNull()?.getLambdaExpression() @@ -55,7 +59,7 @@ class SimplifyCallChainFix(val newName: String) : LocalQuickFix { "$0$1$2 $3 $4", receiverExpression ?: "", operationSign, - newName, + newCallText, argumentsText, lambdaExpression.text ) @@ -63,7 +67,7 @@ class SimplifyCallChainFix(val newName: String) : LocalQuickFix { "$0$1$2 $3", receiverExpression ?: "", operationSign, - newName, + newCallText, argumentsText ) diff --git a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt index c25294b7029..d892a6e11de 100644 --- a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt +++ b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// FIX: Merge call chain to 'withContext' package kotlinx.coroutines diff --git a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt.after b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt.after index 16439deb0be..68ff62364c1 100644 --- a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt.after +++ b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simple.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// FIX: Merge call chain to 'withContext' package kotlinx.coroutines diff --git a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt index 029c3f14adc..94329871a8f 100644 --- a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt +++ b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// FIX: Merge call chain to 'withContext(DefaultDispatcher)' package kotlinx.coroutines diff --git a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt.after b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt.after index c18eed7f57d..4e1cac7e48f 100644 --- a/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt.after +++ b/idea/testData/inspectionsLocal/coroutines/redundantAsync/simplest.kt.after @@ -1,4 +1,5 @@ // WITH_RUNTIME +// FIX: Merge call chain to 'withContext(DefaultDispatcher)' package kotlinx.coroutines