Add braces: don't insert extra line break and move the following comment
#KT-36194 Fixed
This commit is contained in:
committed by
Yan Zhulanow
parent
905d0c1016
commit
777995a3a0
@@ -79,7 +79,9 @@ class AddBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class.ja
|
||||
val nextComment = when {
|
||||
element is KtDoWhileExpression -> null // bound to the closing while
|
||||
element is KtIfExpression && expression === element.then && element.`else` != null -> null // bound to else
|
||||
else -> element.getNextSiblingIgnoringWhitespace().takeIf { it is PsiComment }
|
||||
else -> element.getNextSiblingIgnoringWhitespace().takeIf {
|
||||
it is PsiComment && it.getLineNumber() == element.getLineNumber(start = false)
|
||||
}
|
||||
}
|
||||
|
||||
val saver = when {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
fun foo(list: List<String>) {
|
||||
if (true)<caret> println(list)
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
|
||||
for (l in list) println(l)
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
}
|
||||
|
||||
fun println(a: Any) {}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo(list: List<String>) {
|
||||
if (true) {
|
||||
println(list)
|
||||
}
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
|
||||
for (l in list) println(l)
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
}
|
||||
|
||||
fun println(a: Any) {}
|
||||
@@ -0,0 +1,13 @@
|
||||
fun foo(list: List<String>) {
|
||||
if (true) println(list)
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
|
||||
for (l in list)<caret> println(l)
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
}
|
||||
|
||||
fun println(a: Any) {}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo(list: List<String>) {
|
||||
if (true) println(list)
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
|
||||
for (l in list) {
|
||||
println(l)
|
||||
}
|
||||
|
||||
// printing...
|
||||
println("hi")
|
||||
}
|
||||
|
||||
fun println(a: Any) {}
|
||||
@@ -764,6 +764,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/addBraces/forWithComment.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hasCommentOnNextLine.kt")
|
||||
public void testHasCommentOnNextLine() throws Exception {
|
||||
runTest("idea/testData/intentions/addBraces/hasCommentOnNextLine.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hasCommentOnNextLine2.kt")
|
||||
public void testHasCommentOnNextLine2() throws Exception {
|
||||
runTest("idea/testData/intentions/addBraces/hasCommentOnNextLine2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifElseWithComment.kt")
|
||||
public void testIfElseWithComment() throws Exception {
|
||||
runTest("idea/testData/intentions/addBraces/ifElseWithComment.kt");
|
||||
|
||||
Reference in New Issue
Block a user