Allow to move suspend lambda out of parentheses
#KT-26674 Fixed #KT-26676 Fixed
This commit is contained in:
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiWhiteSpace
|
|||||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
|
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
|
||||||
import com.intellij.psi.tree.IElementType
|
import com.intellij.psi.tree.IElementType
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
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.descriptors.*
|
||||||
import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
|
import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
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 there are functions among candidates but none of them have last function parameter then not show the intention
|
||||||
if (candidates.isNotEmpty() && candidates.none { candidate ->
|
if (candidates.isNotEmpty() && candidates.none { candidate ->
|
||||||
val params = candidate.valueParameters
|
val params = candidate.valueParameters
|
||||||
params.lastOrNull()?.type?.isFunctionType == true &&
|
params.lastOrNull()?.type?.isFunctionOrSuspendFunctionType == true &&
|
||||||
params.count { it.type.isFunctionType } == lambdaArgumentCount + referenceArgumentCount
|
params.count { it.type.isFunctionOrSuspendFunctionType } == lambdaArgumentCount + referenceArgumentCount
|
||||||
}
|
}
|
||||||
) return false
|
) return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun runSuspend(block: suspend () -> Unit) {}
|
||||||
|
|
||||||
|
fun println() {}
|
||||||
|
|
||||||
|
fun usage() {
|
||||||
|
runSuspend(<caret>{ println() })
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun runSuspend(block: suspend () -> Unit) {}
|
||||||
|
|
||||||
|
fun println() {}
|
||||||
|
|
||||||
|
fun usage() {
|
||||||
|
runSuspend { println() }
|
||||||
|
}
|
||||||
@@ -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() {
|
||||||
|
<caret>runSuspendOld { println() }
|
||||||
|
}
|
||||||
@@ -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() }
|
||||||
|
}
|
||||||
+5
@@ -3387,6 +3387,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
public void testNoTwoConsequentLambdas() throws Exception {
|
public void testNoTwoConsequentLambdas() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/moveLambdaOutsideParentheses/noTwoConsequentLambdas.kt");
|
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")
|
@TestMetadata("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses")
|
||||||
|
|||||||
@@ -5323,6 +5323,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/stringTemplate.kt");
|
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")
|
@TestMetadata("toOuterClassMethod.kt")
|
||||||
public void testToOuterClassMethod() throws Exception {
|
public void testToOuterClassMethod() throws Exception {
|
||||||
runTest("idea/testData/quickfix/deprecatedSymbolUsage/toOuterClassMethod.kt");
|
runTest("idea/testData/quickfix/deprecatedSymbolUsage/toOuterClassMethod.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user