diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt index 3e8e575b92c..0f3875d6544 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt @@ -65,8 +65,7 @@ class AddBracesIntention : SelfTargetingIntention(KtElement::class.ja semicolon.delete() } - // Check for single line if expression - if (element is KtIfExpression && expression.isInSingleLine() && element.`else` == null) { + if (element is KtIfExpression) { // Check if a comment is actually underneath (\n) the expression val allElements = element.siblings(withItself = false).filterIsInstance() val sibling = allElements.firstOrNull { it is PsiComment } diff --git a/idea/testData/intentions/addBraces/addBracesForSingleStatementElseWithCommentBeneath.kt b/idea/testData/intentions/addBraces/addBracesForSingleStatementElseWithCommentBeneath.kt new file mode 100644 index 00000000000..8ea7d9dfc01 --- /dev/null +++ b/idea/testData/intentions/addBraces/addBracesForSingleStatementElseWithCommentBeneath.kt @@ -0,0 +1,10 @@ +fun test(b: Boolean) { + if (b) foo(0) + else + while (true) { + foo(1) + } + // comment about call below +} + +fun foo(i: Int) {} \ No newline at end of file diff --git a/idea/testData/intentions/addBraces/addBracesForSingleStatementElseWithCommentBeneath.kt.after b/idea/testData/intentions/addBraces/addBracesForSingleStatementElseWithCommentBeneath.kt.after new file mode 100644 index 00000000000..2c702bcea61 --- /dev/null +++ b/idea/testData/intentions/addBraces/addBracesForSingleStatementElseWithCommentBeneath.kt.after @@ -0,0 +1,11 @@ +fun test(b: Boolean) { + if (b) foo(0) + else { + while (true) { + foo(1) + } + } + // comment about call below +} + +fun foo(i: Int) {} \ No newline at end of file diff --git a/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath.kt b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath.kt new file mode 100644 index 00000000000..278e094b366 --- /dev/null +++ b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath.kt @@ -0,0 +1,10 @@ +fun test() { + if (false) + while (true) { + foo(1) + } + //comment about foo(2) + foo(2) +} + +fun foo(i: Int) {} \ No newline at end of file diff --git a/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath.kt.after b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath.kt.after new file mode 100644 index 00000000000..67503ac9137 --- /dev/null +++ b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath.kt.after @@ -0,0 +1,11 @@ +fun test() { + if (false) { + while (true) { + foo(1) + } + } + //comment about foo(2) + foo(2) +} + +fun foo(i: Int) {} \ No newline at end of file diff --git a/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath2.kt b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath2.kt new file mode 100644 index 00000000000..88a09a1b16c --- /dev/null +++ b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath2.kt @@ -0,0 +1,9 @@ +fun test() { + if (false) + while (true) + foo(1) + //comment about foo(2) + foo(2) +} + +fun foo(i: Int) {} \ No newline at end of file diff --git a/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath2.kt.after b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath2.kt.after new file mode 100644 index 00000000000..b80319f1bf8 --- /dev/null +++ b/idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath2.kt.after @@ -0,0 +1,10 @@ +fun test() { + if (false) { + while (true) + foo(1) + } + //comment about foo(2) + foo(2) +} + +fun foo(i: Int) {} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index dc754164a06..21c4af23cef 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -721,6 +721,21 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/addBraces/addBracesForSingleLineIfWithCommentBeneath3.kt"); } + @TestMetadata("addBracesForSingleStatementElseWithCommentBeneath.kt") + public void testAddBracesForSingleStatementElseWithCommentBeneath() throws Exception { + runTest("idea/testData/intentions/addBraces/addBracesForSingleStatementElseWithCommentBeneath.kt"); + } + + @TestMetadata("addBracesForSingleStatementIfWithCommentBeneath.kt") + public void testAddBracesForSingleStatementIfWithCommentBeneath() throws Exception { + runTest("idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath.kt"); + } + + @TestMetadata("addBracesForSingleStatementIfWithCommentBeneath2.kt") + public void testAddBracesForSingleStatementIfWithCommentBeneath2() throws Exception { + runTest("idea/testData/intentions/addBraces/addBracesForSingleStatementIfWithCommentBeneath2.kt"); + } + @TestMetadata("addBracesForWhile.kt") public void testAddBracesForWhile() throws Exception { runTest("idea/testData/intentions/addBraces/addBracesForWhile.kt");