Move statement: fix comma placement for argument/parameter
#KT-14756 Fixed
This commit is contained in:
+18
-2
@@ -591,8 +591,8 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
|
||||
@Override
|
||||
public void beforeMove(@NotNull Editor editor, @NotNull MoveInfo info, boolean down) {
|
||||
if (parametersOrArgsToMove != null) {
|
||||
PsiElement element1 = parametersOrArgsToMove.first;
|
||||
PsiElement element2 = parametersOrArgsToMove.second;
|
||||
PsiElement element1 = getLastSiblingOfSameTypeInLine(parametersOrArgsToMove.first, editor);
|
||||
PsiElement element2 = getLastSiblingOfSameTypeInLine(parametersOrArgsToMove.second, editor);
|
||||
|
||||
fixCommaIfNeeded(element1, down && isLastOfItsKind(element2, true));
|
||||
fixCommaIfNeeded(element2, !down && isLastOfItsKind(element1, true));
|
||||
@@ -601,4 +601,20 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
|
||||
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
@@ -1212,6 +1212,16 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
||||
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")
|
||||
public void testClassParams1() throws Exception {
|
||||
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/classParams1.kt");
|
||||
@@ -1242,6 +1252,16 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
||||
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")
|
||||
public void testFunParams1() throws Exception {
|
||||
runTest("idea/testData/codeInsight/moveUpDown/parametersAndArguments/funParams1.kt");
|
||||
@@ -1271,5 +1291,15 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
||||
public void testFunParams6() throws Exception {
|
||||
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