diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt index 2b7ceb44b22..54167ad351e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/InvertIfConditionIntention.kt @@ -17,9 +17,21 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.tree.IElementType +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor +import org.jetbrains.kotlin.idea.util.isUnit +import org.jetbrains.kotlin.idea.util.psi.patternMatching.matches import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis +import org.jetbrains.kotlin.psi.psiUtil.siblings +import org.jetbrains.kotlin.psi.psiUtil.startOffset +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance +import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull public class InvertIfConditionIntention : JetSelfTargetingIntention(javaClass(), "Invert 'if' condition") { override fun isApplicableTo(element: JetIfExpression, caretOffset: Int): Boolean { @@ -30,10 +42,11 @@ public class InvertIfConditionIntention : JetSelfTargetingIntention() + if (lastStatementInBlock != null) { + val exitStatementAfterIf = if (lastStatementInBlock.isExitStatement()) + lastStatementInBlock + else + exitStatementExecutedAfter(lastStatementInBlock) + if (exitStatementAfterIf != null) { + val first = afterIfInBlock.first() + val last = afterIfInBlock.last() + // build new then branch text from statements after if (will add exit statement if necessary later) + var newIfBodyText = ifExpression.getContainingFile().getText().substring(first.startOffset, last.endOffset).trim() + + // remove statements after if as they are moving under if + block.deleteChildRange(first, last) + + if (lastThenStatement is JetReturnExpression && lastThenStatement.getReturnedExpression() == null) { + lastThenStatement.delete() + } + copyThenBranchAfter(ifExpression) + + // check if we need to add exit statement to then branch + if (exitStatementAfterIf != lastStatementInBlock) { + // don't insert the exit statement, if the new if statement placement has the same exit statement executed after it + val exitAfterNewIf = exitStatementExecutedAfter(ifExpression) + if (exitAfterNewIf == null || !exitAfterNewIf.matches(exitStatementAfterIf)) { + newIfBodyText += "\n" + exitStatementAfterIf.getText() + } + } + + //TODO: no block if single? + ifExpression.replace(factory.createExpressionByPattern("if ($0) { $1 }", newCondition, newIfBodyText)) + return true + } + } + } + } + + + val exitStatement = exitStatementExecutedAfter(ifExpression) ?: return false + + copyThenBranchAfter(ifExpression) + ifExpression.replace(factory.createExpressionByPattern("if ($0) $1", newCondition, exitStatement)) + + return true + } + + private fun copyThenBranchAfter(ifExpression: JetIfExpression) { + val factory = JetPsiFactory(ifExpression) + val thenBranch = ifExpression.getThen() ?: return + if (thenBranch is JetBlockExpression) { + val range = thenBranch.contentRange() + if (range != null) { + ifExpression.getParent().addRangeAfter(range.first, range.second, ifExpression) + ifExpression.getParent().addAfter(factory.createNewLine(), ifExpression) + } + } + else { + ifExpression.getParent().addAfter(thenBranch, ifExpression) + ifExpression.getParent().addAfter(factory.createNewLine(), ifExpression) + } + } + + private fun JetBlockExpression.contentRange(): Pair? { + val first = getLBrace()?.siblings(withItself = false)?.firstOrNull { it !is PsiWhiteSpace } ?: return null + val rBrace = getRBrace() + if (first == rBrace) return null + val last = rBrace!!.siblings(forward = false, withItself = false).first { it !is PsiWhiteSpace } + return Pair(first, last) + } + + private fun exitStatementExecutedAfter(expression: JetExpression): JetExpression? { + val block = expression.getParent() as? JetBlockExpression ?: return null //TODO? + + val lastStatement = block.getStatements().lastIsInstanceOrNull()!! + if (expression != lastStatement) { + if (lastStatement.isExitStatement() && expression.siblings(withItself = false).firstIsInstance() == lastStatement) { + return lastStatement + } + return null + } + + val parent = block.getParent() + when (parent) { + is JetNamedFunction -> { + if (parent.getBodyExpression() == block) { + if (!parent.hasBlockBody()) return null + val returnType = (parent.resolveToDescriptor() as FunctionDescriptor).getReturnType() + if (returnType == null || !returnType.isUnit()) return null + return JetPsiFactory(expression).createExpression("return") + } + } + + is JetContainerNode -> { + val pparent = parent.getParent() + when (pparent) { + is JetLoopExpression -> { + if (block == pparent.getBody()) { + return JetPsiFactory(expression).createExpression("continue") + } + } + + is JetIfExpression -> { + if (block == pparent.getThen() || block == pparent.getElse()) { + return exitStatementExecutedAfter(pparent) + } + } + } + } + } + return null + } + + private fun JetExpression.isExitStatement(): Boolean { + when (this) { + is JetContinueExpression, is JetBreakExpression, is JetThrowExpression, is JetReturnExpression -> return true + else -> return false + } + } + companion object { private val NEGATABLE_OPERATORS = setOf(JetTokens.EQEQ, JetTokens.EXCLEQ, JetTokens.EQEQEQ, JetTokens.EXCLEQEQEQ, JetTokens.IS_KEYWORD, JetTokens.NOT_IS, JetTokens.IN_KEYWORD, @@ -91,7 +238,7 @@ public class InvertIfConditionIntention : JetSelfTargetingIntention { - val operator = expression.getOperationToken() ?: return null + val operator = expression.getOperationToken() if (operator !in NEGATABLE_OPERATORS) return null val left = expression.getLeft() ?: return null val right = expression.getRight() ?: return null diff --git a/idea/testData/intentions/invertIfCondition/functionWithReturnExpression.kt.after b/idea/testData/intentions/invertIfCondition/functionWithReturnExpression.kt.after index 94639b414f9..fa8610ae53c 100644 --- a/idea/testData/intentions/invertIfCondition/functionWithReturnExpression.kt.after +++ b/idea/testData/intentions/invertIfCondition/functionWithReturnExpression.kt.after @@ -1,10 +1,8 @@ fun foo(): Int { val x = 0 - if (x != 1) { - } else { - x + 1 - } + if (x != 1) return x + x + 1 return x } \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/ifExpressionInsideForLoop.kt.after b/idea/testData/intentions/invertIfCondition/ifExpressionInsideForLoop.kt.after index 75e181c964d..740c32f78a2 100644 --- a/idea/testData/intentions/invertIfCondition/ifExpressionInsideForLoop.kt.after +++ b/idea/testData/intentions/invertIfCondition/ifExpressionInsideForLoop.kt.after @@ -3,9 +3,7 @@ fun main() { val list = 1..4 for (x in list) { - if (x != 2) { - } else { - list - } + if (x != 2) continue + list } } \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/ifExpressionWithReturn.kt.after b/idea/testData/intentions/invertIfCondition/ifExpressionWithReturn.kt.after index 847267c7430..79431a5f26e 100644 --- a/idea/testData/intentions/invertIfCondition/ifExpressionWithReturn.kt.after +++ b/idea/testData/intentions/invertIfCondition/ifExpressionWithReturn.kt.after @@ -2,7 +2,7 @@ fun foo(): Int { val x = 0 if (x != 1) { - } else return x + 1 - - return 0 + return 0 + } + return x + 1 } \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn.kt b/idea/testData/intentions/invertIfCondition/ifThenReturn.kt new file mode 100644 index 00000000000..b951c348ac1 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn.kt @@ -0,0 +1,13 @@ +fun foo(): Boolean { + val x = 2 + if (x <= 1) { + bar1() + bar2() + return false + } + bar1() + return true +} + +fun bar1(){} +fun bar2(){} diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn.kt.after b/idea/testData/intentions/invertIfCondition/ifThenReturn.kt.after new file mode 100644 index 00000000000..382a28828a3 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn.kt.after @@ -0,0 +1,13 @@ +fun foo(): Boolean { + val x = 2 + if (x > 1) { + bar1() + return true + } + bar1() + bar2() + return false +} + +fun bar1(){} +fun bar2(){} diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn2.kt b/idea/testData/intentions/invertIfCondition/ifThenReturn2.kt new file mode 100644 index 00000000000..b9f91bfeb25 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn2.kt @@ -0,0 +1,12 @@ +fun foo() { + val x = 2 + if (x <= 1) { + bar1() + bar2() + return + } + bar1() +} + +fun bar1(){} +fun bar2(){} diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn2.kt.after b/idea/testData/intentions/invertIfCondition/ifThenReturn2.kt.after new file mode 100644 index 00000000000..59a8ddecfd2 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn2.kt.after @@ -0,0 +1,12 @@ +fun foo() { + val x = 2 + if (x > 1) { + bar1() + return + } + bar1() + bar2() +} + +fun bar1(){} +fun bar2(){} diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn3.kt b/idea/testData/intentions/invertIfCondition/ifThenReturn3.kt new file mode 100644 index 00000000000..853d42533f4 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn3.kt @@ -0,0 +1,7 @@ +fun foo() { + val x = 2 + if (x <= 1) return + bar() +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn3.kt.after b/idea/testData/intentions/invertIfCondition/ifThenReturn3.kt.after new file mode 100644 index 00000000000..7041045bdac --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn3.kt.after @@ -0,0 +1,8 @@ +fun foo() { + val x = 2 + if (x > 1) { + bar() + } +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn4.kt b/idea/testData/intentions/invertIfCondition/ifThenReturn4.kt new file mode 100644 index 00000000000..930a5bbafa5 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn4.kt @@ -0,0 +1,14 @@ +fun foo(p: Int): Int { + if (p > 0) { + val x = p / 2 + if (x <= 1) return 1 + bar1() + } + else { + bar2() + } + return 2 +} + +fun bar1(){} +fun bar2(){} diff --git a/idea/testData/intentions/invertIfCondition/ifThenReturn4.kt.after b/idea/testData/intentions/invertIfCondition/ifThenReturn4.kt.after new file mode 100644 index 00000000000..a6c18bc6de5 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/ifThenReturn4.kt.after @@ -0,0 +1,17 @@ +fun foo(p: Int): Int { + if (p > 0) { + val x = p / 2 + if (x > 1) { + bar1() + return 2 + } + return 1 + } + else { + bar2() + } + return 2 +} + +fun bar1(){} +fun bar2(){} diff --git a/idea/testData/intentions/invertIfCondition/invertableOperator.kt.after b/idea/testData/intentions/invertIfCondition/invertableOperator.kt.after index 7575021022e..f6179b22167 100644 --- a/idea/testData/intentions/invertIfCondition/invertableOperator.kt.after +++ b/idea/testData/intentions/invertIfCondition/invertableOperator.kt.after @@ -1,4 +1,3 @@ fun main() { - if (true != false) { - } + if (true != false) return } \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatement1.kt b/idea/testData/intentions/invertIfCondition/lastStatement1.kt new file mode 100644 index 00000000000..43c840e0c28 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatement1.kt @@ -0,0 +1,12 @@ +fun foo() { + val x = 2 + if (x > 1) { + // invoke bar1&bar2 + bar1() + bar2() + // done + } +} + +fun bar1(){} +fun bar2(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatement1.kt.after b/idea/testData/intentions/invertIfCondition/lastStatement1.kt.after new file mode 100644 index 00000000000..aae4888fb4e --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatement1.kt.after @@ -0,0 +1,11 @@ +fun foo() { + val x = 2 + if (x <= 1) return + // invoke bar1&bar2 + bar1() + bar2() + // done +} + +fun bar1(){} +fun bar2(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatement2.kt b/idea/testData/intentions/invertIfCondition/lastStatement2.kt new file mode 100644 index 00000000000..19b4c51d372 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatement2.kt @@ -0,0 +1,6 @@ +fun foo() { + val x = 2 + if (x > 1) bar() +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatement2.kt.after b/idea/testData/intentions/invertIfCondition/lastStatement2.kt.after new file mode 100644 index 00000000000..3f9bf6f88bf --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatement2.kt.after @@ -0,0 +1,7 @@ +fun foo() { + val x = 2 + if (x <= 1) return + bar() +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatement3.kt b/idea/testData/intentions/invertIfCondition/lastStatement3.kt new file mode 100644 index 00000000000..4be4ab5be2f --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatement3.kt @@ -0,0 +1,8 @@ +fun foo(p: Int) { + val x = 2 + if (p > 0) { + if (x > 1) bar() + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatement3.kt.after b/idea/testData/intentions/invertIfCondition/lastStatement3.kt.after new file mode 100644 index 00000000000..02a71447802 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatement3.kt.after @@ -0,0 +1,9 @@ +fun foo(p: Int) { + val x = 2 + if (p > 0) { + if (x <= 1) return + bar() + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatementBeforeBreak.kt b/idea/testData/intentions/invertIfCondition/lastStatementBeforeBreak.kt new file mode 100644 index 00000000000..dce66ec1a12 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementBeforeBreak.kt @@ -0,0 +1,13 @@ +fun foo() { + for (i in 1..10) { + if (i > 3) { + if (i > 5) { + bar() + } + break + } + bar() + } +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/lastStatementBeforeBreak.kt.after b/idea/testData/intentions/invertIfCondition/lastStatementBeforeBreak.kt.after new file mode 100644 index 00000000000..4d8a1c42261 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementBeforeBreak.kt.after @@ -0,0 +1,12 @@ +fun foo() { + for (i in 1..10) { + if (i > 3) { + if (i <= 5) break + bar() + break + } + bar() + } +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/lastStatementBeforeContinue.kt b/idea/testData/intentions/invertIfCondition/lastStatementBeforeContinue.kt new file mode 100644 index 00000000000..e702c9da87b --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementBeforeContinue.kt @@ -0,0 +1,13 @@ +fun foo() { + for (i in 1..10) { + if (i > 3) { + if (i > 5) { + bar() + } + continue + } + bar() + } +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/lastStatementBeforeContinue.kt.after b/idea/testData/intentions/invertIfCondition/lastStatementBeforeContinue.kt.after new file mode 100644 index 00000000000..26be5a45985 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementBeforeContinue.kt.after @@ -0,0 +1,12 @@ +fun foo() { + for (i in 1..10) { + if (i > 3) { + if (i <= 5) continue + bar() + continue + } + bar() + } +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/lastStatementBeforeReturn.kt b/idea/testData/intentions/invertIfCondition/lastStatementBeforeReturn.kt new file mode 100644 index 00000000000..e2e846d19ac --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementBeforeReturn.kt @@ -0,0 +1,9 @@ +fun foo(p: Boolean): Boolean { + val x = 2 + if (x > 1) { + bar() + } + return p +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/lastStatementBeforeReturn.kt.after b/idea/testData/intentions/invertIfCondition/lastStatementBeforeReturn.kt.after new file mode 100644 index 00000000000..4051a11ffd5 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementBeforeReturn.kt.after @@ -0,0 +1,8 @@ +fun foo(p: Boolean): Boolean { + val x = 2 + if (x <= 1) return p + bar() + return p +} + +fun bar(){} diff --git a/idea/testData/intentions/invertIfCondition/lastStatementInLambda.kt b/idea/testData/intentions/invertIfCondition/lastStatementInLambda.kt new file mode 100644 index 00000000000..7aa5664f27d --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementInLambda.kt @@ -0,0 +1,9 @@ +fun foo() { + val v: (Int) -> Unit = { + if (it > 1) { + bar() + } + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatementInLambda.kt.after b/idea/testData/intentions/invertIfCondition/lastStatementInLambda.kt.after new file mode 100644 index 00000000000..f91c7a2b413 --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementInLambda.kt.after @@ -0,0 +1,10 @@ +fun foo() { + val v: (Int) -> Unit = { + if (it <= 1) { + } else { + bar() + } + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatementInLoop.kt b/idea/testData/intentions/invertIfCondition/lastStatementInLoop.kt new file mode 100644 index 00000000000..98183ebef7a --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementInLoop.kt @@ -0,0 +1,9 @@ +fun foo() { + for (i in 1..10) { + if (i > 1) { + bar() + } + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatementInLoop.kt.after b/idea/testData/intentions/invertIfCondition/lastStatementInLoop.kt.after new file mode 100644 index 00000000000..dbcdac133dd --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementInLoop.kt.after @@ -0,0 +1,8 @@ +fun foo() { + for (i in 1..10) { + if (i <= 1) continue + bar() + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatementNonUnitMethod.kt b/idea/testData/intentions/invertIfCondition/lastStatementNonUnitMethod.kt new file mode 100644 index 00000000000..d485239f41b --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementNonUnitMethod.kt @@ -0,0 +1,10 @@ +// ERROR: A 'return' expression required in a function with a block body ('{...}') + +fun foo(): Int { + val x = 2 + if (x > 1) { + bar() + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/lastStatementNonUnitMethod.kt.after b/idea/testData/intentions/invertIfCondition/lastStatementNonUnitMethod.kt.after new file mode 100644 index 00000000000..608b00ce24a --- /dev/null +++ b/idea/testData/intentions/invertIfCondition/lastStatementNonUnitMethod.kt.after @@ -0,0 +1,11 @@ +// ERROR: A 'return' expression required in a function with a block body ('{...}') + +fun foo(): Int { + val x = 2 + if (x <= 1) { + } else { + bar() + } +} + +fun bar(){} \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/negatedExpression.kt.after b/idea/testData/intentions/invertIfCondition/negatedExpression.kt.after index e4d069162c8..abb1a8cbe33 100644 --- a/idea/testData/intentions/invertIfCondition/negatedExpression.kt.after +++ b/idea/testData/intentions/invertIfCondition/negatedExpression.kt.after @@ -3,6 +3,5 @@ fun foo(): Boolean { } fun main() { - if (foo()) { - } + if (foo()) return } \ No newline at end of file diff --git a/idea/testData/intentions/invertIfCondition/simple.kt.after b/idea/testData/intentions/invertIfCondition/simple.kt.after index 97f9907aad2..33b3cada69b 100644 --- a/idea/testData/intentions/invertIfCondition/simple.kt.after +++ b/idea/testData/intentions/invertIfCondition/simple.kt.after @@ -3,6 +3,5 @@ fun foo(): Boolean { } fun main() { - if (!foo()) { - } + if (!foo()) return } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index f955c1205b8..c67fafa6742 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -4669,12 +4669,90 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("ifThenReturn.kt") + public void testIfThenReturn() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/ifThenReturn.kt"); + doTest(fileName); + } + + @TestMetadata("ifThenReturn2.kt") + public void testIfThenReturn2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/ifThenReturn2.kt"); + doTest(fileName); + } + + @TestMetadata("ifThenReturn3.kt") + public void testIfThenReturn3() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/ifThenReturn3.kt"); + doTest(fileName); + } + + @TestMetadata("ifThenReturn4.kt") + public void testIfThenReturn4() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/ifThenReturn4.kt"); + doTest(fileName); + } + @TestMetadata("invertableOperator.kt") public void testInvertableOperator() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/invertableOperator.kt"); doTest(fileName); } + @TestMetadata("lastStatement1.kt") + public void testLastStatement1() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatement1.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatement2.kt") + public void testLastStatement2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatement2.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatement3.kt") + public void testLastStatement3() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatement3.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatementBeforeBreak.kt") + public void testLastStatementBeforeBreak() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatementBeforeBreak.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatementBeforeContinue.kt") + public void testLastStatementBeforeContinue() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatementBeforeContinue.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatementBeforeReturn.kt") + public void testLastStatementBeforeReturn() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatementBeforeReturn.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatementInLambda.kt") + public void testLastStatementInLambda() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatementInLambda.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatementInLoop.kt") + public void testLastStatementInLoop() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatementInLoop.kt"); + doTest(fileName); + } + + @TestMetadata("lastStatementNonUnitMethod.kt") + public void testLastStatementNonUnitMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/lastStatementNonUnitMethod.kt"); + doTest(fileName); + } + @TestMetadata("negatedExpression.kt") public void testNegatedExpression() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/invertIfCondition/negatedExpression.kt");