diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 915cfa2002d..3c51a3ba3d1 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -1093,11 +1093,6 @@ Kotlin - - org.jetbrains.kotlin.idea.intentions.ConvertNegatedBooleanSequenceIntention - Kotlin - - org.jetbrains.kotlin.idea.intentions.ConvertBinaryExpressionWithDemorgansLawIntention Kotlin diff --git a/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/after.kt.template b/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/after.kt.template deleted file mode 100644 index 22bfbbf3006..00000000000 --- a/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/after.kt.template +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean) { - return !(a || b) -} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/before.kt.template b/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/before.kt.template deleted file mode 100644 index 25a1dd503f8..00000000000 --- a/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/before.kt.template +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean) { - return !a && !b -} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/description.html b/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/description.html deleted file mode 100644 index 016e47420d9..00000000000 --- a/idea/resources/intentionDescriptions/ConvertNegatedBooleanSequenceIntention/description.html +++ /dev/null @@ -1,5 +0,0 @@ - - -This intention converts a sequence of negated boolean expressions with the De Morgan equivalent. - - \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt deleted file mode 100644 index 924a81d16a3..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertNegatedBooleanSequenceIntention.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.intentions - -import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.psi.* -import java.util.* - -class ConvertNegatedBooleanSequenceIntention : SelfTargetingOffsetIndependentIntention( - KtBinaryExpression::class.java, "Replace negated sequence with DeMorgan equivalent" -) { - override fun isApplicableTo(element: KtBinaryExpression): Boolean { - if (element.parent is KtBinaryExpression) return false // operate only on the longest sequence - val opToken = element.operationToken - if (opToken != KtTokens.ANDAND && opToken != KtTokens.OROR) return false - - return splitBooleanSequence(element) != null - } - - override fun applyTo(element: KtBinaryExpression, editor: Editor?) { - val operatorText = when(element.operationToken) { - KtTokens.ANDAND -> KtTokens.OROR.value - KtTokens.OROR -> KtTokens.ANDAND.value - else -> throw IllegalArgumentException() // checked in isApplicableTo - } - - val elements = splitBooleanSequence(element)!! - val bareExpressions = elements.map { prefixExpression -> prefixExpression.baseExpression!!.text } - val negatedExpression = bareExpressions.subList(0, bareExpressions.lastIndex).foldRight( - "!(${bareExpressions.last()}", { negated, expression -> "$expression $operatorText $negated" } - ) - - val newExpression = KtPsiFactory(element).createExpression("$negatedExpression)") - - val insertedElement = element.replace(newExpression) - val insertedElementParent = insertedElement.parent as? KtParenthesizedExpression ?: return - - if (KtPsiUtil.areParenthesesUseless(insertedElementParent)) { - insertedElementParent.replace(insertedElement) - } - } - - private fun splitBooleanSequence(expression: KtBinaryExpression): List? { - val itemList = LinkedList() - val firstOperator = expression.operationToken - - var currentItem: KtBinaryExpression? = expression - while (currentItem != null) { - if (currentItem.operationToken != firstOperator) return null //Boolean sequence must be homogeneous - - val rightChild = currentItem.right as? KtPrefixExpression ?: return null - itemList.add(rightChild) - - val leftChild = currentItem.left - when (leftChild) { - is KtPrefixExpression -> itemList.add(leftChild) - !is KtBinaryExpression -> return null - } - - currentItem = leftChild as? KtBinaryExpression - } - - return itemList - } - -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/.intention b/idea/testData/intentions/convertNegatedBooleanSequence/.intention deleted file mode 100644 index 0da6d8bfd89..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.ConvertNegatedBooleanSequenceIntention diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/complexNegatedSequence.kt b/idea/testData/intentions/convertNegatedBooleanSequence/complexNegatedSequence.kt deleted file mode 100644 index a4e0a5d42e0..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/complexNegatedSequence.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Int, b: Int, c: Int, d: Int) : Boolean { - return !(a == b) && !(b == c) && !(a < d) -} \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/complexNegatedSequence.kt.after b/idea/testData/intentions/convertNegatedBooleanSequence/complexNegatedSequence.kt.after deleted file mode 100644 index 9eb2e005b14..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/complexNegatedSequence.kt.after +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Int, b: Int, c: Int, d: Int) : Boolean { - return !((a == b) || (b == c) || (a < d)) -} \ No newline at end of file diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfThreeNegations.kt b/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfThreeNegations.kt deleted file mode 100644 index 291e81decc3..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfThreeNegations.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean, c: Boolean): Boolean { - return !a && !b && !c -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfThreeNegations.kt.after b/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfThreeNegations.kt.after deleted file mode 100644 index 774720db8d4..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfThreeNegations.kt.after +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean, c: Boolean): Boolean { - return !(a || b || c) -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfTwoNegations.kt b/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfTwoNegations.kt deleted file mode 100644 index b52ded667f9..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfTwoNegations.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean): Boolean { - return !a && !b -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfTwoNegations.kt.after b/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfTwoNegations.kt.after deleted file mode 100644 index d229f5ba5cf..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfTwoNegations.kt.after +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean): Boolean { - return !(a || b) -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/disjunctionOfTwoNegations.kt b/idea/testData/intentions/convertNegatedBooleanSequence/disjunctionOfTwoNegations.kt deleted file mode 100644 index f8c5bad0a57..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/disjunctionOfTwoNegations.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean): Boolean { - return !a || !b -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/disjunctionOfTwoNegations.kt.after b/idea/testData/intentions/convertNegatedBooleanSequence/disjunctionOfTwoNegations.kt.after deleted file mode 100644 index 4fb8be5ca42..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/disjunctionOfTwoNegations.kt.after +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean): Boolean { - return !(a && b) -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/doubleParenthesizedExpression.kt b/idea/testData/intentions/convertNegatedBooleanSequence/doubleParenthesizedExpression.kt deleted file mode 100644 index 940d2489ad2..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/doubleParenthesizedExpression.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean, c: Boolean): Boolean { - return !(a && b) || !(a || c) -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/doubleParenthesizedExpression.kt.after b/idea/testData/intentions/convertNegatedBooleanSequence/doubleParenthesizedExpression.kt.after deleted file mode 100644 index ae75f1ce840..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/doubleParenthesizedExpression.kt.after +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean, c: Boolean): Boolean { - return !((a && b) && (a || c)) -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedOperators.kt b/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedOperators.kt deleted file mode 100644 index b32e0c26513..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedOperators.kt +++ /dev/null @@ -1,4 +0,0 @@ -// IS_APPLICABLE: false -fun foo(a: Boolean, b: Boolean, c: Boolean): Boolean { - return !a && !b || !c -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedSequence.kt b/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedSequence.kt deleted file mode 100644 index 5cca24ba936..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedSequence.kt +++ /dev/null @@ -1,4 +0,0 @@ -// IS_APPLICABLE: false -fun foo(a: Boolean, b: Boolean): Boolean { - return !a && b -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt b/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt deleted file mode 100644 index 3b96d315304..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt +++ /dev/null @@ -1,4 +0,0 @@ -// IS_APPLICABLE: false -fun foo(a: Boolean): Boolean { - return !a -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/negatedFunction.kt b/idea/testData/intentions/convertNegatedBooleanSequence/negatedFunction.kt deleted file mode 100644 index 0320d57403d..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/negatedFunction.kt +++ /dev/null @@ -1,11 +0,0 @@ -fun bar1(): Boolean { - return true -} - -fun bar2(): Boolean { - return false -} - -fun foo(): Boolean { - return !bar1() && !bar2() -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/negatedFunction.kt.after b/idea/testData/intentions/convertNegatedBooleanSequence/negatedFunction.kt.after deleted file mode 100644 index da0dbeb5f57..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/negatedFunction.kt.after +++ /dev/null @@ -1,11 +0,0 @@ -fun bar1(): Boolean { - return true -} - -fun bar2(): Boolean { - return false -} - -fun foo(): Boolean { - return !(bar1() || bar2()) -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/parenthesizedConjunctionOfTwoNegations.kt b/idea/testData/intentions/convertNegatedBooleanSequence/parenthesizedConjunctionOfTwoNegations.kt deleted file mode 100644 index dabf8cdd5bd..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/parenthesizedConjunctionOfTwoNegations.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean): Boolean { - return (!a && !b) -} diff --git a/idea/testData/intentions/convertNegatedBooleanSequence/parenthesizedConjunctionOfTwoNegations.kt.after b/idea/testData/intentions/convertNegatedBooleanSequence/parenthesizedConjunctionOfTwoNegations.kt.after deleted file mode 100644 index d229f5ba5cf..00000000000 --- a/idea/testData/intentions/convertNegatedBooleanSequence/parenthesizedConjunctionOfTwoNegations.kt.after +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: Boolean, b: Boolean): Boolean { - return !(a || b) -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 871b41ba59a..8000d9f3cc1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -5830,69 +5830,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } - @TestMetadata("idea/testData/intentions/convertNegatedBooleanSequence") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ConvertNegatedBooleanSequence extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - public void testAllFilesPresentInConvertNegatedBooleanSequence() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertNegatedBooleanSequence"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("complexNegatedSequence.kt") - public void testComplexNegatedSequence() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/complexNegatedSequence.kt"); - } - - @TestMetadata("conjunctionOfThreeNegations.kt") - public void testConjunctionOfThreeNegations() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfThreeNegations.kt"); - } - - @TestMetadata("conjunctionOfTwoNegations.kt") - public void testConjunctionOfTwoNegations() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/conjunctionOfTwoNegations.kt"); - } - - @TestMetadata("disjunctionOfTwoNegations.kt") - public void testDisjunctionOfTwoNegations() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/disjunctionOfTwoNegations.kt"); - } - - @TestMetadata("doubleParenthesizedExpression.kt") - public void testDoubleParenthesizedExpression() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/doubleParenthesizedExpression.kt"); - } - - @TestMetadata("inapplicableMixedOperators.kt") - public void testInapplicableMixedOperators() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedOperators.kt"); - } - - @TestMetadata("inapplicableMixedSequence.kt") - public void testInapplicableMixedSequence() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/inapplicableMixedSequence.kt"); - } - - @TestMetadata("inapplicableSingleExpression.kt") - public void testInapplicableSingleExpression() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/inapplicableSingleExpression.kt"); - } - - @TestMetadata("negatedFunction.kt") - public void testNegatedFunction() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/negatedFunction.kt"); - } - - @TestMetadata("parenthesizedConjunctionOfTwoNegations.kt") - public void testParenthesizedConjunctionOfTwoNegations() throws Exception { - runTest("idea/testData/intentions/convertNegatedBooleanSequence/parenthesizedConjunctionOfTwoNegations.kt"); - } - } - @TestMetadata("idea/testData/intentions/convertNullablePropertyToLateinit") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)