diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiUtil.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtPsiUtil.java index da1b44f87c2..fe5bbc31771 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 || innerExpression.getFirstChild() instanceof KtLambdaExpression) { + if (innerExpression instanceof KtLambdaExpression) { PsiElement prevSibling = PsiTreeUtil.skipWhitespacesAndCommentsBackward(currentInner); if (prevSibling != null && prevSibling.getText().endsWith(KtTokens.RPAR.getValue())) return true; } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt index 856c830727b..ee7869a310c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveUnnecessaryParenthesesIntention.kt @@ -19,10 +19,11 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange import org.jetbrains.kotlin.idea.util.CommentSaver -import org.jetbrains.kotlin.psi.KtParenthesizedExpression -import org.jetbrains.kotlin.psi.KtPsiUtil +import org.jetbrains.kotlin.psi.* -class RemoveUnnecessaryParenthesesIntention : SelfTargetingRangeIntention(KtParenthesizedExpression::class.java, "Remove unnecessary parentheses") { +class RemoveUnnecessaryParenthesesIntention : SelfTargetingRangeIntention( + KtParenthesizedExpression::class.java, "Remove unnecessary parentheses" +) { override fun applicabilityRange(element: KtParenthesizedExpression): TextRange? { element.expression ?: return null if (!KtPsiUtil.areParenthesesUseless(element)) return null @@ -31,7 +32,11 @@ class RemoveUnnecessaryParenthesesIntention : SelfTargetingRangeIntention(KtDotQualifiedExpression::class.java, "Replace 'contains' call with 'in' operator"), HighPriorityAction { +class ReplaceContainsIntention : SelfTargetingRangeIntention( + KtDotQualifiedExpression::class.java, "Replace 'contains' call with 'in' operator" +), HighPriorityAction { override fun applicabilityRange(element: KtDotQualifiedExpression): TextRange? { if (element.calleeName != OperatorNameConventions.CONTAINS.asString()) return null @@ -61,19 +63,13 @@ class ReplaceContainsIntention : SelfTargetingRangeIntention({ foo() } as? () -> Unit) diff --git a/idea/testData/intentions/removeUnnecessaryParentheses/lambda2.kt.after b/idea/testData/intentions/removeUnnecessaryParentheses/lambda2.kt.after new file mode 100644 index 00000000000..b69b037592f --- /dev/null +++ b/idea/testData/intentions/removeUnnecessaryParentheses/lambda2.kt.after @@ -0,0 +1,6 @@ +fun main() { + foo(); + { foo() } as? () -> Unit +} + +fun foo() {} diff --git a/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt b/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt index 5b23af4e675..7234fd23345 100644 --- a/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt +++ b/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt @@ -1,5 +1,3 @@ -// IS_APPLICABLE: false - fun main() { foo() ({ foo() }.invoke()) diff --git a/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt.after b/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt.after new file mode 100644 index 00000000000..78f9fd4cd6b --- /dev/null +++ b/idea/testData/intentions/removeUnnecessaryParentheses/lambda3.kt.after @@ -0,0 +1,6 @@ +fun main() { + foo(); + { foo() }.invoke() +} + +fun foo() {}