Move lambda out: don't apply to multiple/default functional parameters
So #KT-24694 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a9c91099a4
commit
3e207fd6b2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user