Use expression body: add new line more accurately
This commit is contained in:
@@ -172,6 +172,14 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs
|
|||||||
declaration.addBefore(factory.createEQ(), body)
|
declaration.addBefore(factory.createEQ(), body)
|
||||||
val newBody = body.replaced(value)
|
val newBody = body.replaced(value)
|
||||||
|
|
||||||
|
commentSaver.restore(newBody)
|
||||||
|
|
||||||
|
if (deleteTypeHandler != null && declaration is KtCallableDeclaration) {
|
||||||
|
if (declaration.hasDeclaredReturnType() && declaration.canOmitDeclaredType(newBody, canChangeTypeToSubtype = true)) {
|
||||||
|
deleteTypeHandler(declaration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val editor = declaration.findExistingEditor()
|
val editor = declaration.findExistingEditor()
|
||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
val startOffset = newBody.startOffset
|
val startOffset = newBody.startOffset
|
||||||
@@ -182,14 +190,6 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs
|
|||||||
declaration.addBefore(factory.createNewLine(), newBody)
|
declaration.addBefore(factory.createNewLine(), newBody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commentSaver.restore(newBody)
|
|
||||||
|
|
||||||
if (deleteTypeHandler != null && declaration is KtCallableDeclaration) {
|
|
||||||
if (declaration.hasDeclaredReturnType() && declaration.canOmitDeclaredType(newBody, canChangeTypeToSubtype = true)) {
|
|
||||||
deleteTypeHandler(declaration)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ConvertToExpressionBodyFix : LocalQuickFix {
|
inner class ConvertToExpressionBodyFix : LocalQuickFix {
|
||||||
|
|||||||
+1
-2
@@ -10,7 +10,6 @@ class Foo {
|
|||||||
arguments = map(arg)
|
arguments = map(arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun map(arg: String) =
|
private fun map(arg: String) = mapOf(Foo::arguments.name to arg)
|
||||||
mapOf(Foo::arguments.name to arg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user