Do not move closing brace in function-like elements
This commit is contained in:
@@ -16,15 +16,12 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
public JetExpressionMover() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
private static Class[] MOVABLE_ELEMENT_CLASSES = {JetExpression.class, JetWhenEntry.class, JetValueArgument.class, PsiComment.class};
|
||||
private final static Class[] MOVABLE_ELEMENT_CLASSES = {JetExpression.class, JetWhenEntry.class, JetValueArgument.class, PsiComment.class};
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
private static Class[] BLOCKLIKE_ELEMENT_CLASSES =
|
||||
private final static Class[] BLOCKLIKE_ELEMENT_CLASSES =
|
||||
{JetBlockExpression.class, JetWhenExpression.class, JetClassBody.class, JetFile.class};
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
private static Class[] FUNCTIONLIKE_ELEMENT_CLASSES =
|
||||
private final static Class[] FUNCTIONLIKE_ELEMENT_CLASSES =
|
||||
{JetFunction.class, JetPropertyAccessor.class, JetClassInitializer.class};
|
||||
|
||||
@Nullable
|
||||
@@ -113,7 +110,10 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
|
||||
PsiElement blockLikeElement = closingBrace.getParent();
|
||||
if (!(blockLikeElement instanceof JetBlockExpression)) return BraceStatus.NOT_MOVABLE;
|
||||
if (blockLikeElement.getParent() instanceof JetWhenEntry) return BraceStatus.NOT_FOUND;
|
||||
|
||||
PsiElement blockParent = blockLikeElement.getParent();
|
||||
if (blockParent instanceof JetWhenEntry) return BraceStatus.NOT_FOUND;
|
||||
if (PsiTreeUtil.instanceOf(blockParent, FUNCTIONLIKE_ELEMENT_CLASSES)) return BraceStatus.NOT_FOUND;
|
||||
|
||||
PsiElement enclosingExpression = PsiTreeUtil.getParentOfType(blockLikeElement, JetExpression.class);
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
fun foo() {
|
||||
val x = ""
|
||||
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
|
||||
val y = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
fun foo() {
|
||||
val x = ""
|
||||
|
||||
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
val y = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
fun foo() {
|
||||
val x = ""
|
||||
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
|
||||
val y = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
fun foo() {
|
||||
val x = ""
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
|
||||
|
||||
val y = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
fun foo() {
|
||||
val x = ""
|
||||
|
||||
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
val y = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: down
|
||||
fun foo() {
|
||||
val x = ""
|
||||
|
||||
|
||||
val y = ""
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
fun foo() {
|
||||
val x = ""
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
|
||||
|
||||
val y = ""
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MOVE: up
|
||||
fun foo() {
|
||||
fun bar() {
|
||||
|
||||
}<caret>
|
||||
val x = ""
|
||||
|
||||
|
||||
val y = ""
|
||||
}
|
||||
+30
-1
@@ -574,7 +574,7 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/codeInsight/moveUpDown/closingBraces")
|
||||
@InnerTestClasses({ClosingBraces.For.class, ClosingBraces.If.class, ClosingBraces.Nested.class, ClosingBraces.When.class, ClosingBraces.While.class})
|
||||
@InnerTestClasses({ClosingBraces.For.class, ClosingBraces.Function.class, ClosingBraces.If.class, ClosingBraces.Nested.class, ClosingBraces.When.class, ClosingBraces.While.class})
|
||||
public static class ClosingBraces extends AbstractCodeMoverTest {
|
||||
public void testAllFilesPresentInClosingBraces() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/moveUpDown/closingBraces"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
@@ -598,6 +598,34 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/codeInsight/moveUpDown/closingBraces/function")
|
||||
public static class Function extends AbstractCodeMoverTest {
|
||||
public void testAllFilesPresentInFunction() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/moveUpDown/closingBraces/function"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("function1.kt")
|
||||
public void testFunction1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/closingBraces/function/function1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function2.kt")
|
||||
public void testFunction2() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/closingBraces/function/function2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function3.kt")
|
||||
public void testFunction3() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/closingBraces/function/function3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("function4.kt")
|
||||
public void testFunction4() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/closingBraces/function/function4.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/codeInsight/moveUpDown/closingBraces/if")
|
||||
public static class If extends AbstractCodeMoverTest {
|
||||
public void testAllFilesPresentInIf() throws Exception {
|
||||
@@ -714,6 +742,7 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
TestSuite suite = new TestSuite("ClosingBraces");
|
||||
suite.addTestSuite(ClosingBraces.class);
|
||||
suite.addTestSuite(For.class);
|
||||
suite.addTestSuite(Function.class);
|
||||
suite.addTestSuite(If.class);
|
||||
suite.addTestSuite(Nested.class);
|
||||
suite.addTestSuite(When.class);
|
||||
|
||||
Reference in New Issue
Block a user