Replace explicit parameter with it : correct handling of it from outer lambda #KT-12437 Fixed
(cherry picked from commit cb8fe96)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
b44c94a887
commit
bd8c7577e1
+7
-5
@@ -47,17 +47,19 @@ class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBaseInten
|
||||
if (parameter.typeReference != null) return false
|
||||
|
||||
if (functionLiteral.anyDescendantOfType<KtFunctionLiteral>() { literal ->
|
||||
literal !== functionLiteral &&
|
||||
!literal.hasParameterSpecification() &&
|
||||
literal.anyDescendantOfType<KtSimpleNameExpression> { nameExpr ->
|
||||
nameExpr.getReferencedName() == element.text
|
||||
}
|
||||
literal.usesName(element.text) &&
|
||||
(!literal.hasParameterSpecification() || literal.usesName("it"))
|
||||
} ) return false
|
||||
|
||||
text = "Replace explicit parameter '${parameter.name}' with 'it'"
|
||||
return true
|
||||
}
|
||||
|
||||
private fun KtFunctionLiteral.usesName(name: String): Boolean =
|
||||
anyDescendantOfType<KtSimpleNameExpression> {
|
||||
nameExpr -> nameExpr.getReferencedName() == name
|
||||
}
|
||||
|
||||
override fun startInWriteAction(): Boolean = false
|
||||
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
|
||||
Reference in New Issue
Block a user