Extract CallableReferenceCandidate into separate file

This commit is contained in:
Victor Petukhov
2021-09-20 14:17:34 +03:00
parent dedac63a8c
commit 4fcb16b4c4
2 changed files with 52 additions and 36 deletions
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.model.CompatibilityWarning
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.tower.Candidate
import org.jetbrains.kotlin.resolve.calls.tower.getResultApplicability
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
import org.jetbrains.kotlin.types.UnwrappedType
/**
* Suppose we have class A with staticM, memberM, memberExtM.
* For A::staticM both receivers will be null
* For A::memberM dispatchReceiver = UnboundReceiver, extensionReceiver = null
* For a::memberExtM dispatchReceiver = ExplicitValueReceiver, extensionReceiver = ExplicitValueReceiver
*
* For class B with companion object B::companionM dispatchReceiver = BoundValueReference
*/
class CallableReferenceCandidate(
val candidate: CallableDescriptor,
val dispatchReceiver: CallableReceiver?,
val extensionReceiver: CallableReceiver?,
val explicitReceiverKind: ExplicitReceiverKind,
val reflectionCandidateType: UnwrappedType,
val callableReferenceAdaptation: CallableReferenceAdaptation?,
initialDiagnostics: List<KotlinCallDiagnostic>
) : Candidate {
private val mutableDiagnostics = initialDiagnostics.toMutableList()
val diagnostics: List<KotlinCallDiagnostic> = mutableDiagnostics
override val resultingApplicability = getResultApplicability(diagnostics)
override fun addCompatibilityWarning(other: Candidate) {
if (this !== other && other is CallableReferenceCandidate) {
mutableDiagnostics.add(CompatibilityWarning(other.candidate))
}
}
override val isSuccessful get() = resultingApplicability.isSuccess
var freshSubstitutor: FreshVariableNewTypeSubstitutor? = null
internal set
val numDefaults get() = callableReferenceAdaptation?.defaults ?: 0
}
@@ -44,42 +44,6 @@ sealed class CallableReceiver(val receiver: ReceiverValueWithSmartCastInfo) {
private val CallableReceiver.asReceiverValueForVisibilityChecks: ReceiverValue
get() = receiver.receiverValue
/**
* Suppose we have class A with staticM, memberM, memberExtM.
* For A::staticM both receivers will be null
* For A::memberM dispatchReceiver = UnboundReceiver, extensionReceiver = null
* For a::memberExtM dispatchReceiver = ExplicitValueReceiver, extensionReceiver = ExplicitValueReceiver
*
* For class B with companion object B::companionM dispatchReceiver = BoundValueReference
*/
class CallableReferenceCandidate(
val candidate: CallableDescriptor,
val dispatchReceiver: CallableReceiver?,
val extensionReceiver: CallableReceiver?,
val explicitReceiverKind: ExplicitReceiverKind,
val reflectionCandidateType: UnwrappedType,
val callableReferenceAdaptation: CallableReferenceAdaptation?,
initialDiagnostics: List<KotlinCallDiagnostic>
) : Candidate {
private val mutableDiagnostics = initialDiagnostics.toMutableList()
val diagnostics: List<KotlinCallDiagnostic> = mutableDiagnostics
override val resultingApplicability = getResultApplicability(diagnostics)
override fun addCompatibilityWarning(other: Candidate) {
if (this !== other && other is CallableReferenceCandidate) {
mutableDiagnostics.add(CompatibilityWarning(other.candidate))
}
}
override val isSuccessful get() = resultingApplicability.isSuccess
var freshSubstitutor: FreshVariableNewTypeSubstitutor? = null
internal set
val numDefaults get() = callableReferenceAdaptation?.defaults ?: 0
}
class CallableReferenceAdaptation(
val argumentTypes: Array<KotlinType>,
val coercionStrategy: CoercionStrategy,