Refactoring. Remove descriptor from resolution Candidate.

This commit is contained in:
Stanislav Erokhin
2016-09-02 16:09:35 +03:00
parent 794e65b5d6
commit 83a82cdd04
4 changed files with 26 additions and 30 deletions
@@ -321,10 +321,7 @@ class NewResolutionOldInference(
internal data class MyCandidate<out D: CallableDescriptor>( internal data class MyCandidate<out D: CallableDescriptor>(
val candidateStatus: ResolutionCandidateStatus, val candidateStatus: ResolutionCandidateStatus,
val resolvedCall: MutableResolvedCall<@UnsafeVariance D> val resolvedCall: MutableResolvedCall<@UnsafeVariance D>
) : Candidate<D> { ) : Candidate {
override val descriptor: D
get() = resolvedCall.candidateDescriptor
override val isSuccessful: Boolean override val isSuccessful: Boolean
get() = candidateStatus.resultingApplicability.isSuccess get() = candidateStatus.resultingApplicability.isSuccess
override val status: ResolutionCandidateStatus override val status: ResolutionCandidateStatus
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastI
import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.util.OperatorNameConventions
import java.util.* import java.util.*
abstract class AbstractInvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>>( abstract class AbstractInvokeTowerProcessor<F : Candidate, V : Candidate>(
protected val factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>, protected val factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
private val variableProcessor: ScopeTowerProcessor<V> private val variableProcessor: ScopeTowerProcessor<V>
) : ScopeTowerProcessor<F> { ) : ScopeTowerProcessor<F> {
@@ -86,7 +86,7 @@ abstract class AbstractInvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V
} }
// todo KT-9522 Allow invoke convention for synthetic property // todo KT-9522 Allow invoke convention for synthetic property
class InvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>>( class InvokeTowerProcessor<F : Candidate, V : Candidate>(
val scopeTower: ImplicitScopeTower, val scopeTower: ImplicitScopeTower,
val name: Name, val name: Name,
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>, factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
@@ -104,7 +104,7 @@ class InvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<Vari
} }
} }
class InvokeExtensionTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>>( class InvokeExtensionTowerProcessor<F : Candidate, V : Candidate>(
val scopeTower: ImplicitScopeTower, val scopeTower: ImplicitScopeTower,
val name: Name, val name: Name,
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>, factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
@@ -123,7 +123,7 @@ class InvokeExtensionTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candi
} }
} }
private class InvokeExtensionScopeTowerProcessor<C : Candidate<FunctionDescriptor>>( private class InvokeExtensionScopeTowerProcessor<C : Candidate>(
context: CandidateFactory<FunctionDescriptor, C>, context: CandidateFactory<FunctionDescriptor, C>,
private val invokeCandidateDescriptor: CandidateWithBoundDispatchReceiver<FunctionDescriptor>, private val invokeCandidateDescriptor: CandidateWithBoundDispatchReceiver<FunctionDescriptor>,
private val explicitReceiver: ReceiverValueWithSmartCastInfo? private val explicitReceiver: ReceiverValueWithSmartCastInfo?
@@ -159,7 +159,7 @@ private fun ImplicitScopeTower.getExtensionInvokeCandidateDescriptor(
} }
// case 1.(foo())() or (foo())() // case 1.(foo())() or (foo())()
fun <F : Candidate<FunctionDescriptor>> createCallTowerProcessorForExplicitInvoke( fun <F : Candidate> createCallTowerProcessorForExplicitInvoke(
scopeTower: ImplicitScopeTower, scopeTower: ImplicitScopeTower,
functionContext: CandidateFactory<FunctionDescriptor, F>, functionContext: CandidateFactory<FunctionDescriptor, F>,
expressionForInvoke: ReceiverValueWithSmartCastInfo, expressionForInvoke: ReceiverValueWithSmartCastInfo,
@@ -39,7 +39,7 @@ class CompositeScopeTowerProcessor<out C>(
override fun process(data: TowerData): List<Collection<C>> = processors.flatMap { it.process(data) } override fun process(data: TowerData): List<Collection<C>> = processors.flatMap { it.process(data) }
} }
internal abstract class AbstractSimpleScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>( internal abstract class AbstractSimpleScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
val candidateFactory: CandidateFactory<D, C> val candidateFactory: CandidateFactory<D, C>
) : ScopeTowerProcessor<C> { ) : ScopeTowerProcessor<C> {
@@ -51,7 +51,7 @@ internal abstract class AbstractSimpleScopeTowerProcessor<D : CallableDescriptor
private typealias CandidatesCollector<D> = private typealias CandidatesCollector<D> =
ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver<D>> ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver<D>>
internal class ExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>( internal class ExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
val scopeTower: ImplicitScopeTower, val scopeTower: ImplicitScopeTower,
context: CandidateFactory<D, C>, context: CandidateFactory<D, C>,
val explicitReceiver: ReceiverValueWithSmartCastInfo, val explicitReceiver: ReceiverValueWithSmartCastInfo,
@@ -78,7 +78,7 @@ internal class ExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Ca
} }
} }
private class QualifierScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>( private class QualifierScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
val scopeTower: ImplicitScopeTower, val scopeTower: ImplicitScopeTower,
context: CandidateFactory<D, C>, context: CandidateFactory<D, C>,
val qualifier: QualifierReceiver, val qualifier: QualifierReceiver,
@@ -94,7 +94,7 @@ private class QualifierScopeTowerProcessor<D : CallableDescriptor, C: Candidate<
} }
} }
private class NoExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>( private class NoExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate>(
context: CandidateFactory<D, C>, context: CandidateFactory<D, C>,
val collectCandidates: CandidatesCollector<D> val collectCandidates: CandidatesCollector<D>
) : AbstractSimpleScopeTowerProcessor<D, C>(context) { ) : AbstractSimpleScopeTowerProcessor<D, C>(context) {
@@ -120,7 +120,8 @@ private class NoExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: C
} }
} }
private fun <D : CallableDescriptor, C : Candidate<D>> processCommonAndSyntheticMembers(
private fun <D : CallableDescriptor, C : Candidate> processCommonAndSyntheticMembers(
receiverForMember: ReceiverValueWithSmartCastInfo, receiverForMember: ReceiverValueWithSmartCastInfo,
scopeTowerLevel: ScopeTowerLevel, scopeTowerLevel: ScopeTowerLevel,
collectCandidates: CandidatesCollector<D>, collectCandidates: CandidatesCollector<D>,
@@ -149,7 +150,7 @@ private fun <D : CallableDescriptor, C : Candidate<D>> processCommonAndSynthetic
} }
} }
private fun <D : CallableDescriptor, C: Candidate<D>> createSimpleProcessor( private fun <D : CallableDescriptor, C: Candidate> createSimpleProcessor(
scopeTower: ImplicitScopeTower, scopeTower: ImplicitScopeTower,
context: CandidateFactory<D, C>, context: CandidateFactory<D, C>,
explicitReceiver: DetailedReceiver?, explicitReceiver: DetailedReceiver?,
@@ -178,23 +179,23 @@ private fun <D : CallableDescriptor, C: Candidate<D>> createSimpleProcessor(
} }
} }
fun <C : Candidate<VariableDescriptor>> createVariableProcessor(scopeTower: ImplicitScopeTower, name: Name, fun <C : Candidate> createVariableProcessor(scopeTower: ImplicitScopeTower, name: Name,
context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getVariables(name, it) } ) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getVariables(name, it) }
fun <C : Candidate<VariableDescriptor>> createVariableAndObjectProcessor(scopeTower: ImplicitScopeTower, name: Name, fun <C : Candidate> createVariableAndObjectProcessor(scopeTower: ImplicitScopeTower, name: Name,
context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
) = CompositeScopeTowerProcessor( ) = CompositeScopeTowerProcessor(
createVariableProcessor(scopeTower, name, context, explicitReceiver), createVariableProcessor(scopeTower, name, context, explicitReceiver),
createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getObjects(name, it) } createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getObjects(name, it) }
) )
fun <C : Candidate<FunctionDescriptor>> createSimpleFunctionProcessor(scopeTower: ImplicitScopeTower, name: Name, fun <C : Candidate> createSimpleFunctionProcessor(scopeTower: ImplicitScopeTower, name: Name,
context: CandidateFactory<FunctionDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true context: CandidateFactory<FunctionDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getFunctions(name, it) } ) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getFunctions(name, it) }
fun <F: Candidate<FunctionDescriptor>, V: Candidate<VariableDescriptor>> createFunctionProcessor( fun <F: Candidate, V: Candidate> createFunctionProcessor(
scopeTower: ImplicitScopeTower, scopeTower: ImplicitScopeTower,
name: Name, name: Name,
simpleContext: CandidateFactory<FunctionDescriptor, F>, simpleContext: CandidateFactory<FunctionDescriptor, F>,
@@ -217,7 +218,7 @@ fun <F: Candidate<FunctionDescriptor>, V: Candidate<VariableDescriptor>> createF
} }
fun <D : CallableDescriptor, C: Candidate<D>> createProcessorWithReceiverValueOrEmpty( fun <C: Candidate> createProcessorWithReceiverValueOrEmpty(
explicitReceiver: DetailedReceiver?, explicitReceiver: DetailedReceiver?,
create: (ReceiverValueWithSmartCastInfo?) -> ScopeTowerProcessor<C> create: (ReceiverValueWithSmartCastInfo?) -> ScopeTowerProcessor<C>
): ScopeTowerProcessor<C> { ): ScopeTowerProcessor<C> {
@@ -27,16 +27,14 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastI
import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
import java.util.* import java.util.*
interface Candidate<out D : CallableDescriptor> { interface Candidate {
val descriptor: D
// this operation should be very fast // this operation should be very fast
val isSuccessful: Boolean val isSuccessful: Boolean
val status: ResolutionCandidateStatus val status: ResolutionCandidateStatus
} }
interface CandidateFactory<D : CallableDescriptor, out C: Candidate<D>> { interface CandidateFactory<in D : CallableDescriptor, out C: Candidate> {
fun createCandidate( fun createCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver<D>, towerCandidate: CandidateWithBoundDispatchReceiver<D>,
explicitReceiverKind: ExplicitReceiverKind, explicitReceiverKind: ExplicitReceiverKind,
@@ -44,7 +42,7 @@ interface CandidateFactory<D : CallableDescriptor, out C: Candidate<D>> {
): C ): C
} }
interface CandidateFactoryProviderForInvoke<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>> { interface CandidateFactoryProviderForInvoke<F : Candidate, V : Candidate> {
fun transformCandidate(variable: V, invoke: F): F fun transformCandidate(variable: V, invoke: F): F
@@ -69,13 +67,13 @@ interface ScopeTowerProcessor<out C> {
} }
class TowerResolver { class TowerResolver {
fun <C: Candidate<*>> runResolve( fun <C: Candidate> runResolve(
scopeTower: ImplicitScopeTower, scopeTower: ImplicitScopeTower,
processor: ScopeTowerProcessor<C>, processor: ScopeTowerProcessor<C>,
useOrder: Boolean useOrder: Boolean
): Collection<C> = scopeTower.run(processor, SuccessfulResultCollector { it.status }, useOrder) ): Collection<C> = scopeTower.run(processor, SuccessfulResultCollector { it.status }, useOrder)
fun <C: Candidate<*>> collectAllCandidates( fun <C: Candidate> collectAllCandidates(
scopeTower: ImplicitScopeTower, scopeTower: ImplicitScopeTower,
processor: ScopeTowerProcessor<C> processor: ScopeTowerProcessor<C>
): Collection<C> ): Collection<C>