diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiUtil.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiUtil.java index fe5bbc31771..da1b44f87c2 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiUtil.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiUtil.java @@ -448,7 +448,7 @@ public class KtPsiUtil { } } - if (innerExpression instanceof KtLambdaExpression) { + if (innerExpression instanceof KtLambdaExpression || innerExpression.getFirstChild() instanceof KtLambdaExpression) { PsiElement prevSibling = PsiTreeUtil.skipWhitespacesAndCommentsBackward(currentInner); if (prevSibling != null && prevSibling.getText().endsWith(KtTokens.RPAR.getValue())) return true; } diff --git a/idea/testData/intentions/removeUnnecessaryParentheses/lambda.kt b/idea/testData/intentions/removeUnnecessaryParentheses/lambda.kt new file mode 100644 index 00000000000..de18ea34869 --- /dev/null +++ b/idea/testData/intentions/removeUnnecessaryParentheses/lambda.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false + +fun main() { + foo() + ({ foo() } ) +} + +fun foo() {} diff --git a/idea/testData/intentions/removeUnnecessaryParentheses/lambda2.kt b/idea/testData/intentions/removeUnnecessaryParentheses/lambda2.kt new file mode 100644 index 00000000000..3a7659c8c7d --- /dev/null +++ b/idea/testData/intentions/removeUnnecessaryParentheses/lambda2.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false + +fun main() { + foo() + ({ foo() } as? () -> Unit) +} + +fun foo() {} diff --git a/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt b/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt new file mode 100644 index 00000000000..5b23af4e675 --- /dev/null +++ b/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false + +fun main() { + foo() + ({ foo() }.invoke()) +} + +fun foo() {} diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 58dd6248408..25f1cea17b9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -14274,6 +14274,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/removeUnnecessaryParentheses/elvisRhsEmptyReturn.kt"); } + @TestMetadata("lambda.kt") + public void testLambda() throws Exception { + runTest("idea/testData/intentions/removeUnnecessaryParentheses/lambda.kt"); + } + + @TestMetadata("lambda2.kt") + public void testLambda2() throws Exception { + runTest("idea/testData/intentions/removeUnnecessaryParentheses/lambda2.kt"); + } + + @TestMetadata("lambda3.kt") + public void testLambda3() throws Exception { + runTest("idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt"); + } + @TestMetadata("necessaryParentheses1.kt") public void testNecessaryParentheses1() throws Exception { runTest("idea/testData/intentions/removeUnnecessaryParentheses/necessaryParentheses1.kt");