diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java index d0922dcbd7d..4bced467dec 100644 --- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -375,6 +375,7 @@ public class GenerateTests { "idea/tests/", "UnwrapRemoveTestGenerated", AbstractUnwrapRemoveTest.class, + testModel("idea/testData/codeInsight/unwrapAndRemove/removeExpression", "doTestExpressionRemover"), testModel("idea/testData/codeInsight/unwrapAndRemove/unwrapThen", "doTestThenUnwrapper"), testModel("idea/testData/codeInsight/unwrapAndRemove/unwrapElse", "doTestElseUnwrapper"), testModel("idea/testData/codeInsight/unwrapAndRemove/removeElse", "doTestElseRemover"), diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KoitlinUnwrappers.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KoitlinUnwrappers.java index 52d4a760487..09efdafaf22 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KoitlinUnwrappers.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KoitlinUnwrappers.java @@ -26,6 +26,17 @@ public class KoitlinUnwrappers { private KoitlinUnwrappers() { } + public static class KotlinExpressionRemover extends KotlinRemover { + public KotlinExpressionRemover(String key) { + super(key); + } + + @Override + public boolean isApplicableTo(PsiElement e) { + return e instanceof JetExpression && e.getParent() instanceof JetBlockExpression; + } + } + public static class KotlinElseUnwrapper extends KotlinComponentUnwrapper { public KotlinElseUnwrapper(String key) { super(key); diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrapDescriptor.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrapDescriptor.java index a105ac0d978..27be42c648a 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrapDescriptor.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/unwrap/KotlinUnwrapDescriptor.java @@ -23,6 +23,7 @@ public class KotlinUnwrapDescriptor extends UnwrapDescriptorBase { @Override protected Unwrapper[] createUnwrappers() { return new Unwrapper[] { + new KoitlinUnwrappers.KotlinExpressionRemover("remove.expression"), new KoitlinUnwrappers.KotlinThenUnwrapper("unwrap.expression"), new KoitlinUnwrappers.KotlinElseRemover("remove.else"), new KoitlinUnwrappers.KotlinElseUnwrapper("unwrap.else"), diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInBlock.kt b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInBlock.kt new file mode 100644 index 00000000000..4e42512cfd1 --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInBlock.kt @@ -0,0 +1,10 @@ +// OPTION: 0 +fun foo(n : Int): Int { + if (n > 0) { + 1 + } else { + -1 + } + + return 0 +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInBlock.kt.after b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInBlock.kt.after new file mode 100644 index 00000000000..ed009ef6d14 --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInBlock.kt.after @@ -0,0 +1,5 @@ +// OPTION: 0 +fun foo(n : Int): Int { + + return 0 +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInExpressionInReturn.kt b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInExpressionInReturn.kt new file mode 100644 index 00000000000..3526de57020 --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInExpressionInReturn.kt @@ -0,0 +1,9 @@ +// OPTION: 3 +fun foo(n : Int): Int { + return 10 + + if (n > 0) { + 1 + } else { + -1 + } +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInExpressionInReturn.kt.after b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInExpressionInReturn.kt.after new file mode 100644 index 00000000000..eb7c581f4cc --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInExpressionInReturn.kt.after @@ -0,0 +1,3 @@ +// OPTION: 3 +fun foo(n : Int): Int { +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInReturn.kt b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInReturn.kt new file mode 100644 index 00000000000..842780a3fd0 --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInReturn.kt @@ -0,0 +1,8 @@ +// OPTION: 3 +fun foo(n : Int): Int { + return if (n > 0) { + 1 + } else { + -1 + } +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInReturn.kt.after b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInReturn.kt.after new file mode 100644 index 00000000000..eb7c581f4cc --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInReturn.kt.after @@ -0,0 +1,3 @@ +// OPTION: 3 +fun foo(n : Int): Int { +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInBlock.kt b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInBlock.kt new file mode 100644 index 00000000000..b866dbe27a8 --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInBlock.kt @@ -0,0 +1,10 @@ +// OPTION: 0 +fun foo(n : Int): Int { + try { + n/0 + } catch (e: Exception) { + -1 + } + + return 0 +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInBlock.kt.after b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInBlock.kt.after new file mode 100644 index 00000000000..ed009ef6d14 --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInBlock.kt.after @@ -0,0 +1,5 @@ +// OPTION: 0 +fun foo(n : Int): Int { + + return 0 +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInReturn.kt b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInReturn.kt new file mode 100644 index 00000000000..e8892e5dcce --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInReturn.kt @@ -0,0 +1,8 @@ +// OPTION: 1 +fun foo(n : Int): Int { + return try { + n/0 + } catch (e: Exception) { + -1 + } +} diff --git a/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInReturn.kt.after b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInReturn.kt.after new file mode 100644 index 00000000000..6ecc87566f0 --- /dev/null +++ b/idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInReturn.kt.after @@ -0,0 +1,3 @@ +// OPTION: 1 +fun foo(n : Int): Int { +} diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/AbstractUnwrapRemoveTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/AbstractUnwrapRemoveTest.java index 964b1a8940a..1b2c2880188 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/AbstractUnwrapRemoveTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/AbstractUnwrapRemoveTest.java @@ -30,6 +30,10 @@ import java.io.File; import java.util.List; public abstract class AbstractUnwrapRemoveTest extends LightCodeInsightTestCase { + public void doTestExpressionRemover(@NotNull String path) throws Exception { + doTest(path, KoitlinUnwrappers.KotlinExpressionRemover.class); + } + public void doTestThenUnwrapper(@NotNull String path) throws Exception { doTest(path, KoitlinUnwrappers.KotlinThenUnwrapper.class); } diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/UnwrapRemoveTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/UnwrapRemoveTestGenerated.java index 92c013c37e9..670b6b8962b 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/UnwrapRemoveTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/unwrap/UnwrapRemoveTestGenerated.java @@ -30,8 +30,41 @@ import org.jetbrains.jet.plugin.codeInsight.unwrap.AbstractUnwrapRemoveTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@InnerTestClasses({UnwrapRemoveTestGenerated.UnwrapThen.class, UnwrapRemoveTestGenerated.UnwrapElse.class, UnwrapRemoveTestGenerated.RemoveElse.class, UnwrapRemoveTestGenerated.UnwrapLoop.class, UnwrapRemoveTestGenerated.UnwrapTry.class, UnwrapRemoveTestGenerated.UnwrapCatch.class, UnwrapRemoveTestGenerated.RemoveCatch.class, UnwrapRemoveTestGenerated.UnwrapFinally.class, UnwrapRemoveTestGenerated.RemoveFinally.class, UnwrapRemoveTestGenerated.UnwrapLambda.class}) +@InnerTestClasses({UnwrapRemoveTestGenerated.RemoveExpression.class, UnwrapRemoveTestGenerated.UnwrapThen.class, UnwrapRemoveTestGenerated.UnwrapElse.class, UnwrapRemoveTestGenerated.RemoveElse.class, UnwrapRemoveTestGenerated.UnwrapLoop.class, UnwrapRemoveTestGenerated.UnwrapTry.class, UnwrapRemoveTestGenerated.UnwrapCatch.class, UnwrapRemoveTestGenerated.RemoveCatch.class, UnwrapRemoveTestGenerated.UnwrapFinally.class, UnwrapRemoveTestGenerated.RemoveFinally.class, UnwrapRemoveTestGenerated.UnwrapLambda.class}) public class UnwrapRemoveTestGenerated extends AbstractUnwrapRemoveTest { + @TestMetadata("idea/testData/codeInsight/unwrapAndRemove/removeExpression") + public static class RemoveExpression extends AbstractUnwrapRemoveTest { + public void testAllFilesPresentInRemoveExpression() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/unwrapAndRemove/removeExpression"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("ifInBlock.kt") + public void testIfInBlock() throws Exception { + doTestExpressionRemover("idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInBlock.kt"); + } + + @TestMetadata("ifInExpressionInReturn.kt") + public void testIfInExpressionInReturn() throws Exception { + doTestExpressionRemover("idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInExpressionInReturn.kt"); + } + + @TestMetadata("ifInReturn.kt") + public void testIfInReturn() throws Exception { + doTestExpressionRemover("idea/testData/codeInsight/unwrapAndRemove/removeExpression/ifInReturn.kt"); + } + + @TestMetadata("tryInBlock.kt") + public void testTryInBlock() throws Exception { + doTestExpressionRemover("idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInBlock.kt"); + } + + @TestMetadata("tryInReturn.kt") + public void testTryInReturn() throws Exception { + doTestExpressionRemover("idea/testData/codeInsight/unwrapAndRemove/removeExpression/tryInReturn.kt"); + } + + } + @TestMetadata("idea/testData/codeInsight/unwrapAndRemove/unwrapThen") public static class UnwrapThen extends AbstractUnwrapRemoveTest { public void testAllFilesPresentInUnwrapThen() throws Exception { @@ -274,6 +307,7 @@ public class UnwrapRemoveTestGenerated extends AbstractUnwrapRemoveTest { public static Test suite() { TestSuite suite = new TestSuite("UnwrapRemoveTestGenerated"); + suite.addTestSuite(RemoveExpression.class); suite.addTestSuite(UnwrapThen.class); suite.addTestSuite(UnwrapElse.class); suite.addTestSuite(RemoveElse.class);