Introduce Parameter: Add suspend to lambdas with nested suspend-calls
#KT-24712 Fixed
This commit is contained in:
+4
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.idea.refactoring.isMultiLine
|
||||
import org.jetbrains.kotlin.idea.refactoring.runRefactoringWithPostprocessing
|
||||
import org.jetbrains.kotlin.idea.refactoring.validateElement
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -285,6 +286,9 @@ class KotlinIntroduceParameterDialog private constructor(
|
||||
val returnType = function.typeReference?.text ?: "Unit"
|
||||
|
||||
chosenType = (receiverType?.let { "$it." } ?: "") + "($parameterTypes) -> $returnType"
|
||||
if (KtTokens.SUSPEND_KEYWORD in newDescriptor.modifiers) {
|
||||
chosenType = "${KtTokens.SUSPEND_KEYWORD} $chosenType"
|
||||
}
|
||||
newArgumentValue = createLambdaForArgument(function)
|
||||
newReplacer = { }
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_DEFAULT_VALUE: false
|
||||
suspend fun foo(n: Int) = n
|
||||
|
||||
suspend fun test() {
|
||||
val m = <selection>foo(1)</selection>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_DEFAULT_VALUE: false
|
||||
suspend fun foo(n: Int) = n
|
||||
|
||||
suspend fun test(i: suspend () -> Int) {
|
||||
val m = i()
|
||||
}
|
||||
+5
@@ -3557,6 +3557,11 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
||||
runTest("idea/testData/refactoring/introduceLambdaParameter/lambdaParamWithDefaultValue.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendCalls.kt")
|
||||
public void testSuspendCalls() throws Exception {
|
||||
runTest("idea/testData/refactoring/introduceLambdaParameter/suspendCalls.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/refactoring/introduceLambdaParameter/multiline")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user