diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt index dee3edb5131..f1503182d68 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/OperatorToFunctionIntention.kt @@ -147,8 +147,8 @@ class OperatorToFunctionIntention : SelfTargetingIntention(KtExpre KtTokens.MULTEQ -> if (functionName == "multAssign") "$0.multAssign($1)" else "$0 = $0.mult($1)" KtTokens.DIVEQ -> if (functionName == "divAssign") "$0.divAssign($1)" else "$0 = $0.div($1)" KtTokens.PERCEQ -> if (functionName == "modAssign") "$0.modAssign($1)" else "$0 = $0.mod($1)" - KtTokens.EQEQ -> if (elemType?.isMarkedNullable() ?: true) "$0?.equals($1) ?: $1 == null" else "$0.equals($1)" - KtTokens.EXCLEQ -> if (elemType?.isMarkedNullable() ?: true) "!($0?.equals($1) ?: $1 == null)" else "!$0.equals($1)" + KtTokens.EQEQ -> if (elemType?.isMarkedNullable() ?: true) "$0?.equals($1) ?: ($1 == null)" else "$0.equals($1)" + KtTokens.EXCLEQ -> if (elemType?.isMarkedNullable() ?: true) "!($0?.equals($1) ?: ($1 == null))" else "!$0.equals($1)" KtTokens.GT -> "$0.compareTo($1) > 0" KtTokens.LT -> "$0.compareTo($1) < 0" KtTokens.GTEQ -> "$0.compareTo($1) >= 0" @@ -249,6 +249,8 @@ class OperatorToFunctionIntention : SelfTargetingIntention(KtExpre result.baseExpression?.let { findCallName(it) } } + is KtParenthesizedExpression -> result.expression?.let { findCallName(it) } + else -> result.getQualifiedElementSelector() as KtSimpleNameExpression? } } diff --git a/idea/testData/intentions/operatorToFunction/binarayNotEqNullable.kt b/idea/testData/intentions/operatorToFunction/binarayNotEqNullable.kt new file mode 100644 index 00000000000..1a4d1cbfc7f --- /dev/null +++ b/idea/testData/intentions/operatorToFunction/binarayNotEqNullable.kt @@ -0,0 +1,5 @@ +fun foo(p1: String?, p2: String?) { + if (p1 != p2) { + + } +} \ No newline at end of file diff --git a/idea/testData/intentions/operatorToFunction/binarayNotEqNullable.kt.after b/idea/testData/intentions/operatorToFunction/binarayNotEqNullable.kt.after new file mode 100644 index 00000000000..cd9a96fa69e --- /dev/null +++ b/idea/testData/intentions/operatorToFunction/binarayNotEqNullable.kt.after @@ -0,0 +1,5 @@ +fun foo(p1: String?, p2: String?) { + if (!(p1?.equals(p2) ?: (p2 == null))) { + + } +} \ No newline at end of file diff --git a/idea/testData/intentions/operatorToFunction/binaryEqEqNonNullable.kt b/idea/testData/intentions/operatorToFunction/binaryEqEqNonNullable.kt new file mode 100644 index 00000000000..b7ad39585fe --- /dev/null +++ b/idea/testData/intentions/operatorToFunction/binaryEqEqNonNullable.kt @@ -0,0 +1,3 @@ +fun foo(a: String, b: String?) { + a == b +} diff --git a/idea/testData/intentions/operatorToFunction/binaryEqEqNonNullable.kt.after b/idea/testData/intentions/operatorToFunction/binaryEqEqNonNullable.kt.after new file mode 100644 index 00000000000..c8bd64414c3 --- /dev/null +++ b/idea/testData/intentions/operatorToFunction/binaryEqEqNonNullable.kt.after @@ -0,0 +1,3 @@ +fun foo(a: String, b: String?) { + a.equals(b) +} diff --git a/idea/testData/intentions/operatorToFunction/binaryEqualsEqualsNullableOperands.kt b/idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt similarity index 100% rename from idea/testData/intentions/operatorToFunction/binaryEqualsEqualsNullableOperands.kt rename to idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt diff --git a/idea/testData/intentions/operatorToFunction/binaryEqualsEqualsNullableOperands.kt.after b/idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt.after similarity index 52% rename from idea/testData/intentions/operatorToFunction/binaryEqualsEqualsNullableOperands.kt.after rename to idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt.after index 9c324271e37..d94da626340 100644 --- a/idea/testData/intentions/operatorToFunction/binaryEqualsEqualsNullableOperands.kt.after +++ b/idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt.after @@ -1,3 +1,3 @@ fun foo(a: String?, b: String?) { - a?.equals(b) ?: b == null + a?.equals(b) ?: (b == null) } diff --git a/idea/testData/intentions/operatorToFunction/binaryNotEqualsNonNullableOperands.kt b/idea/testData/intentions/operatorToFunction/binaryNotEqNonNullable.kt similarity index 100% rename from idea/testData/intentions/operatorToFunction/binaryNotEqualsNonNullableOperands.kt rename to idea/testData/intentions/operatorToFunction/binaryNotEqNonNullable.kt diff --git a/idea/testData/intentions/operatorToFunction/binaryNotEqualsNonNullableOperands.kt.after b/idea/testData/intentions/operatorToFunction/binaryNotEqNonNullable.kt.after similarity index 100% rename from idea/testData/intentions/operatorToFunction/binaryNotEqualsNonNullableOperands.kt.after rename to idea/testData/intentions/operatorToFunction/binaryNotEqNonNullable.kt.after diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 49f5384f44b..43b49233342 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -6896,15 +6896,27 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } - @TestMetadata("binaryEqualsEqualsNullableOperands.kt") - public void testBinaryEqualsEqualsNullableOperands() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqualsEqualsNullableOperands.kt"); + @TestMetadata("binarayNotEqNullable.kt") + public void testBinarayNotEqNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binarayNotEqNullable.kt"); doTest(fileName); } - @TestMetadata("binaryNotEqualsNonNullableOperands.kt") - public void testBinaryNotEqualsNonNullableOperands() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryNotEqualsNonNullableOperands.kt"); + @TestMetadata("binaryEqEqNonNullable.kt") + public void testBinaryEqEqNonNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNonNullable.kt"); + doTest(fileName); + } + + @TestMetadata("binaryEqEqNullable.kt") + public void testBinaryEqEqNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryEqEqNullable.kt"); + doTest(fileName); + } + + @TestMetadata("binaryNotEqNonNullable.kt") + public void testBinaryNotEqNonNullable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/operatorToFunction/binaryNotEqNonNullable.kt"); doTest(fileName); }