From 8842bb574cae5c49c3cce1685b4c01a19c3b997b Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 7 Jul 2014 21:18:25 +0400 Subject: [PATCH] KT-5397 Simplify text of DeMorgan law conversion intentions #KT-5397 --- .../org/jetbrains/jet/plugin/JetBundle.properties | 6 ++++-- ...vertNegatedExpressionWithDemorgansLawIntention.kt | 12 +++++++----- .../conjunctionNegation1.kt | 2 ++ .../conjunctionNegation1.kt.after | 2 ++ .../conjunctionNegation2.kt | 2 ++ .../conjunctionNegation2.kt.after | 2 ++ .../disjunctionNegation1.kt | 2 ++ .../disjunctionNegation1.kt.after | 2 ++ .../disjunctionNegation2.kt | 2 ++ .../disjunctionNegation2.kt.after | 2 ++ 10 files changed, 27 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index 62aa43d0f39..1e4f6f112f6 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -292,8 +292,10 @@ add.braces=Add braces add.braces.family=Add Braces convert.negated.boolean.sequence=Replace negated sequence with DeMorgan equivalent convert.negated.boolean.sequence.family=Replace Negated Sequence with DeMorgan Equivalent -convert.negated.expression.with.demorgans.law=Convert negated expression to DeMorgan equivalent -convert.negated.expression.with.demorgans.law.family=Convert Negated Expression to DeMorgan Equivalent +convert.negated.expression.with.demorgans.law=DeMorgan Law +convert.negated.expression.with.demorgans.law.andToOr=Replace '\\&\\&' with '||' +convert.negated.expression.with.demorgans.law.orToAnd=Replace '||' with '\\&\\&' +convert.negated.expression.with.demorgans.law.family=DeMorgan Law split.if=Split into 2 if's split.if.family=Split If replace.with.operator.assign.intention=Replace with an operator-assign expression diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt index 6a75fbb403c..bd725605526 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertNegatedExpressionWithDemorgansLawIntention.kt @@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.psi.JetConstantExpression import org.jetbrains.jet.lang.psi.JetSimpleNameExpression import java.util.ArrayList import java.util.LinkedList +import org.jetbrains.jet.plugin.JetBundle public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetingIntention( "convert.negated.expression.with.demorgans.law", javaClass() @@ -41,10 +42,11 @@ public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetin val parenthesizedExpression = element.getBaseExpression() as? JetParenthesizedExpression val baseExpression = parenthesizedExpression?.getExpression() as? JetBinaryExpression ?: return false - val operatorToken = baseExpression.getOperationToken() ?: return false - if (!(operatorToken == JetTokens.ANDAND || operatorToken == JetTokens.OROR)) { - return false + when (baseExpression.getOperationToken()) { + JetTokens.ANDAND -> setText(JetBundle.message("convert.negated.expression.with.demorgans.law.andToOr")) + JetTokens.OROR -> setText(JetBundle.message("convert.negated.expression.with.demorgans.law.orToAnd")) + else -> return false } val elements = splitBooleanSequence(baseExpression) ?: return false @@ -54,7 +56,7 @@ public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetin override fun applyTo(element: JetPrefixExpression, editor: Editor) { val parenthesizedExpression = element.getBaseExpression() as JetParenthesizedExpression val baseExpression = parenthesizedExpression.getExpression() as JetBinaryExpression - val operatorText = when(baseExpression.getOperationToken()) { + val operatorText = when (baseExpression.getOperationToken()) { JetTokens.ANDAND -> JetTokens.OROR.getValue() JetTokens.OROR -> JetTokens.ANDAND.getValue() else -> throw IllegalArgumentException( @@ -70,7 +72,7 @@ public class ConvertNegatedExpressionWithDemorgansLawIntention : JetSelfTargetin } fun handleSpecial(expression: JetExpression): String { - return when(expression) { + return when (expression) { is JetSimpleNameExpression, is JetConstantExpression, is JetPrefixExpression, is JetParenthesizedExpression -> "!${expression.getText()}" else -> "!(${expression.getText()})" diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt index a5481eb8c08..9561b64422e 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '&&' with '||' + fun foo(a: Boolean, b: Boolean) : Boolean { return !(a && b) } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt.after b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt.after index 3112d8d05a8..02405605911 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt.after +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation1.kt.after @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '&&' with '||' + fun foo(a: Boolean, b: Boolean) : Boolean { return !a || !b } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt index 69a930622af..e6243d9487e 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '&&' with '||' + fun foo(a: Boolean, b: Boolean, c: Boolean) : Boolean { return !(a && (b && c)) } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt.after b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt.after index 14d4629c3c2..9508b5c455b 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt.after +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/conjunctionNegation2.kt.after @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '&&' with '||' + fun foo(a: Boolean, b: Boolean, c: Boolean) : Boolean { return !a || !(b && c) } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt index 9ae04916fbc..46d4d6c3171 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '||' with '&&' + fun foo(a: Boolean, b: Boolean) : Boolean { return !(a || b) } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt.after b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt.after index 0a4f9bb2ef2..cf27014f385 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt.after +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation1.kt.after @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '||' with '&&' + fun foo(a: Boolean, b: Boolean) : Boolean { return !a && !b } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt index ddc41bdcfba..54b2c3129f4 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '||' with '&&' + fun foo(a: Boolean, b: Boolean, c: Boolean) : Boolean { return !(a || (b && c)) } \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt.after b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt.after index 337443b4075..040f1480cd5 100644 --- a/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt.after +++ b/idea/testData/intentions/convertNegatedExpressionWithDemorgansLaw/disjunctionNegation2.kt.after @@ -1,3 +1,5 @@ +// INTENTION_TEXT: Replace '||' with '&&' + fun foo(a: Boolean, b: Boolean, c: Boolean) : Boolean { return !a && !(b && c) } \ No newline at end of file