Suggest "Remove braces" in nested if correctly #KT-14270 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-03-07 04:51:02 +03:00
committed by Mikhail Glukhikh
parent 8082a5daf7
commit e328d2d1ca
11 changed files with 119 additions and 1 deletions
@@ -38,7 +38,10 @@ class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class
val container = block.parent
when (container) {
is KtContainerNode -> {
if (singleStatement is KtIfExpression && container.parent is KtIfExpression) return false
if (singleStatement is KtIfExpression) {
val elseExpression = (container.parent as? KtIfExpression)?.`else`
if (elseExpression != null && elseExpression != block) return false
}
val description = container.description() ?: return false
text = "Remove braces from '$description' statement"
+7
View File
@@ -0,0 +1,7 @@
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {<caret>
if (b) foo(1)
}
}
@@ -0,0 +1,5 @@
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) if (b) foo(1)
}
+11
View File
@@ -0,0 +1,11 @@
// IS_APPLICABLE: false
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {<caret>
if (b) foo(1)
} else if (i == 2) {
if (b) foo(2)
}
}
+9
View File
@@ -0,0 +1,9 @@
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {
if (b) foo(1)
} else if (i == 2) {<caret>
if (b) foo(2)
}
}
@@ -0,0 +1,7 @@
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {
if (b) foo(1)
} else if (i == 2) if (b) foo(2)
}
+11
View File
@@ -0,0 +1,11 @@
// IS_APPLICABLE: false
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {<caret>
if (b) foo(1)
} else {
if (b) foo(2)
}
}
+9
View File
@@ -0,0 +1,9 @@
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {
if (b) foo(1)
} else {<caret>
if (b) foo(2)
}
}
@@ -0,0 +1,7 @@
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {
if (b) foo(1)
} else if (b) foo(2)
}
+13
View File
@@ -0,0 +1,13 @@
// IS_APPLICABLE: false
fun foo(i :Int) {}
fun test(i: Int, b: Boolean) {
if (i == 1) {
if (b) foo(1)
} else if (i == 2) {<caret>
if (b) foo(2)
} else {
if (b) foo(3)
}
}
@@ -12528,6 +12528,42 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("ifInsideIf2.kt")
public void testIfInsideIf2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifInsideIf2.kt");
doTest(fileName);
}
@TestMetadata("ifInsideIf3.kt")
public void testIfInsideIf3() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifInsideIf3.kt");
doTest(fileName);
}
@TestMetadata("ifInsideIf4.kt")
public void testIfInsideIf4() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifInsideIf4.kt");
doTest(fileName);
}
@TestMetadata("ifInsideIf5.kt")
public void testIfInsideIf5() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifInsideIf5.kt");
doTest(fileName);
}
@TestMetadata("ifInsideIf6.kt")
public void testIfInsideIf6() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifInsideIf6.kt");
doTest(fileName);
}
@TestMetadata("ifInsideIf7.kt")
public void testIfInsideIf7() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifInsideIf7.kt");
doTest(fileName);
}
@TestMetadata("ifWithComment.kt")
public void testIfWithComment() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifWithComment.kt");