diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt index 6e6c3da5ef6..b71dbba01c5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt @@ -33,63 +33,47 @@ abstract class ControlFlowBuilderAdapter : ControlFlowBuilder { delegateBuilder.loadUnit(expression) } - override fun loadConstant(expression: KtExpression, constant: CompileTimeConstant<*>?): InstructionWithValue { - return delegateBuilder.loadConstant(expression, constant) - } + override fun loadConstant(expression: KtExpression, constant: CompileTimeConstant<*>?): InstructionWithValue = + delegateBuilder.loadConstant(expression, constant) - override fun createAnonymousObject(expression: KtObjectLiteralExpression): InstructionWithValue { - return delegateBuilder.createAnonymousObject(expression) - } + override fun createAnonymousObject(expression: KtObjectLiteralExpression): InstructionWithValue = + delegateBuilder.createAnonymousObject(expression) - override fun createLambda(expression: KtFunction): InstructionWithValue { - return delegateBuilder.createLambda(expression) - } + override fun createLambda(expression: KtFunction): InstructionWithValue = delegateBuilder.createLambda(expression) - override fun loadStringTemplate(expression: KtStringTemplateExpression, inputValues: List): InstructionWithValue { - return delegateBuilder.loadStringTemplate(expression, inputValues) - } + override fun loadStringTemplate(expression: KtStringTemplateExpression, inputValues: List): InstructionWithValue = + delegateBuilder.loadStringTemplate(expression, inputValues) override fun magic( instructionElement: KtElement, valueElement: KtElement?, inputValues: List, - kind: MagicKind): MagicInstruction { - return delegateBuilder.magic(instructionElement, valueElement, inputValues, kind) - } + kind: MagicKind): MagicInstruction = delegateBuilder.magic(instructionElement, valueElement, inputValues, kind) - override fun merge(expression: KtExpression, inputValues: List): MergeInstruction { - return delegateBuilder.merge(expression, inputValues) - } + override fun merge(expression: KtExpression, inputValues: List): MergeInstruction = + delegateBuilder.merge(expression, inputValues) override fun readVariable( expression: KtExpression, resolvedCall: ResolvedCall<*>, - receiverValues: Map): ReadValueInstruction { - return delegateBuilder.readVariable(expression, resolvedCall, receiverValues) - } + receiverValues: Map): ReadValueInstruction = + delegateBuilder.readVariable(expression, resolvedCall, receiverValues) override fun call( valueElement: KtElement, resolvedCall: ResolvedCall<*>, receiverValues: Map, - arguments: Map): CallInstruction { - return delegateBuilder.call(valueElement, resolvedCall, receiverValues, arguments) - } + arguments: Map): CallInstruction = + delegateBuilder.call(valueElement, resolvedCall, receiverValues, arguments) override fun predefinedOperation( expression: KtExpression, operation: ControlFlowBuilder.PredefinedOperation, - inputValues: List): OperationInstruction { - return delegateBuilder.predefinedOperation(expression, operation, inputValues) - } + inputValues: List): OperationInstruction = delegateBuilder.predefinedOperation(expression, operation, inputValues) - override fun createUnboundLabel(): Label { - return delegateBuilder.createUnboundLabel() - } + override fun createUnboundLabel(): Label = delegateBuilder.createUnboundLabel() - override fun createUnboundLabel(name: String): Label { - return delegateBuilder.createUnboundLabel(name) - } + override fun createUnboundLabel(name: String): Label = delegateBuilder.createUnboundLabel(name) override fun bindLabel(label: Label) { delegateBuilder.bindLabel(label) @@ -123,21 +107,13 @@ abstract class ControlFlowBuilderAdapter : ControlFlowBuilder { delegateBuilder.throwException(throwExpression, thrownValue) } - override fun getSubroutineExitPoint(labelElement: KtElement): Label? { - return delegateBuilder.getSubroutineExitPoint(labelElement) - } + override fun getSubroutineExitPoint(labelElement: KtElement): Label? = delegateBuilder.getSubroutineExitPoint(labelElement) - override fun getLoopConditionEntryPoint(loop: KtLoopExpression): Label? { - return delegateBuilder.getLoopConditionEntryPoint(loop) - } + override fun getLoopConditionEntryPoint(loop: KtLoopExpression): Label? = delegateBuilder.getLoopConditionEntryPoint(loop) - override fun getLoopExitPoint(loop: KtLoopExpression): Label? { - return delegateBuilder.getLoopExitPoint(loop) - } + override fun getLoopExitPoint(loop: KtLoopExpression): Label? = delegateBuilder.getLoopExitPoint(loop) - override fun enterLoop(expression: KtLoopExpression): LoopInfo { - return delegateBuilder.enterLoop(expression) - } + override fun enterLoop(expression: KtLoopExpression): LoopInfo = delegateBuilder.enterLoop(expression) override fun enterLoopBody(expression: KtLoopExpression) { delegateBuilder.enterLoopBody(expression) @@ -162,9 +138,7 @@ abstract class ControlFlowBuilderAdapter : ControlFlowBuilder { delegateBuilder.enterSubroutine(subroutine) } - override fun exitSubroutine(subroutine: KtElement): Pseudocode { - return delegateBuilder.exitSubroutine(subroutine) - } + override fun exitSubroutine(subroutine: KtElement): Pseudocode = delegateBuilder.exitSubroutine(subroutine) override val currentSubroutine: KtElement get() = delegateBuilder.currentSubroutine @@ -216,17 +190,13 @@ abstract class ControlFlowBuilderAdapter : ControlFlowBuilder { delegateBuilder.mark(element) } - override fun getBoundValue(element: KtElement?): PseudoValue? { - return delegateBuilder.getBoundValue(element) - } + override fun getBoundValue(element: KtElement?): PseudoValue? = delegateBuilder.getBoundValue(element) override fun bindValue(value: PseudoValue, element: KtElement) { delegateBuilder.bindValue(value, element) } - override fun newValue(element: KtElement?): PseudoValue { - return delegateBuilder.newValue(element) - } + override fun newValue(element: KtElement?): PseudoValue = delegateBuilder.newValue(element) override fun enterBlockScope(block: KtElement) { delegateBuilder.enterBlockScope(block) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInfo.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInfo.kt index f7733349714..b894cf2dfb8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInfo.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInfo.kt @@ -102,13 +102,9 @@ enum class InitState(private val s: String) { class VariableControlFlowState private constructor(val initState: InitState, val isDeclared: Boolean) { - fun definitelyInitialized(): Boolean { - return initState == InitState.INITIALIZED - } + fun definitelyInitialized(): Boolean = initState == InitState.INITIALIZED - fun mayBeInitialized(): Boolean { - return initState != InitState.NOT_INITIALIZED - } + fun mayBeInitialized(): Boolean = initState != InitState.NOT_INITIALIZED override fun toString(): String { if (initState == InitState.NOT_INITIALIZED && !isDeclared) return "-" @@ -134,17 +130,14 @@ class VariableControlFlowState private constructor(val initState: InitState, val InitState.NOT_INITIALIZED -> if (isDeclared) VS_NT else VS_NF } - fun createInitializedExhaustively(isDeclared: Boolean): VariableControlFlowState { - return create(InitState.INITIALIZED_EXHAUSTIVELY, isDeclared) - } + fun createInitializedExhaustively(isDeclared: Boolean): VariableControlFlowState = + create(InitState.INITIALIZED_EXHAUSTIVELY, isDeclared) - fun create(isInitialized: Boolean, isDeclared: Boolean = false): VariableControlFlowState { - return create(if (isInitialized) InitState.INITIALIZED else InitState.NOT_INITIALIZED, isDeclared) - } + fun create(isInitialized: Boolean, isDeclared: Boolean = false): VariableControlFlowState = + create(if (isInitialized) InitState.INITIALIZED else InitState.NOT_INITIALIZED, isDeclared) - fun create(isDeclaredHere: Boolean, mergedEdgesData: VariableControlFlowState?): VariableControlFlowState { - return create(true, isDeclaredHere || mergedEdgesData != null && mergedEdgesData.isDeclared) - } + fun create(isDeclaredHere: Boolean, mergedEdgesData: VariableControlFlowState?): VariableControlFlowState = + create(true, isDeclaredHere || mergedEdgesData != null && mergedEdgesData.isDeclared) } } @@ -162,9 +155,7 @@ enum class VariableUseState(private val priority: Int) { companion object { @JvmStatic - fun isUsed(variableUseState: VariableUseState?): Boolean { - return variableUseState != null && variableUseState != UNUSED - } + fun isUsed(variableUseState: VariableUseState?): Boolean = variableUseState != null && variableUseState != UNUSED } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt index b7d937998ea..7d4a9569567 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt @@ -59,7 +59,6 @@ import org.jetbrains.kotlin.types.TypeUtils.* import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import org.jetbrains.kotlin.types.isFlexible import org.jetbrains.kotlin.util.OperatorNameConventions -import java.util.* class ControlFlowInformationProvider private constructor( private val subroutine: KtElement, @@ -311,7 +310,7 @@ class ControlFlowInformationProvider private constructor( } private fun PropertyDescriptor.isDefinitelyInitialized(): Boolean { - if (trace.get(BACKING_FIELD_REQUIRED, this) ?: false) return false + if (trace.get(BACKING_FIELD_REQUIRED, this) == true) return false val property = DescriptorToSourceUtils.descriptorToDeclaration(this) if (property is KtProperty && property.hasDelegate()) return false return true @@ -432,14 +431,14 @@ class ControlFlowInformationProvider private constructor( if (operationReference != null) { val descriptor = trace.get(BindingContext.REFERENCE_TARGET, operationReference) if (descriptor is FunctionDescriptor) { - if (descriptor.returnType?.let { KotlinBuiltIns.isUnit(it) } ?: false) { + if (descriptor.returnType?.let { KotlinBuiltIns.isUnit(it) } == true) { hasReassignMethodReturningUnit = true } } if (descriptor == null) { val descriptors = trace.get(BindingContext.AMBIGUOUS_REFERENCE_TARGET, operationReference) ?: emptyList() for (referenceDescriptor in descriptors) { - if ((referenceDescriptor as? FunctionDescriptor)?.returnType?.let { KotlinBuiltIns.isUnit(it) } ?: false) { + if ((referenceDescriptor as? FunctionDescriptor)?.returnType?.let { KotlinBuiltIns.isUnit(it) } == true) { hasReassignMethodReturningUnit = true } } @@ -476,10 +475,10 @@ class ControlFlowInformationProvider private constructor( } private fun checkAssignmentBeforeDeclaration(ctxt: VariableInitContext, expression: KtExpression) = - if (ctxt.enterInitState?.isDeclared ?: false - || ctxt.exitInitState?.isDeclared ?: false - || ctxt.enterInitState?.mayBeInitialized() ?: false - || !(ctxt.exitInitState?.mayBeInitialized() ?: false)) { + if (ctxt.enterInitState?.isDeclared == true + || ctxt.exitInitState?.isDeclared == true + || ctxt.enterInitState?.mayBeInitialized() == true + || ctxt.exitInitState?.mayBeInitialized() != true) { false } else { @@ -492,10 +491,10 @@ class ControlFlowInformationProvider private constructor( private fun checkInitializationForCustomSetter(ctxt: VariableInitContext, expression: KtExpression): Boolean { val variableDescriptor = ctxt.variableDescriptor if (variableDescriptor !is PropertyDescriptor - || ctxt.enterInitState?.mayBeInitialized() ?: false - || !(ctxt.exitInitState?.mayBeInitialized() ?: false) + || ctxt.enterInitState?.mayBeInitialized() == true + || ctxt.exitInitState?.mayBeInitialized() != true || !variableDescriptor.isVar - || !(trace.get(BindingContext.BACKING_FIELD_REQUIRED, variableDescriptor) ?: false)) { + || trace.get(BindingContext.BACKING_FIELD_REQUIRED, variableDescriptor) != true) { return false } @@ -528,7 +527,7 @@ class ControlFlowInformationProvider private constructor( val declaredVariables = pseudocodeVariablesData.getDeclaredVariables(pseudocode, false) for (variable in declaredVariables) { if (variable is PropertyDescriptor) { - if (initializers.incoming.getOrNull(variable)?.definitelyInitialized() ?: false) continue + if (initializers.incoming.getOrNull(variable)?.definitelyInitialized() == true) continue trace.record(BindingContext.IS_UNINITIALIZED, variable) } } @@ -947,7 +946,7 @@ class ControlFlowInformationProvider private constructor( val tailInstructionDetector = TailInstructionDetector(subroutine) return traverseFollowingInstructions( this, - HashSet(), + hashSetOf(), TraversalOrder.FORWARD ) { if (it == this@isTailCall || it.accept(tailInstructionDetector)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt index ca2c1924cc0..081718f7685 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt @@ -117,9 +117,8 @@ class ControlFlowProcessor(private val trace: BindingTrace) { private val conditionVisitor = object : KtVisitorVoid() { - private fun getSubjectExpression(condition: KtWhenCondition): KtExpression? { - return condition.getStrictParentOfType()?.subjectExpression - } + private fun getSubjectExpression(condition: KtWhenCondition): KtExpression? = + condition.getStrictParentOfType()?.subjectExpression override fun visitWhenConditionInRange(condition: KtWhenConditionInRange) { if (!generateCall(condition.operationReference)) { @@ -181,17 +180,14 @@ class ControlFlowProcessor(private val trace: BindingTrace) { } } - private fun createSyntheticValue(instructionElement: KtElement, kind: MagicKind, vararg from: KtElement): PseudoValue { - return builder.magic(instructionElement, null, elementsToValues(from.asList()), kind).outputValue - } + private fun createSyntheticValue(instructionElement: KtElement, kind: MagicKind, vararg from: KtElement): PseudoValue = + builder.magic(instructionElement, null, elementsToValues(from.asList()), kind).outputValue - private fun createNonSyntheticValue(to: KtElement, from: List, kind: MagicKind): PseudoValue { - return builder.magic(to, to, elementsToValues(from), kind).outputValue - } + private fun createNonSyntheticValue(to: KtElement, from: List, kind: MagicKind): PseudoValue = + builder.magic(to, to, elementsToValues(from), kind).outputValue - private fun createNonSyntheticValue(to: KtElement, kind: MagicKind, vararg from: KtElement?): PseudoValue { - return createNonSyntheticValue(to, from.asList(), kind) - } + private fun createNonSyntheticValue(to: KtElement, kind: MagicKind, vararg from: KtElement?): PseudoValue = + createNonSyntheticValue(to, from.asList(), kind) private fun mergeValues(from: List, to: KtExpression) { builder.merge(to, elementsToValues(from)) @@ -208,18 +204,16 @@ class ControlFlowProcessor(private val trace: BindingTrace) { return if (value != null || element is KtDeclaration) value else builder.newValue(element) } - private fun elementsToValues(from: List): List { - return from.mapNotNull { element -> getBoundOrUnreachableValue(element) } - } + private fun elementsToValues(from: List): List = + from.mapNotNull { element -> getBoundOrUnreachableValue(element) } private fun generateInitializer(declaration: KtDeclaration, initValue: PseudoValue) { builder.write(declaration, declaration, initValue, getDeclarationAccessTarget(declaration), emptyMap()) } - private fun getResolvedCallAccessTarget(element: KtElement?): AccessTarget { - return element.getResolvedCall(trace.bindingContext)?.let { AccessTarget.Call(it) } - ?: AccessTarget.BlackBox - } + private fun getResolvedCallAccessTarget(element: KtElement?): AccessTarget = + element.getResolvedCall(trace.bindingContext)?.let { AccessTarget.Call(it) } + ?: AccessTarget.BlackBox private fun getDeclarationAccessTarget(element: KtElement): AccessTarget { val descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element) @@ -533,9 +527,8 @@ class ControlFlowProcessor(private val trace: BindingTrace) { } } - private fun isIncrementOrDecrement(operationType: IElementType): Boolean { - return operationType === KtTokens.PLUSPLUS || operationType === KtTokens.MINUSMINUS - } + private fun isIncrementOrDecrement(operationType: IElementType): Boolean = + operationType === KtTokens.PLUSPLUS || operationType === KtTokens.MINUSMINUS override fun visitIfExpression(expression: KtIfExpression) { mark(expression) @@ -668,7 +661,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) { builder.bindLabel(onException) val catchLabels = LinkedList