Introduce Parameter: Add suspend to lambdas with nested suspend-calls

#KT-24712 Fixed
This commit is contained in:
Alexey Sedunov
2018-06-01 21:12:48 +03:00
parent 8a838ab5bb
commit 0ea1784d33
4 changed files with 21 additions and 0 deletions
@@ -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()
}
@@ -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)