Merge pull request #2467 from t-kameyama/KT-14756
KT-14756 Move statement down breaks code in argument list
This commit is contained in:
+18
-2
@@ -651,8 +651,8 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
|
|||||||
@Override
|
@Override
|
||||||
public void beforeMove(@NotNull Editor editor, @NotNull MoveInfo info, boolean down) {
|
public void beforeMove(@NotNull Editor editor, @NotNull MoveInfo info, boolean down) {
|
||||||
if (parametersOrArgsToMove != null) {
|
if (parametersOrArgsToMove != null) {
|
||||||
PsiElement element1 = parametersOrArgsToMove.first;
|
PsiElement element1 = getLastSiblingOfSameTypeInLine(parametersOrArgsToMove.first, editor);
|
||||||
PsiElement element2 = parametersOrArgsToMove.second;
|
PsiElement element2 = getLastSiblingOfSameTypeInLine(parametersOrArgsToMove.second, editor);
|
||||||
|
|
||||||
fixCommaIfNeeded(element1, down && isLastOfItsKind(element2, true));
|
fixCommaIfNeeded(element1, down && isLastOfItsKind(element2, true));
|
||||||
fixCommaIfNeeded(element2, !down && isLastOfItsKind(element1, true));
|
fixCommaIfNeeded(element2, !down && isLastOfItsKind(element1, true));
|
||||||
@@ -661,4 +661,20 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
|
|||||||
PsiDocumentManager.getInstance(editor.getProject()).doPostponedOperationsAndUnblockDocument(editor.getDocument());
|
PsiDocumentManager.getInstance(editor.getProject()).doPostponedOperationsAndUnblockDocument(editor.getDocument());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static PsiElement getLastSiblingOfSameTypeInLine(@NotNull PsiElement element, @NotNull Editor editor) {
|
||||||
|
PsiElement lastElement = element;
|
||||||
|
int lineNumber = getElementLine(element, editor, true);
|
||||||
|
while (true) {
|
||||||
|
PsiElement nextElement = PsiTreeUtil.getNextSiblingOfType(lastElement, lastElement.getClass());
|
||||||
|
if (nextElement != null && getElementLine(nextElement, editor, true) == lineNumber) {
|
||||||
|
lastElement = nextElement;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastElement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: down
|
||||||
|
val x = listOf(
|
||||||
|
1,
|
||||||
|
<caret>2, 3,
|
||||||
|
4
|
||||||
|
)
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: down
|
||||||
|
val x = listOf(
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
<caret>2, 3
|
||||||
|
)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: up
|
||||||
|
val x = listOf(
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
<caret>2, 3
|
||||||
|
)
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: up
|
||||||
|
val x = listOf(
|
||||||
|
1,
|
||||||
|
<caret>2, 3,
|
||||||
|
4
|
||||||
|
)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: down
|
||||||
|
class A(
|
||||||
|
a: Int,
|
||||||
|
<caret>b: Int, c: Int,
|
||||||
|
d: Int
|
||||||
|
)
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: down
|
||||||
|
class A(
|
||||||
|
a: Int,
|
||||||
|
d: Int,
|
||||||
|
<caret>b: Int, c: Int
|
||||||
|
)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: up
|
||||||
|
class A(
|
||||||
|
a: Int,
|
||||||
|
d: Int,
|
||||||
|
<caret>b: Int, c: Int
|
||||||
|
)
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: up
|
||||||
|
class A(
|
||||||
|
a: Int,
|
||||||
|
<caret>b: Int, c: Int,
|
||||||
|
d: Int
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(
|
||||||
|
a: Int,
|
||||||
|
<caret>b: Int, c: Int,
|
||||||
|
d: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun test(
|
||||||
|
a: Int,
|
||||||
|
d: Int,
|
||||||
|
<caret>b: Int, c: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(
|
||||||
|
a: Int,
|
||||||
|
d: Int,
|
||||||
|
<caret>b: Int, c: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// MOVE: up
|
||||||
|
fun test(
|
||||||
|
a: Int,
|
||||||
|
<caret>b: Int, c: Int,
|
||||||
|
d: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
Generated
+30
@@ -1247,6 +1247,16 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
|||||||
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/callArgs6.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/callArgs6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("callArgs7.kt")
|
||||||
|
public void testCallArgs7() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/callArgs7.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("callArgs8.kt")
|
||||||
|
public void testCallArgs8() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/callArgs8.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("classParams1.kt")
|
@TestMetadata("classParams1.kt")
|
||||||
public void testClassParams1() throws Exception {
|
public void testClassParams1() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/classParams1.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/classParams1.kt");
|
||||||
@@ -1277,6 +1287,16 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
|||||||
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/classParams6.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/classParams6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classParams7.kt")
|
||||||
|
public void testClassParams7() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/classParams7.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classParams8.kt")
|
||||||
|
public void testClassParams8() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/classParams8.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("funParams1.kt")
|
@TestMetadata("funParams1.kt")
|
||||||
public void testFunParams1() throws Exception {
|
public void testFunParams1() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/funParams1.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/funParams1.kt");
|
||||||
@@ -1306,5 +1326,15 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
|||||||
public void testFunParams6() throws Exception {
|
public void testFunParams6() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/funParams6.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/funParams6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("funParams7.kt")
|
||||||
|
public void testFunParams7() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/funParams7.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("funParams8.kt")
|
||||||
|
public void testFunParams8() throws Exception {
|
||||||
|
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/funParams8.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user