Introduce Variable: Amend semicolons to updated expression
#KT-2098 Fixed
This commit is contained in:
+15
-1
@@ -377,8 +377,16 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
PsiElement parent = anchor.getParent();
|
||||||
|
PsiElement copyTo = parent.getLastChild();
|
||||||
|
PsiElement copyFrom = anchor.getNextSibling();
|
||||||
|
|
||||||
property = (JetProperty)emptyBody.addAfter(property, firstChild);
|
property = (JetProperty)emptyBody.addAfter(property, firstChild);
|
||||||
emptyBody.addAfter(psiFactory.createNewLine(), firstChild);
|
emptyBody.addAfter(psiFactory.createNewLine(), firstChild);
|
||||||
|
if (copyFrom != null && copyTo != null) {
|
||||||
|
emptyBody.addRangeAfter(copyFrom, copyTo, property);
|
||||||
|
parent.deleteChildRange(copyFrom, copyTo);
|
||||||
|
}
|
||||||
emptyBody = (JetBlockExpression) anchor.replace(emptyBody);
|
emptyBody = (JetBlockExpression) anchor.replace(emptyBody);
|
||||||
}
|
}
|
||||||
for (PsiElement child : emptyBody.getChildren()) {
|
for (PsiElement child : emptyBody.getChildren()) {
|
||||||
@@ -406,7 +414,13 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
|||||||
replaceExpression(replace);
|
replaceExpression(replace);
|
||||||
}
|
}
|
||||||
else if (!needBraces) {
|
else if (!needBraces) {
|
||||||
replace.delete();
|
PsiElement sibling = PsiTreeUtil.skipSiblingsBackward(replace, PsiWhiteSpace.class);
|
||||||
|
if (sibling == property) {
|
||||||
|
replace.getParent().deleteChildRange(property.getNextSibling(), replace);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
replace.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
propertyRef.set(property);
|
propertyRef.set(property);
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun bar(): Int = 1
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
<selection>bar()</selection>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun bar(): Int = 1
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val i = bar();
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun bar(): Int = 1
|
||||||
|
fun baz()
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
if (true) <selection>bar()</selection>; else baz()
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fun bar(): Int = 1
|
||||||
|
fun baz()
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
if (true) {
|
||||||
|
val i = bar();
|
||||||
|
} else baz()
|
||||||
|
}
|
||||||
+12
@@ -177,6 +177,18 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
|||||||
doIntroduceVariableTest(fileName);
|
doIntroduceVariableTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("NoNewLinesInBetween.kt")
|
||||||
|
public void testNoNewLinesInBetween() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/NoNewLinesInBetween.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("NoNewLinesInBetweenNoBraces.kt")
|
||||||
|
public void testNoNewLinesInBetweenNoBraces() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/NoNewLinesInBetweenNoBraces.kt");
|
||||||
|
doIntroduceVariableTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonEquivalentReceivers.kt")
|
@TestMetadata("nonEquivalentReceivers.kt")
|
||||||
public void testNonEquivalentReceivers() throws Exception {
|
public void testNonEquivalentReceivers() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/nonEquivalentReceivers.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/nonEquivalentReceivers.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user