Reformat: if to when
This commit is contained in:
+13
-16
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user