KT-12942 related: remove braces now does not work for if inside if

(cherry picked from commit c1faed5)
This commit is contained in:
Mikhail Glukhikh
2016-07-12 10:56:33 +03:00
committed by Mikhail Glukhikh
parent 3fe114fc24
commit 39ffb68cc6
3 changed files with 19 additions and 1 deletions
@@ -23,9 +23,10 @@ import org.jetbrains.kotlin.psi.*
class RemoveBracesIntention : SelfTargetingIntention<KtBlockExpression>(KtBlockExpression::class.java, "Remove braces") {
override fun isApplicableTo(element: KtBlockExpression, caretOffset: Int): Boolean {
if (element.statements.size != 1) return false
val singleStatement = element.statements.singleOrNull() ?: return false
val containerNode = element.parent as? KtContainerNode ?: return false
if (singleStatement is KtIfExpression && containerNode.parent is KtIfExpression) return false
val lBrace = element.lBrace ?: return false
val rBrace = element.rBrace ?: return false
+11
View File
@@ -0,0 +1,11 @@
// IS_APPLICABLE: false
fun test(b: Boolean): String {
if (b == true) {
if (true) return "first"
}<caret>
else if (b == false) {
if (true) return "second"
}
return "none"
}
@@ -7697,6 +7697,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("ifInsideIf.kt")
public void testIfInsideIf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifInsideIf.kt");
doTest(fileName);
}
@TestMetadata("ifWithComment.kt")
public void testIfWithComment() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifWithComment.kt");