From c149e956cc164f916def95c91a03bd95775c3456 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Thu, 8 Jun 2017 13:04:51 +0300 Subject: [PATCH] Replace explicit parameter isn't shown on destructuring declaration So #KT-17026 Fixed --- .../ReplaceExplicitFunctionLiteralParamWithItIntention.kt | 3 ++- .../notApplicable_hasDestructuringDeclaration.kt | 4 ++++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/replaceExplicitFunctionLiteralParamWithIt/notApplicable_hasDestructuringDeclaration.kt 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");