Convert to expression body: insert new-line after = for long lines
This commit is contained in:
@@ -174,9 +174,21 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs
|
||||
|
||||
val commentSaver = CommentSaver(body)
|
||||
|
||||
declaration.addBefore(KtPsiFactory(declaration).createEQ(), body)
|
||||
val factory = KtPsiFactory(declaration)
|
||||
declaration.addBefore(factory.createEQ(), body)
|
||||
val newBody = body.replaced(value)
|
||||
|
||||
val editor = declaration.findExistingEditor()
|
||||
if (editor != null) {
|
||||
val startOffset = newBody.startOffset
|
||||
val document = editor.document
|
||||
val startLine = document.getLineNumber(startOffset)
|
||||
val rightMargin = editor.settings.getRightMargin(editor.project)
|
||||
if (document.getLineEndOffset(startLine) - document.getLineStartOffset(startLine) >= rightMargin) {
|
||||
declaration.addBefore(factory.createNewLine(), newBody)
|
||||
}
|
||||
}
|
||||
|
||||
commentSaver.restore(newBody)
|
||||
|
||||
if (deleteTypeHandler != null && declaration is KtCallableDeclaration) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(s1: String, s2: String) = s1 + s2
|
||||
|
||||
fun bar(): String {
|
||||
<caret>return foo("gjahkrgkjuyrtetyuairytoiuyareoihuyitouy897304hkdjgnba", "uiyiuye987130423toiuywtuiyrwityriwyhw")
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun foo(s1: String, s2: String) = s1 + s2
|
||||
|
||||
fun bar(): String =
|
||||
foo("gjahkrgkjuyrtetyuairytoiuyareoihuyitouy897304hkdjgnba", "uiyiuye987130423toiuywtuiyrwityriwyhw")
|
||||
+2
-1
@@ -10,6 +10,7 @@ class Foo {
|
||||
arguments = map(arg)
|
||||
}
|
||||
|
||||
private fun map(arg: String) = mapOf(Foo::arguments.name to arg)
|
||||
private fun map(arg: String) =
|
||||
mapOf(Foo::arguments.name to arg)
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -13,4 +13,5 @@ fun foo(n: Int): Int {
|
||||
return i(n, Int::bar1, Int::bar2)
|
||||
}
|
||||
|
||||
private fun i(n: Int, bar1: Int.(m: Int) -> Int, bar2: Int.(m: Int) -> Int) = n.bar1(n + 1).bar2(n + 2)
|
||||
private fun i(n: Int, bar1: Int.(m: Int) -> Int, bar2: Int.(m: Int) -> Int) =
|
||||
n.bar1(n + 1).bar2(n + 2)
|
||||
+2
-1
@@ -17,4 +17,5 @@ class A<T: Data>(val t: T) where T: DataEx {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Data, U : Data, V : Data> i(a: A<T>, b: A<T>.B<U>, v: V) where T : DataEx, U : DataExEx, V : DataEx = a.t.x + b.u.x + v.x
|
||||
private fun <T : Data, U : Data, V : Data> i(a: A<T>, b: A<T>.B<U>, v: V) where T : DataEx, U : DataExEx, V : DataEx =
|
||||
a.t.x + b.u.x + v.x
|
||||
@@ -863,6 +863,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("veryVeryLong.kt")
|
||||
public void testVeryVeryLong() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/useExpressionBody/veryVeryLong.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("when.kt")
|
||||
public void testWhen() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/useExpressionBody/when.kt");
|
||||
|
||||
Reference in New Issue
Block a user