Implement general expresion remover
This commit is contained in:
@@ -375,6 +375,7 @@ public class GenerateTests {
|
|||||||
"idea/tests/",
|
"idea/tests/",
|
||||||
"UnwrapRemoveTestGenerated",
|
"UnwrapRemoveTestGenerated",
|
||||||
AbstractUnwrapRemoveTest.class,
|
AbstractUnwrapRemoveTest.class,
|
||||||
|
testModel("idea/testData/codeInsight/unwrapAndRemove/removeExpression", "doTestExpressionRemover"),
|
||||||
testModel("idea/testData/codeInsight/unwrapAndRemove/unwrapThen", "doTestThenUnwrapper"),
|
testModel("idea/testData/codeInsight/unwrapAndRemove/unwrapThen", "doTestThenUnwrapper"),
|
||||||
testModel("idea/testData/codeInsight/unwrapAndRemove/unwrapElse", "doTestElseUnwrapper"),
|
testModel("idea/testData/codeInsight/unwrapAndRemove/unwrapElse", "doTestElseUnwrapper"),
|
||||||
testModel("idea/testData/codeInsight/unwrapAndRemove/removeElse", "doTestElseRemover"),
|
testModel("idea/testData/codeInsight/unwrapAndRemove/removeElse", "doTestElseRemover"),
|
||||||
|
|||||||
@@ -26,6 +26,17 @@ public class KoitlinUnwrappers {
|
|||||||
private 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 static class KotlinElseUnwrapper extends KotlinComponentUnwrapper {
|
||||||
public KotlinElseUnwrapper(String key) {
|
public KotlinElseUnwrapper(String key) {
|
||||||
super(key);
|
super(key);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class KotlinUnwrapDescriptor extends UnwrapDescriptorBase {
|
|||||||
@Override
|
@Override
|
||||||
protected Unwrapper[] createUnwrappers() {
|
protected Unwrapper[] createUnwrappers() {
|
||||||
return new Unwrapper[] {
|
return new Unwrapper[] {
|
||||||
|
new KoitlinUnwrappers.KotlinExpressionRemover("remove.expression"),
|
||||||
new KoitlinUnwrappers.KotlinThenUnwrapper("unwrap.expression"),
|
new KoitlinUnwrappers.KotlinThenUnwrapper("unwrap.expression"),
|
||||||
new KoitlinUnwrappers.KotlinElseRemover("remove.else"),
|
new KoitlinUnwrappers.KotlinElseRemover("remove.else"),
|
||||||
new KoitlinUnwrappers.KotlinElseUnwrapper("unwrap.else"),
|
new KoitlinUnwrappers.KotlinElseUnwrapper("unwrap.else"),
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// OPTION: 0
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
<caret>if (n > 0) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// OPTION: 0
|
||||||
|
fun foo(n : Int): Int {<caret>
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// OPTION: 3
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
return 10 +
|
||||||
|
<caret>if (n > 0) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// OPTION: 3
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
<caret>}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// OPTION: 3
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
return <caret>if (n > 0) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// OPTION: 3
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
<caret>}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// OPTION: 0
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
<caret>try {
|
||||||
|
n/0
|
||||||
|
} catch (e: Exception) {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// OPTION: 0
|
||||||
|
fun foo(n : Int): Int {<caret>
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// OPTION: 1
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
return <caret>try {
|
||||||
|
n/0
|
||||||
|
} catch (e: Exception) {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// OPTION: 1
|
||||||
|
fun foo(n : Int): Int {
|
||||||
|
<caret>}
|
||||||
@@ -30,6 +30,10 @@ import java.io.File;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class AbstractUnwrapRemoveTest extends LightCodeInsightTestCase {
|
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 {
|
public void doTestThenUnwrapper(@NotNull String path) throws Exception {
|
||||||
doTest(path, KoitlinUnwrappers.KotlinThenUnwrapper.class);
|
doTest(path, KoitlinUnwrappers.KotlinThenUnwrapper.class);
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-1
@@ -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 */
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@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 {
|
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")
|
@TestMetadata("idea/testData/codeInsight/unwrapAndRemove/unwrapThen")
|
||||||
public static class UnwrapThen extends AbstractUnwrapRemoveTest {
|
public static class UnwrapThen extends AbstractUnwrapRemoveTest {
|
||||||
public void testAllFilesPresentInUnwrapThen() throws Exception {
|
public void testAllFilesPresentInUnwrapThen() throws Exception {
|
||||||
@@ -274,6 +307,7 @@ public class UnwrapRemoveTestGenerated extends AbstractUnwrapRemoveTest {
|
|||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite = new TestSuite("UnwrapRemoveTestGenerated");
|
TestSuite suite = new TestSuite("UnwrapRemoveTestGenerated");
|
||||||
|
suite.addTestSuite(RemoveExpression.class);
|
||||||
suite.addTestSuite(UnwrapThen.class);
|
suite.addTestSuite(UnwrapThen.class);
|
||||||
suite.addTestSuite(UnwrapElse.class);
|
suite.addTestSuite(UnwrapElse.class);
|
||||||
suite.addTestSuite(RemoveElse.class);
|
suite.addTestSuite(RemoveElse.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user