RemoveBracesIntention: add new line for long expression
#KT-30523 Fixed
This commit is contained in:
committed by
Yan Zhulanow
parent
731848849e
commit
f4b9c4777f
@@ -62,6 +62,13 @@ class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class
|
||||
|
||||
if (construct is KtDoWhileExpression) {
|
||||
newElement.parent!!.addAfter(factory.createNewLine(), newElement)
|
||||
} else if (editor != null) {
|
||||
val document = editor.document
|
||||
val line = document.getLineNumber(newElement.startOffset)
|
||||
val rightMargin = editor.settings.getRightMargin(editor.project)
|
||||
if (document.getLineEndOffset(line) - document.getLineStartOffset(line) >= rightMargin) {
|
||||
newElement.parent.addBefore(factory.createNewLine(), newElement)
|
||||
}
|
||||
}
|
||||
|
||||
if (construct is KtIfExpression &&
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Boolean
|
||||
): Int {
|
||||
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {<caret>
|
||||
return 1
|
||||
}
|
||||
return 2
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Boolean
|
||||
): Int {
|
||||
if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
|
||||
return 1
|
||||
return 2
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Boolean
|
||||
): Int {
|
||||
when {
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -> {<caret>
|
||||
return 1
|
||||
}
|
||||
else -> return 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: Boolean
|
||||
): Int {
|
||||
when {
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ->
|
||||
return 1
|
||||
else -> return 2
|
||||
}
|
||||
}
|
||||
@@ -13781,6 +13781,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/removeBraces/ifLambda2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifLong.kt")
|
||||
public void testIfLong() throws Exception {
|
||||
runTest("idea/testData/intentions/removeBraces/ifLong.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifWithComment.kt")
|
||||
public void testIfWithComment() throws Exception {
|
||||
runTest("idea/testData/intentions/removeBraces/ifWithComment.kt");
|
||||
@@ -13826,6 +13831,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/removeBraces/whenLambda3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whenLong.kt")
|
||||
public void testWhenLong() throws Exception {
|
||||
runTest("idea/testData/intentions/removeBraces/whenLong.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whenMultiple.kt")
|
||||
public void testWhenMultiple() throws Exception {
|
||||
runTest("idea/testData/intentions/removeBraces/whenMultiple.kt");
|
||||
|
||||
Reference in New Issue
Block a user