Refactoring: rename TowerContext to CandidatesFactory, InvokeTowerContext to CandidateFactoryProviderForInvoke.
This commit is contained in:
+20
-20
@@ -77,8 +77,8 @@ class NewResolutionOldInference(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<FunctionDescriptor>> {
|
||||
val functionContext = outer.SimpleContext<FunctionDescriptor>(name, context, tracing)
|
||||
return createFunctionProcessor(scopeTower, name, functionContext, outer.InvokeContext(functionContext), explicitReceiver)
|
||||
val functionFactory = outer.CandidateFactoryImpl<FunctionDescriptor>(name, context, tracing)
|
||||
return createFunctionProcessor(scopeTower, name, functionFactory, outer.CandidateFactoryProviderForInvokeImpl(functionFactory), explicitReceiver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ class NewResolutionOldInference(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<VariableDescriptor>> {
|
||||
val simpleContext = outer.SimpleContext<VariableDescriptor>(name, context, tracing)
|
||||
return createVariableAndObjectProcessor(scopeTower, name, simpleContext, explicitReceiver)
|
||||
val variableFactory = outer.CandidateFactoryImpl<VariableDescriptor>(name, context, tracing)
|
||||
return createVariableAndObjectProcessor(scopeTower, name, variableFactory, explicitReceiver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +97,11 @@ class NewResolutionOldInference(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<CallableDescriptor>> {
|
||||
val simpleContextF = outer.SimpleContext<FunctionDescriptor>(name, context, tracing)
|
||||
val simpleContextV = outer.SimpleContext<VariableDescriptor>(name, context, tracing)
|
||||
val functionFactory = outer.CandidateFactoryImpl<FunctionDescriptor>(name, context, tracing)
|
||||
val variableFactory = outer.CandidateFactoryImpl<VariableDescriptor>(name, context, tracing)
|
||||
return CompositeScopeTowerProcessor(
|
||||
createSimpleFunctionProcessor(scopeTower, name, simpleContextF, explicitReceiver, classValueReceiver = false),
|
||||
createVariableProcessor(scopeTower, name, simpleContextV, explicitReceiver, classValueReceiver = false)
|
||||
createSimpleFunctionProcessor(scopeTower, name, functionFactory, explicitReceiver, classValueReceiver = false),
|
||||
createVariableProcessor(scopeTower, name, variableFactory, explicitReceiver, classValueReceiver = false)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -111,13 +111,13 @@ class NewResolutionOldInference(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate<FunctionDescriptor>> {
|
||||
val functionContext = outer.SimpleContext<FunctionDescriptor>(name, context, tracing)
|
||||
val functionFactory = outer.CandidateFactoryImpl<FunctionDescriptor>(name, context, tracing)
|
||||
// todo
|
||||
val call = (context.call as? CallTransformer.CallForImplicitInvoke).sure {
|
||||
"Call should be CallForImplicitInvoke, but it is: ${context.call}"
|
||||
}
|
||||
return createProcessorWithReceiverValueOrEmpty(explicitReceiver) {
|
||||
createCallTowerProcessorForExplicitInvoke(scopeTower, functionContext, context.transformToReceiverWithSmartCastInfo(call.dispatchReceiver), it)
|
||||
createCallTowerProcessorForExplicitInvoke(scopeTower, functionFactory, context.transformToReceiverWithSmartCastInfo(call.dispatchReceiver), it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,11 +273,11 @@ class NewResolutionOldInference(
|
||||
get() = candidateStatus
|
||||
}
|
||||
|
||||
private inner class SimpleContext<D : CallableDescriptor>(
|
||||
private inner class CandidateFactoryImpl<D : CallableDescriptor>(
|
||||
val name: Name,
|
||||
val basicCallContext: BasicCallResolutionContext,
|
||||
val tracing: TracingStrategy
|
||||
) : TowerContext<D, MyCandidate<D>> {
|
||||
) : CandidateFactory<D, MyCandidate<D>> {
|
||||
override fun createCandidate(
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver<D>,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
@@ -327,9 +327,9 @@ class NewResolutionOldInference(
|
||||
|
||||
}
|
||||
|
||||
private inner class InvokeContext(
|
||||
val functionContext: SimpleContext<FunctionDescriptor>
|
||||
) : InvokeTowerContext<MyCandidate<FunctionDescriptor>, MyCandidate<VariableDescriptor>> {
|
||||
private inner class CandidateFactoryProviderForInvokeImpl(
|
||||
val functionContext: CandidateFactoryImpl<FunctionDescriptor>
|
||||
) : CandidateFactoryProviderForInvoke<MyCandidate<FunctionDescriptor>, MyCandidate<VariableDescriptor>> {
|
||||
|
||||
override fun transformCandidate(
|
||||
variable: MyCandidate<VariableDescriptor>,
|
||||
@@ -346,17 +346,17 @@ class NewResolutionOldInference(
|
||||
return MyCandidate(ResolutionCandidateStatus(variable.candidateStatus.diagnostics + invoke.candidateStatus.diagnostics), resolvedCallImpl)
|
||||
}
|
||||
|
||||
override fun contextForVariable(stripExplicitReceiver: Boolean): TowerContext<VariableDescriptor, MyCandidate<VariableDescriptor>> {
|
||||
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<VariableDescriptor, MyCandidate<VariableDescriptor>> {
|
||||
val newCall = CallTransformer.stripCallArguments(functionContext.basicCallContext.call).let {
|
||||
if (stripExplicitReceiver) CallTransformer.stripReceiver(it) else it
|
||||
}
|
||||
return SimpleContext(functionContext.name, functionContext.basicCallContext.replaceCall(newCall), functionContext.tracing)
|
||||
return CandidateFactoryImpl(functionContext.name, functionContext.basicCallContext.replaceCall(newCall), functionContext.tracing)
|
||||
}
|
||||
|
||||
override fun contextForInvoke(
|
||||
override fun factoryForInvoke(
|
||||
variable: MyCandidate<VariableDescriptor>,
|
||||
useExplicitReceiver: Boolean
|
||||
): Pair<ReceiverValueWithSmartCastInfo, TowerContext<FunctionDescriptor, MyCandidate<FunctionDescriptor>>>? {
|
||||
): Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<FunctionDescriptor, MyCandidate<FunctionDescriptor>>>? {
|
||||
assert(variable.resolvedCall.status.possibleTransformToSuccess()) {
|
||||
"Incorrect status: ${variable.resolvedCall.status} for variable call: ${variable.resolvedCall} " +
|
||||
"and descriptor: ${variable.resolvedCall.candidateDescriptor}"
|
||||
@@ -386,7 +386,7 @@ class NewResolutionOldInference(
|
||||
.replaceCall(functionCall)
|
||||
.replaceContextDependency(ContextDependency.DEPENDENT) // todo
|
||||
|
||||
val newContext = SimpleContext<FunctionDescriptor>(OperatorNameConventions.INVOKE, basicCallResolutionContext, tracingForInvoke)
|
||||
val newContext = CandidateFactoryImpl<FunctionDescriptor>(OperatorNameConventions.INVOKE, basicCallResolutionContext, tracingForInvoke)
|
||||
|
||||
return basicCallResolutionContext.transformToReceiverWithSmartCastInfo(variableReceiver) to newContext
|
||||
}
|
||||
|
||||
+12
-12
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import java.util.*
|
||||
|
||||
abstract class AbstractInvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>>(
|
||||
protected val invokeContext: InvokeTowerContext<F, V>,
|
||||
protected val factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
private val variableProcessor: ScopeTowerProcessor<V>
|
||||
) : ScopeTowerProcessor<F> {
|
||||
// todo optimize it
|
||||
@@ -40,7 +40,7 @@ abstract class AbstractInvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V
|
||||
|
||||
override fun process(data: TowerData)
|
||||
= invokeProcessor.process(data).map { candidateGroup ->
|
||||
candidateGroup.map { invokeContext.transformCandidate(variableCandidate, it) }
|
||||
candidateGroup.map { factoryProviderForInvoke.transformCandidate(variableCandidate, it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,16 +89,16 @@ abstract class AbstractInvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V
|
||||
class InvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val name: Name,
|
||||
invokeContext: InvokeTowerContext<F, V>,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
explicitReceiver: DetailedReceiver?
|
||||
) : AbstractInvokeTowerProcessor<F, V>(
|
||||
invokeContext,
|
||||
createVariableAndObjectProcessor(scopeTower, name, invokeContext.contextForVariable(stripExplicitReceiver = false), explicitReceiver)
|
||||
factoryProviderForInvoke,
|
||||
createVariableAndObjectProcessor(scopeTower, name, factoryProviderForInvoke.factoryForVariable(stripExplicitReceiver = false), explicitReceiver)
|
||||
) {
|
||||
|
||||
// todo filter by operator
|
||||
override fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F> {
|
||||
val (variableReceiver, invokeContext) = invokeContext.contextForInvoke(variableCandidate, useExplicitReceiver = false)
|
||||
val (variableReceiver, invokeContext) = factoryProviderForInvoke.factoryForInvoke(variableCandidate, useExplicitReceiver = false)
|
||||
?: return KnownResultProcessor(emptyList())
|
||||
return ExplicitReceiverScopeTowerProcessor(scopeTower, invokeContext, variableReceiver) { getFunctions(OperatorNameConventions.INVOKE, it) }
|
||||
}
|
||||
@@ -107,15 +107,15 @@ class InvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<Vari
|
||||
class InvokeExtensionTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val name: Name,
|
||||
invokeContext: InvokeTowerContext<F, V>,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
private val explicitReceiver: ReceiverValueWithSmartCastInfo?
|
||||
) : AbstractInvokeTowerProcessor<F, V>(
|
||||
invokeContext,
|
||||
createVariableAndObjectProcessor(scopeTower, name, invokeContext.contextForVariable(stripExplicitReceiver = true), explicitReceiver = null)
|
||||
factoryProviderForInvoke,
|
||||
createVariableAndObjectProcessor(scopeTower, name, factoryProviderForInvoke.factoryForVariable(stripExplicitReceiver = true), explicitReceiver = null)
|
||||
) {
|
||||
|
||||
override fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F> {
|
||||
val (variableReceiver, invokeContext) = invokeContext.contextForInvoke(variableCandidate, useExplicitReceiver = true)
|
||||
val (variableReceiver, invokeContext) = factoryProviderForInvoke.factoryForInvoke(variableCandidate, useExplicitReceiver = true)
|
||||
?: return KnownResultProcessor(emptyList())
|
||||
val invokeDescriptor = scopeTower.getExtensionInvokeCandidateDescriptor(variableReceiver)
|
||||
?: return KnownResultProcessor(emptyList())
|
||||
@@ -124,7 +124,7 @@ class InvokeExtensionTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candi
|
||||
}
|
||||
|
||||
private class InvokeExtensionScopeTowerProcessor<C : Candidate<FunctionDescriptor>>(
|
||||
context: TowerContext<FunctionDescriptor, C>,
|
||||
context: CandidateFactory<FunctionDescriptor, C>,
|
||||
private val invokeCandidateDescriptor: CandidateWithBoundDispatchReceiver<FunctionDescriptor>,
|
||||
private val explicitReceiver: ReceiverValueWithSmartCastInfo?
|
||||
) : AbstractSimpleScopeTowerProcessor<FunctionDescriptor, C>(context) {
|
||||
@@ -159,7 +159,7 @@ private fun ImplicitScopeTower.getExtensionInvokeCandidateDescriptor(
|
||||
// case 1.(foo())() or (foo())()
|
||||
fun <F : Candidate<FunctionDescriptor>> createCallTowerProcessorForExplicitInvoke(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
functionContext: TowerContext<FunctionDescriptor, F>,
|
||||
functionContext: CandidateFactory<FunctionDescriptor, F>,
|
||||
expressionForInvoke: ReceiverValueWithSmartCastInfo,
|
||||
explicitReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): ScopeTowerProcessor<F> {
|
||||
|
||||
+12
-12
@@ -41,7 +41,7 @@ class CompositeScopeTowerProcessor<out C>(
|
||||
}
|
||||
|
||||
internal abstract class AbstractSimpleScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>(
|
||||
val context: TowerContext<D, C>
|
||||
val context: CandidateFactory<D, C>
|
||||
) : ScopeTowerProcessor<C> {
|
||||
|
||||
protected abstract fun simpleProcess(data: TowerData): Collection<C>
|
||||
@@ -51,7 +51,7 @@ internal abstract class AbstractSimpleScopeTowerProcessor<D : CallableDescriptor
|
||||
|
||||
internal class ExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
context: TowerContext<D, C>,
|
||||
context: CandidateFactory<D, C>,
|
||||
val explicitReceiver: ReceiverValueWithSmartCastInfo,
|
||||
val collectCandidates: ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver<D>>
|
||||
): AbstractSimpleScopeTowerProcessor<D, C>(context) {
|
||||
@@ -77,7 +77,7 @@ internal class ExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Ca
|
||||
|
||||
private class QualifierScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
context: TowerContext<D, C>,
|
||||
context: CandidateFactory<D, C>,
|
||||
val qualifier: QualifierReceiver,
|
||||
val collectCandidates: ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver<D>>
|
||||
): AbstractSimpleScopeTowerProcessor<D, C>(context) {
|
||||
@@ -92,7 +92,7 @@ private class QualifierScopeTowerProcessor<D : CallableDescriptor, C: Candidate<
|
||||
}
|
||||
|
||||
private class NoExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: Candidate<D>>(
|
||||
context: TowerContext<D, C>,
|
||||
context: CandidateFactory<D, C>,
|
||||
val collectCandidates: ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver<D>>
|
||||
) : AbstractSimpleScopeTowerProcessor<D, C>(context) {
|
||||
override fun simpleProcess(data: TowerData): Collection<C>
|
||||
@@ -127,7 +127,7 @@ private class NoExplicitReceiverScopeTowerProcessor<D : CallableDescriptor, C: C
|
||||
|
||||
private fun <D : CallableDescriptor, C: Candidate<D>> createSimpleProcessor(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
context: TowerContext<D, C>,
|
||||
context: CandidateFactory<D, C>,
|
||||
explicitReceiver: DetailedReceiver?,
|
||||
classValueReceiver: Boolean,
|
||||
collectCandidates: ScopeTowerLevel.(extensionReceiver: ReceiverValueWithSmartCastInfo?) -> Collection<CandidateWithBoundDispatchReceiver<D>>
|
||||
@@ -155,26 +155,26 @@ private fun <D : CallableDescriptor, C: Candidate<D>> createSimpleProcessor(
|
||||
}
|
||||
|
||||
fun <C : Candidate<VariableDescriptor>> createVariableProcessor(scopeTower: ImplicitScopeTower, name: Name,
|
||||
context: TowerContext<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getVariables(name, it) }
|
||||
|
||||
fun <C : Candidate<VariableDescriptor>> createVariableAndObjectProcessor(scopeTower: ImplicitScopeTower, name: Name,
|
||||
context: TowerContext<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
context: CandidateFactory<VariableDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
) = CompositeScopeTowerProcessor(
|
||||
createVariableProcessor(scopeTower, name, context, explicitReceiver),
|
||||
createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getObjects(name, it) }
|
||||
)
|
||||
|
||||
fun <C : Candidate<FunctionDescriptor>> createSimpleFunctionProcessor(scopeTower: ImplicitScopeTower, name: Name,
|
||||
context: TowerContext<FunctionDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
context: CandidateFactory<FunctionDescriptor, C>, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true
|
||||
) = createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getFunctions(name, it) }
|
||||
|
||||
|
||||
fun <F: Candidate<FunctionDescriptor>, V: Candidate<VariableDescriptor>> createFunctionProcessor(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
name: Name,
|
||||
simpleContext: TowerContext<FunctionDescriptor, F>,
|
||||
invokeContext: InvokeTowerContext<F, V>,
|
||||
simpleContext: CandidateFactory<FunctionDescriptor, F>,
|
||||
factoryProviderForInvoke: CandidateFactoryProviderForInvoke<F, V>,
|
||||
explicitReceiver: DetailedReceiver?
|
||||
): CompositeScopeTowerProcessor<F> {
|
||||
|
||||
@@ -182,11 +182,11 @@ fun <F: Candidate<FunctionDescriptor>, V: Candidate<VariableDescriptor>> createF
|
||||
val simpleFunction = createSimpleFunctionProcessor(scopeTower, name, simpleContext, explicitReceiver)
|
||||
|
||||
// a.foo() -- property a.foo + foo.invoke()
|
||||
val invokeProcessor = InvokeTowerProcessor(scopeTower, name, invokeContext, explicitReceiver)
|
||||
val invokeProcessor = InvokeTowerProcessor(scopeTower, name, factoryProviderForInvoke, explicitReceiver)
|
||||
|
||||
// a.foo() -- property foo is extension function with receiver a -- a.invoke()
|
||||
val invokeExtensionProcessor = createProcessorWithReceiverValueOrEmpty(explicitReceiver) {
|
||||
InvokeExtensionTowerProcessor(scopeTower, name, invokeContext, it)
|
||||
InvokeExtensionTowerProcessor(scopeTower, name, factoryProviderForInvoke, it)
|
||||
}
|
||||
|
||||
return CompositeScopeTowerProcessor(simpleFunction, invokeProcessor, invokeExtensionProcessor)
|
||||
|
||||
@@ -37,7 +37,7 @@ interface Candidate<out D : CallableDescriptor> {
|
||||
val status: ResolutionCandidateStatus
|
||||
}
|
||||
|
||||
interface TowerContext<D : CallableDescriptor, out C: Candidate<D>> {
|
||||
interface CandidateFactory<D : CallableDescriptor, out C: Candidate<D>> {
|
||||
fun createCandidate(
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver<D>,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
@@ -45,15 +45,15 @@ interface TowerContext<D : CallableDescriptor, out C: Candidate<D>> {
|
||||
): C
|
||||
}
|
||||
|
||||
interface InvokeTowerContext<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>> {
|
||||
interface CandidateFactoryProviderForInvoke<F : Candidate<FunctionDescriptor>, V : Candidate<VariableDescriptor>> {
|
||||
|
||||
fun transformCandidate(variable: V, invoke: F): F
|
||||
|
||||
fun contextForVariable(stripExplicitReceiver: Boolean): TowerContext<VariableDescriptor, V>
|
||||
fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<VariableDescriptor, V>
|
||||
|
||||
// foo() -> ReceiverValue(foo), context for invoke
|
||||
// null means that there is no invoke on variable
|
||||
fun contextForInvoke(variable: V, useExplicitReceiver: Boolean): Pair<ReceiverValueWithSmartCastInfo, TowerContext<FunctionDescriptor, F>>?
|
||||
fun factoryForInvoke(variable: V, useExplicitReceiver: Boolean): Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<FunctionDescriptor, F>>?
|
||||
}
|
||||
|
||||
sealed class TowerData {
|
||||
|
||||
Reference in New Issue
Block a user