Cleanup code: BranchedFoldingUtils
This commit is contained in:
+5
-9
@@ -42,18 +42,15 @@ object BranchedFoldingUtils {
|
|||||||
return (branch?.lastBlockStatementOrThis() as? KtBinaryExpression)?.takeIf(::checkAssignment)
|
return (branch?.lastBlockStatementOrThis() as? KtBinaryExpression)?.takeIf(::checkAssignment)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFoldableBranchedReturn(branch: KtExpression?): KtReturnExpression? {
|
fun getFoldableBranchedReturn(branch: KtExpression?): KtReturnExpression? =
|
||||||
return (branch?.lastBlockStatementOrThis() as? KtReturnExpression)?.takeIf { it.returnedExpression != null }
|
(branch?.lastBlockStatementOrThis() as? KtReturnExpression)?.takeIf { it.returnedExpression != null }
|
||||||
}
|
|
||||||
|
|
||||||
fun checkAssignmentsMatch(a1: KtBinaryExpression, a2: KtBinaryExpression): Boolean {
|
fun checkAssignmentsMatch(a1: KtBinaryExpression, a2: KtBinaryExpression): Boolean =
|
||||||
return a1.left?.text == a2.left?.text && a1.operationToken == a2.operationToken
|
a1.left?.text == a2.left?.text && a1.operationToken == a2.operationToken
|
||||||
}
|
|
||||||
|
|
||||||
fun canFoldToAssignment(expression: KtExpression?): Boolean {
|
fun canFoldToAssignment(expression: KtExpression?): Boolean {
|
||||||
val assignments = mutableListOf<KtBinaryExpression>()
|
val assignments = mutableListOf<KtBinaryExpression>()
|
||||||
fun collectAssignmentsAndCheck(e: KtExpression?): Boolean {
|
fun collectAssignmentsAndCheck(e: KtExpression?): Boolean = when (e) {
|
||||||
return when (e) {
|
|
||||||
is KtWhenExpression -> {
|
is KtWhenExpression -> {
|
||||||
val entries = e.entries
|
val entries = e.entries
|
||||||
KtPsiUtil.checkWhenExpressionHasSingleElse(e) &&
|
KtPsiUtil.checkWhenExpressionHasSingleElse(e) &&
|
||||||
@@ -79,7 +76,6 @@ object BranchedFoldingUtils {
|
|||||||
is KtThrowExpression, is KtReturnExpression -> true
|
is KtThrowExpression, is KtReturnExpression -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!collectAssignmentsAndCheck(expression)) return false
|
if (!collectAssignmentsAndCheck(expression)) return false
|
||||||
if (assignments.isEmpty()) return false
|
if (assignments.isEmpty()) return false
|
||||||
val firstAssignment = assignments.first()
|
val firstAssignment = assignments.first()
|
||||||
|
|||||||
Reference in New Issue
Block a user