[NI] Refactoring: KotlinCallContext to stateless component (1)
This commit is contained in:
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionExternalPredicatesImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionStatelessCallbacksImpl
|
||||
import org.jetbrains.kotlin.resolve.lazy.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||
@@ -61,7 +61,7 @@ fun StorageComponentContainer.configureModule(
|
||||
|
||||
private fun StorageComponentContainer.configurePlatformIndependentComponents() {
|
||||
useImpl<SupertypeLoopCheckerImpl>()
|
||||
useImpl<KotlinResolutionExternalPredicatesImpl>()
|
||||
useImpl<KotlinResolutionStatelessCallbacksImpl>()
|
||||
}
|
||||
|
||||
fun StorageComponentContainer.configureModule(
|
||||
|
||||
+3
-3
@@ -24,14 +24,14 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isConventionCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isSuperOrDelegatingConstructorCall
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionExternalPredicates
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionStatelessCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.isHiddenInResolution
|
||||
|
||||
class KotlinResolutionExternalPredicatesImpl(
|
||||
class KotlinResolutionStatelessCallbacksImpl(
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
) : KotlinResolutionExternalPredicates {
|
||||
) : KotlinResolutionStatelessCallbacks {
|
||||
override fun isDescriptorFromSource(descriptor: CallableDescriptor) =
|
||||
DescriptorToSourceUtils.descriptorToDeclaration(descriptor) != null
|
||||
|
||||
@@ -71,7 +71,7 @@ class PSICallResolver(
|
||||
private val dynamicCallableDescriptors: DynamicCallableDescriptors,
|
||||
private val syntheticScopes: SyntheticScopes,
|
||||
private val argumentsToParametersMapper: ArgumentsToParametersMapper,
|
||||
private val externalPredicates: KotlinResolutionExternalPredicates,
|
||||
private val statelessCallbacks: KotlinResolutionStatelessCallbacks,
|
||||
private val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
|
||||
private val resultTypeResolver: ResultTypeResolver,
|
||||
private val callableReferenceResolver: CallableReferenceResolver,
|
||||
@@ -98,14 +98,14 @@ class PSICallResolver(
|
||||
val lambdaAnalyzer = createLambdaAnalyzer(context)
|
||||
|
||||
val callContext = createCallContext(scopeTower, lambdaAnalyzer)
|
||||
val factoryProviderForInvoke = FactoryProviderForInvoke(context, callContext, kotlinCall)
|
||||
val factoryProviderForInvoke = FactoryProviderForInvoke(context, callContext, scopeTower, kotlinCall)
|
||||
|
||||
val expectedType = calculateExpectedType(context)
|
||||
var result = kotlinCallResolver.resolveCall(callContext, kotlinCall, expectedType, factoryProviderForInvoke)
|
||||
|
||||
val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)
|
||||
if (isBinaryRemOperator && shouldUseOperatorRem && (result.isEmpty() || result.areAllCompletedAndInapplicable())) {
|
||||
result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, callContext, expectedType)
|
||||
result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, callContext, scopeTower, expectedType)
|
||||
}
|
||||
|
||||
if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, resolutionKind.kotlinCallKind, kotlinCall)) {
|
||||
@@ -129,7 +129,7 @@ class PSICallResolver(
|
||||
val callContext = createCallContext(scopeTower, lambdaAnalyzer)
|
||||
|
||||
val givenCandidates = resolutionCandidates.map {
|
||||
GivenCandidate(it.descriptor as FunctionDescriptor,
|
||||
GivenCandidate(scopeTower, it.descriptor as FunctionDescriptor,
|
||||
it.dispatchReceiver?.let { context.transformToReceiverWithSmartCastInfo(it) },
|
||||
it.knownTypeParametersResultingSubstitutor)
|
||||
}
|
||||
@@ -143,12 +143,14 @@ class PSICallResolver(
|
||||
remOperatorName: Name,
|
||||
context: BasicCallResolutionContext,
|
||||
resolutionKind: NewResolutionOldInference.ResolutionKind<D>,
|
||||
tracingStrategy: TracingStrategy, callContext: KotlinCallContext,
|
||||
tracingStrategy: TracingStrategy,
|
||||
callContext: KotlinCallContext,
|
||||
scopeTower: ImplicitScopeTower,
|
||||
expectedType: UnwrappedType?
|
||||
): Collection<ResolvedKotlinCall> {
|
||||
val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[remOperatorName]!!
|
||||
val callWithDeprecatedName = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, deprecatedName, tracingStrategy)
|
||||
val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, callContext, callWithDeprecatedName)
|
||||
val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, callContext, scopeTower, callWithDeprecatedName)
|
||||
return kotlinCallResolver.resolveCall(callContext, callWithDeprecatedName, expectedType, refinedProviderForInvokeFactory)
|
||||
}
|
||||
|
||||
@@ -176,7 +178,7 @@ class PSICallResolver(
|
||||
}
|
||||
|
||||
private fun createCallContext(scopeTower: ASTScopeTower, resolutionCallbacks: KotlinResolutionCallbacks) =
|
||||
KotlinCallContext(scopeTower, resolutionCallbacks, externalPredicates, argumentsToParametersMapper,
|
||||
KotlinCallContext(scopeTower, resolutionCallbacks, statelessCallbacks, argumentsToParametersMapper,
|
||||
typeArgumentsToParametersMapper, resultTypeResolver,
|
||||
callableReferenceResolver, constraintInjector, reflectionTypes)
|
||||
|
||||
@@ -290,6 +292,7 @@ class PSICallResolver(
|
||||
private inner class FactoryProviderForInvoke(
|
||||
val context: BasicCallResolutionContext,
|
||||
val callContext: KotlinCallContext,
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val kotlinCall: PSIKotlinCallImpl
|
||||
) : CandidateFactoryProviderForInvoke<KotlinResolutionCandidate> {
|
||||
|
||||
@@ -314,7 +317,7 @@ class PSICallResolver(
|
||||
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<SimpleKotlinResolutionCandidate> {
|
||||
val explicitReceiver = if (stripExplicitReceiver) null else kotlinCall.explicitReceiver
|
||||
val variableCall = PSIKotlinCallForVariable(kotlinCall, explicitReceiver, kotlinCall.name)
|
||||
return SimpleCandidateFactory(callContext, variableCall)
|
||||
return SimpleCandidateFactory(callContext, scopeTower, variableCall)
|
||||
}
|
||||
|
||||
override fun factoryForInvoke(variable: KotlinResolutionCandidate, useExplicitReceiver: Boolean):
|
||||
@@ -338,7 +341,7 @@ class PSICallResolver(
|
||||
PSIKotlinCallForInvoke(kotlinCall, variableCallArgument, null)
|
||||
}
|
||||
|
||||
return variableCallArgument.receiver to SimpleCandidateFactory(callContext, callForInvoke)
|
||||
return variableCallArgument.receiver to SimpleCandidateFactory(callContext, scopeTower, callForInvoke)
|
||||
}
|
||||
|
||||
// todo: create special check that there is no invoke on variable
|
||||
|
||||
Reference in New Issue
Block a user