From 3528405666e81aa09e7941d976ef6cad71d0098e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sat, 9 Jun 2018 14:22:23 +0300 Subject: [PATCH] Minor: reformat --- .../codegen/when/SwitchCodegenProvider.kt | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegenProvider.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegenProvider.kt index a7865f15d4c..f05c3a26d2b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegenProvider.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegenProvider.kt @@ -31,35 +31,36 @@ import org.jetbrains.org.objectweb.asm.Type import java.util.ArrayList class SwitchCodegenProvider -private constructor ( - private val bindingContext: BindingContext, - private val shouldInlineConstVals: Boolean, - private val codegen: ExpressionCodegen? +private constructor( + private val bindingContext: BindingContext, + private val shouldInlineConstVals: Boolean, + private val codegen: ExpressionCodegen? ) { constructor(state: GenerationState) : this(state.bindingContext, state.shouldInlineConstVals, null) constructor(codegen: ExpressionCodegen) : this(codegen.bindingContext, codegen.state.shouldInlineConstVals, codegen) fun checkAllItemsAreConstantsSatisfying(expression: KtWhenExpression, predicate: Function1, Boolean>): Boolean = - expression.entries.all { entry -> - entry.conditions.all { condition -> - if (condition !is KtWhenConditionWithExpression) return false - val patternExpression = condition.expression ?: return false - val constant = ExpressionCodegen.getCompileTimeConstant(patternExpression, bindingContext, shouldInlineConstVals) ?: return false - predicate.invoke(constant) - } + expression.entries.all { entry -> + entry.conditions.all { condition -> + if (condition !is KtWhenConditionWithExpression) return false + val patternExpression = condition.expression ?: return false + val constant = + ExpressionCodegen.getCompileTimeConstant(patternExpression, bindingContext, shouldInlineConstVals) ?: return false + predicate.invoke(constant) } + } fun getAllConstants(expression: KtWhenExpression): Iterable?> = - ArrayList?>().apply { - for (entry in expression.entries) { - addConstantsFromConditions(entry) - } - } - - fun getConstantsFromEntry(entry: KtWhenEntry): Iterable?> = - ArrayList?>().apply { + ArrayList?>().apply { + for (entry in expression.entries) { addConstantsFromConditions(entry) } + } + + fun getConstantsFromEntry(entry: KtWhenEntry): Iterable?> = + ArrayList?>().apply { + addConstantsFromConditions(entry) + } private fun ArrayList?>.addConstantsFromConditions(entry: KtWhenEntry) { for (condition in entry.conditions) { @@ -70,9 +71,9 @@ private constructor ( } fun buildAppropriateSwitchCodegenIfPossible( - expression: KtWhenExpression, - isStatement: Boolean, - isExhaustive: Boolean + expression: KtWhenExpression, + isStatement: Boolean, + isExhaustive: Boolean ): SwitchCodegen? { val codegen = codegen ?: throw AssertionError("Can't create SwitchCodegen in this context") @@ -97,13 +98,13 @@ private constructor ( } private fun isThereConstantEntriesButNulls(expression: KtWhenExpression): Boolean = - getAllConstants(expression).any { it != null && it !is NullValue } + getAllConstants(expression).any { it != null && it !is NullValue } private fun isIntegralConstantsSwitch(expression: KtWhenExpression, subjectType: Type): Boolean = - AsmUtil.isIntPrimitive(subjectType) && - checkAllItemsAreConstantsSatisfying(expression) { it is IntegerValueConstant<*> } + AsmUtil.isIntPrimitive(subjectType) && + checkAllItemsAreConstantsSatisfying(expression) { it is IntegerValueConstant<*> } private fun isStringConstantsSwitch(expression: KtWhenExpression, subjectType: Type): Boolean = - subjectType.className == String::class.java.name && - checkAllItemsAreConstantsSatisfying(expression) { it is StringValue || it is NullValue } + subjectType.className == String::class.java.name && + checkAllItemsAreConstantsSatisfying(expression) { it is StringValue || it is NullValue } }