diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt index e48db00404b..0caf64adc1f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt @@ -43,8 +43,9 @@ class ReplaceExplicitFunctionLiteralParamWithItIntention : PsiElementBaseIntenti val parameter = functionLiteral.valueParameters.singleOrNull() ?: return false if (parameter.typeReference != null) return false + if (parameter.destructuringDeclaration != null) return false - if (functionLiteral.anyDescendantOfType() { literal -> + if (functionLiteral.anyDescendantOfType { literal -> literal.usesName(element.text) && (!literal.hasParameterSpecification() || literal.usesName("it")) } ) return false diff --git a/idea/testData/intentions/replaceExplicitFunctionLiteralParamWithIt/notApplicable_hasDestructuringDeclaration.kt b/idea/testData/intentions/replaceExplicitFunctionLiteralParamWithIt/notApplicable_hasDestructuringDeclaration.kt new file mode 100644 index 00000000000..b039ad11906 --- /dev/null +++ b/idea/testData/intentions/replaceExplicitFunctionLiteralParamWithIt/notApplicable_hasDestructuringDeclaration.kt @@ -0,0 +1,4 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false + +val list = listOf(Pair(1, 2), Pair(3, 4)).map { (f, s) -> f + s } diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 2cf6e708f5d..f900a5f63a7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -13388,6 +13388,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("notApplicable_hasDestructuringDeclaration.kt") + public void testNotApplicable_hasDestructuringDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceExplicitFunctionLiteralParamWithIt/notApplicable_hasDestructuringDeclaration.kt"); + doTest(fileName); + } + @TestMetadata("notApplicable_hasMultipleParameters.kt") public void testNotApplicable_hasMultipleParameters() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceExplicitFunctionLiteralParamWithIt/notApplicable_hasMultipleParameters.kt");