"Replace if with when": Do not remove block braces if block has single lambda expression #KT-26187 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-08-17 13:38:19 +09:00
committed by Mikhail Glukhikh
parent e59427edab
commit 362e6863ac
6 changed files with 57 additions and 1 deletions
@@ -69,7 +69,9 @@ fun KtExpression.unwrapBlockOrParenthesis(): KtExpression {
val innerExpression = KtPsiUtil.safeDeparenthesize(this, true)
if (innerExpression is KtBlockExpression) {
val statement = innerExpression.statements.singleOrNull() ?: return this
return KtPsiUtil.safeDeparenthesize(statement, true)
val deparenthesized = KtPsiUtil.safeDeparenthesize(statement, true)
if (deparenthesized is KtLambdaExpression) return this
return deparenthesized
}
return innerExpression
}