Add braces: Remove new line between '}' and 'else' #KT-26839 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-09-25 12:52:43 +09:00
committed by Mikhail Glukhikh
parent de261df6f5
commit 3e4d8eba76
8 changed files with 84 additions and 2 deletions
@@ -76,8 +76,12 @@ class AddBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.ja
val result = expression.replace(psiFactory.createSingleStatementBlock(expression))
if (element is KtDoWhileExpression) { // remove new line between '}' and while
(element.body!!.parent.nextSibling as? PsiWhiteSpace)?.delete()
when (element) {
is KtDoWhileExpression ->
// remove new line between '}' and while
(element.body!!.parent.nextSibling as? PsiWhiteSpace)?.delete()
is KtIfExpression ->
(result?.parent?.nextSibling as? PsiWhiteSpace)?.delete()
}
saver.restore(result)
}
@@ -0,0 +1,10 @@
fun <T> doSomething(a: T) {}
fun foo(i: Int) {
<caret>if (i == 1)
doSomething(1)
else
doSomething(0)
doSomething(-1)
}
@@ -0,0 +1,10 @@
fun <T> doSomething(a: T) {}
fun foo(i: Int) {
if (i == 1) {
doSomething(1)
} else
doSomething(0)
doSomething(-1)
}
@@ -0,0 +1,12 @@
fun <T> doSomething(a: T) {}
fun foo(i: Int) {
<caret>if (i == 1)
doSomething(1)
else
doSomething(0)
doSomething(-1)
}
@@ -0,0 +1,10 @@
fun <T> doSomething(a: T) {}
fun foo(i: Int) {
if (i == 1) {
doSomething(1)
} else
doSomething(0)
doSomething(-1)
}
@@ -0,0 +1,10 @@
fun <T> doSomething(a: T) {}
fun foo(i: Int) {
if (i == 1)
doSomething(1)
<caret>else
doSomething(0)
doSomething(-1)
}
@@ -0,0 +1,11 @@
fun <T> doSomething(a: T) {}
fun foo(i: Int) {
if (i == 1)
doSomething(1)
else {
doSomething(0)
}
doSomething(-1)
}
@@ -666,6 +666,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/addBraces/addBracesForIf.kt");
}
@TestMetadata("addBracesForIfWithIndent.kt")
public void testAddBracesForIfWithIndent() throws Exception {
runTest("idea/testData/intentions/addBraces/addBracesForIfWithIndent.kt");
}
@TestMetadata("addBracesForIfWithIndent2.kt")
public void testAddBracesForIfWithIndent2() throws Exception {
runTest("idea/testData/intentions/addBraces/addBracesForIfWithIndent2.kt");
}
@TestMetadata("addBracesForIfWithIndent3.kt")
public void testAddBracesForIfWithIndent3() throws Exception {
runTest("idea/testData/intentions/addBraces/addBracesForIfWithIndent3.kt");
}
@TestMetadata("addBracesForIfWithNoSpace.kt")
public void testAddBracesForIfWithNoSpace() throws Exception {
runTest("idea/testData/intentions/addBraces/addBracesForIfWithNoSpace.kt");