Reformat: if to when

This commit is contained in:
Mikhail Glukhikh
2018-04-28 16:21:31 +03:00
parent d9d7b87fd9
commit 73a756084e
@@ -39,16 +39,16 @@ class IfToWhenIntention : SelfTargetingRangeIntention<KtIfExpression>(KtIfExpres
} }
private fun canPassThrough(expression: KtExpression?): Boolean = private fun canPassThrough(expression: KtExpression?): Boolean =
when (expression) { when (expression) {
is KtReturnExpression, is KtThrowExpression -> is KtReturnExpression, is KtThrowExpression ->
false false
is KtBlockExpression -> is KtBlockExpression ->
expression.statements.all { canPassThrough(it) } expression.statements.all { canPassThrough(it) }
is KtIfExpression -> is KtIfExpression ->
canPassThrough(expression.then) || canPassThrough(expression.`else`) canPassThrough(expression.then) || canPassThrough(expression.`else`)
else -> else ->
true true
} }
private fun buildNextBranch(ifExpression: KtIfExpression): KtExpression? { private fun buildNextBranch(ifExpression: KtIfExpression): KtExpression? {
var nextSibling = ifExpression.getNextSiblingIgnoringWhitespaceAndComments() ?: return null var nextSibling = ifExpression.getNextSiblingIgnoringWhitespaceAndComments() ?: return null
@@ -125,16 +125,13 @@ class IfToWhenIntention : SelfTargetingRangeIntention<KtIfExpression>(KtIfExpres
baseIfExpressionForSyntheticBranch = syntheticElseBranch baseIfExpressionForSyntheticBranch = syntheticElseBranch
currentIfExpression = syntheticElseBranch currentIfExpression = syntheticElseBranch
toDelete.add(syntheticElseBranch) toDelete.add(syntheticElseBranch)
} } else {
else {
appendElseBlock(syntheticElseBranch) appendElseBlock(syntheticElseBranch)
break break
} }
} } else if (currentElseBranch is KtIfExpression) {
else if (currentElseBranch is KtIfExpression) {
currentIfExpression = currentElseBranch currentIfExpression = currentElseBranch
} } else {
else {
appendElseBlock(currentElseBranch) appendElseBlock(currentElseBranch)
applyFullCommentSaver = false applyFullCommentSaver = false
break break