Introduce Variable: Amend semicolons to updated expression

#KT-2098 Fixed
This commit is contained in:
Alexey Sedunov
2014-12-24 14:47:38 +03:00
parent 2fe77d2c6c
commit c7a71827a7
6 changed files with 51 additions and 1 deletions
@@ -377,8 +377,16 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
}
}
else {
PsiElement parent = anchor.getParent();
PsiElement copyTo = parent.getLastChild();
PsiElement copyFrom = anchor.getNextSibling();
property = (JetProperty)emptyBody.addAfter(property, 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);
}
for (PsiElement child : emptyBody.getChildren()) {
@@ -406,7 +414,13 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
replaceExpression(replace);
}
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);
@@ -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()
}
@@ -177,6 +177,18 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
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")
public void testNonEquivalentReceivers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/nonEquivalentReceivers.kt");