KT-12942 related: remove braces now does not work for if inside if
(cherry picked from commit c1faed5)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
3fe114fc24
commit
39ffb68cc6
@@ -23,9 +23,10 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
|
|
||||||
class RemoveBracesIntention : SelfTargetingIntention<KtBlockExpression>(KtBlockExpression::class.java, "Remove braces") {
|
class RemoveBracesIntention : SelfTargetingIntention<KtBlockExpression>(KtBlockExpression::class.java, "Remove braces") {
|
||||||
override fun isApplicableTo(element: KtBlockExpression, caretOffset: Int): Boolean {
|
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
|
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 lBrace = element.lBrace ?: return false
|
||||||
val rBrace = element.rBrace ?: return false
|
val rBrace = element.rBrace ?: return false
|
||||||
|
|||||||
@@ -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);
|
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")
|
@TestMetadata("ifWithComment.kt")
|
||||||
public void testIfWithComment() throws Exception {
|
public void testIfWithComment() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifWithComment.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeBraces/ifWithComment.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user