Move lambda out: don't apply to multiple/default functional parameters

So #KT-24694 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-06-26 17:43:59 +03:00
committed by Mikhail Glukhikh
parent a9c91099a4
commit 3e207fd6b2
5 changed files with 40 additions and 5 deletions
@@ -131,6 +131,7 @@ fun KtCallExpression.canMoveLambdaOutsideParentheses(): Boolean {
val callee = calleeExpression
if (callee is KtNameReferenceExpression) {
val lambdaArgumentCount = valueArguments.mapNotNull { it.getArgumentExpression()?.unpackFunctionLiteral() }.count()
val bindingContext = analyze(BodyResolveMode.PARTIAL)
val targets = bindingContext[BindingContext.REFERENCE_TARGET, callee]?.let { listOf(it) }
?: bindingContext[BindingContext.AMBIGUOUS_REFERENCE_TARGET, callee]
@@ -138,11 +139,9 @@ fun KtCallExpression.canMoveLambdaOutsideParentheses(): Boolean {
val candidates = targets.filterIsInstance<FunctionDescriptor>()
// if there are functions among candidates but none of them have last function parameter then not show the intention
if (candidates.isNotEmpty() && candidates.none {
val lastParameter = it.valueParameters.lastOrNull()
lastParameter != null && lastParameter.type.isFunctionType
}) {
return false
}
val params = it.valueParameters
params.lastOrNull()?.type?.isFunctionType == true && params.count { it.type.isFunctionType } == lambdaArgumentCount
}) return false
}
return true