diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt index da203086fe4..8c9ef33d5c3 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt @@ -21,7 +21,7 @@ import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.impl.source.codeStyle.CodeEditUtil import com.intellij.psi.tree.IElementType import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.kotlin.builtins.isFunctionType +import org.jetbrains.kotlin.builtins.isFunctionOrSuspendFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension import org.jetbrains.kotlin.idea.caches.resolve.analyze @@ -135,8 +135,8 @@ fun KtCallExpression.canMoveLambdaOutsideParentheses(): Boolean { // if there are functions among candidates but none of them have last function parameter then not show the intention if (candidates.isNotEmpty() && candidates.none { candidate -> val params = candidate.valueParameters - params.lastOrNull()?.type?.isFunctionType == true && - params.count { it.type.isFunctionType } == lambdaArgumentCount + referenceArgumentCount + params.lastOrNull()?.type?.isFunctionOrSuspendFunctionType == true && + params.count { it.type.isFunctionOrSuspendFunctionType } == lambdaArgumentCount + referenceArgumentCount } ) return false } diff --git a/idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt b/idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt new file mode 100644 index 00000000000..06668ef7f6b --- /dev/null +++ b/idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt @@ -0,0 +1,7 @@ +fun runSuspend(block: suspend () -> Unit) {} + +fun println() {} + +fun usage() { + runSuspend({ println() }) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt.after b/idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt.after new file mode 100644 index 00000000000..4f1fe810b45 --- /dev/null +++ b/idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt.after @@ -0,0 +1,7 @@ +fun runSuspend(block: suspend () -> Unit) {} + +fun println() {} + +fun usage() { + runSuspend { println() } +} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/suspendLambda.kt b/idea/testData/quickfix/deprecatedSymbolUsage/suspendLambda.kt new file mode 100644 index 00000000000..bc2ac6cf157 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/suspendLambda.kt @@ -0,0 +1,11 @@ +// "Replace with 'runSuspend(block)'" "true" + +fun runSuspend(block: suspend () -> Unit) {} +@Deprecated("Use new function", ReplaceWith("runSuspend(block)")) +fun runSuspendOld(block: suspend () -> Unit) = runSuspend(block) + +fun println() {} + +fun usage() { + runSuspendOld { println() } +} \ No newline at end of file diff --git a/idea/testData/quickfix/deprecatedSymbolUsage/suspendLambda.kt.after b/idea/testData/quickfix/deprecatedSymbolUsage/suspendLambda.kt.after new file mode 100644 index 00000000000..a754ba773c6 --- /dev/null +++ b/idea/testData/quickfix/deprecatedSymbolUsage/suspendLambda.kt.after @@ -0,0 +1,11 @@ +// "Replace with 'runSuspend(block)'" "true" + +fun runSuspend(block: suspend () -> Unit) {} +@Deprecated("Use new function", ReplaceWith("runSuspend(block)")) +fun runSuspendOld(block: suspend () -> Unit) = runSuspend(block) + +fun println() {} + +fun usage() { + runSuspend { println() } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 825d4fd9bac..cbcc018f320 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -3387,6 +3387,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { public void testNoTwoConsequentLambdas() throws Exception { runTest("idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/noTwoConsequentLambdas.kt"); } + + @TestMetadata("suspendLambda.kt") + public void testSuspendLambda() throws Exception { + runTest("idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/suspendLambda.kt"); + } } @TestMetadata("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses") diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 2815ae0b108..126982b7fe1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -5323,6 +5323,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/deprecatedSymbolUsage/stringTemplate.kt"); } + @TestMetadata("suspendLambda.kt") + public void testSuspendLambda() throws Exception { + runTest("idea/testData/quickfix/deprecatedSymbolUsage/suspendLambda.kt"); + } + @TestMetadata("toOuterClassMethod.kt") public void testToOuterClassMethod() throws Exception { runTest("idea/testData/quickfix/deprecatedSymbolUsage/toOuterClassMethod.kt");