[NI] Minor. Rename LambdaAnalyzer to KotlinResolutionCallbacks
This commit is contained in:
+3
-3
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.LambdaAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
|
||||
@@ -37,13 +37,13 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
|
||||
|
||||
class LambdaAnalyzerImpl(
|
||||
class KotlinResolutionCallbacksImpl(
|
||||
val expressionTypingServices: ExpressionTypingServices,
|
||||
val trace: BindingTrace,
|
||||
val typeApproximator: TypeApproximator,
|
||||
val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer,
|
||||
val argumentTypeResolver: ArgumentTypeResolver
|
||||
): LambdaAnalyzer {
|
||||
): KotlinResolutionCallbacks {
|
||||
|
||||
override fun analyzeAndGetLambdaResultArguments(
|
||||
topLevelCall: KotlinCall,
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.createLookupLocation
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||
import org.jetbrains.kotlin.resolve.calls.components.ArgumentsToParametersMapper
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.LambdaAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
@@ -128,7 +128,7 @@ class PSICallResolver(
|
||||
}
|
||||
|
||||
private fun createLambdaAnalyzer(context: BasicCallResolutionContext) =
|
||||
LambdaAnalyzerImpl(expressionTypingServices, context.trace, typeApproximator, kotlinToResolvedCallTransformer, argumentTypeResolver)
|
||||
KotlinResolutionCallbacksImpl(expressionTypingServices, context.trace, typeApproximator, kotlinToResolvedCallTransformer, argumentTypeResolver)
|
||||
|
||||
private fun calculateExpectedType(context: BasicCallResolutionContext): UnwrappedType? {
|
||||
val expectedType = context.expectedType.unwrap()
|
||||
@@ -144,8 +144,8 @@ class PSICallResolver(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCallContext(scopeTower: ASTScopeTower, lambdaAnalyzer: LambdaAnalyzer) =
|
||||
KotlinCallContext(scopeTower, lambdaAnalyzer, argumentsToParametersMapper, typeArgumentsToParametersMapper, resultTypeResolver,
|
||||
private fun createCallContext(scopeTower: ASTScopeTower, resolutionCallbacks: KotlinResolutionCallbacks) =
|
||||
KotlinCallContext(scopeTower, resolutionCallbacks, argumentsToParametersMapper, typeArgumentsToParametersMapper, resultTypeResolver,
|
||||
callableReferenceResolver, constraintInjector)
|
||||
|
||||
private fun <D : CallableDescriptor> convertToOverloadResolutionResults(
|
||||
|
||||
@@ -95,14 +95,14 @@ class KotlinCallResolver(
|
||||
isDebuggerContext = callContext.scopeTower.isDebuggerContext)
|
||||
|
||||
val singleResult = maximallySpecificCandidates.singleOrNull()?.let {
|
||||
kotlinCallCompleter.completeCallIfNecessary(it, expectedType, callContext.lambdaAnalyzer)
|
||||
kotlinCallCompleter.completeCallIfNecessary(it, expectedType, callContext.resolutionCallbacks)
|
||||
}
|
||||
if (singleResult != null) {
|
||||
return listOf(singleResult)
|
||||
}
|
||||
|
||||
return maximallySpecificCandidates.map {
|
||||
kotlinCallCompleter.transformWhenAmbiguity(it, callContext.lambdaAnalyzer)
|
||||
kotlinCallCompleter.transformWhenAmbiguity(it, callContext.resolutionCallbacks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -25,7 +25,8 @@ interface IsDescriptorFromSourcePredicate: (CallableDescriptor) -> Boolean
|
||||
|
||||
interface CommonSupertypeCalculator: (Collection<UnwrappedType>) -> UnwrappedType
|
||||
|
||||
interface LambdaAnalyzer {
|
||||
// This components hold state (trace). Work with this carefully.
|
||||
interface KotlinResolutionCallbacks {
|
||||
fun analyzeAndGetLambdaResultArguments(
|
||||
topLevelCall: KotlinCall,
|
||||
lambdaArgument: LambdaKotlinCallArgument,
|
||||
|
||||
+15
-15
@@ -63,15 +63,15 @@ class KotlinCallCompleter(
|
||||
fun getBuilder(): ConstraintSystemBuilder
|
||||
}
|
||||
|
||||
fun transformWhenAmbiguity(candidate: KotlinResolutionCandidate, lambdaAnalyzer: LambdaAnalyzer): ResolvedKotlinCall =
|
||||
toCompletedBaseResolvedCall(candidate.lastCall.constraintSystem.asCallCompleterContext(), candidate, lambdaAnalyzer)
|
||||
fun transformWhenAmbiguity(candidate: KotlinResolutionCandidate, resolutionCallbacks: KotlinResolutionCallbacks): ResolvedKotlinCall =
|
||||
toCompletedBaseResolvedCall(candidate.lastCall.constraintSystem.asCallCompleterContext(), candidate, resolutionCallbacks)
|
||||
|
||||
fun completeCallIfNecessary(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
expectedType: UnwrappedType?,
|
||||
lambdaAnalyzer: LambdaAnalyzer
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
): ResolvedKotlinCall {
|
||||
lambdaAnalyzer.bindStubResolvedCallForCandidate(candidate)
|
||||
resolutionCallbacks.bindStubResolvedCallForCandidate(candidate)
|
||||
val topLevelCall =
|
||||
when (candidate) {
|
||||
is VariableAsFunctionKotlinResolutionCandidate -> candidate.invokeCandidate
|
||||
@@ -81,8 +81,8 @@ class KotlinCallCompleter(
|
||||
if (topLevelCall.prepareForCompletion(expectedType)) {
|
||||
val c = candidate.lastCall.constraintSystem.asCallCompleterContext()
|
||||
|
||||
topLevelCall.competeCall(c, lambdaAnalyzer)
|
||||
return toCompletedBaseResolvedCall(c, candidate, lambdaAnalyzer)
|
||||
topLevelCall.competeCall(c, resolutionCallbacks)
|
||||
return toCompletedBaseResolvedCall(c, candidate, resolutionCallbacks)
|
||||
}
|
||||
|
||||
return ResolvedKotlinCall.OnlyResolvedKotlinCall(candidate)
|
||||
@@ -91,7 +91,7 @@ class KotlinCallCompleter(
|
||||
private fun toCompletedBaseResolvedCall(
|
||||
c: Context,
|
||||
candidate: KotlinResolutionCandidate,
|
||||
lambdaAnalyzer: LambdaAnalyzer
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
): ResolvedKotlinCall.CompletedResolvedKotlinCall {
|
||||
val currentSubstitutor = c.buildResultingSubstitutor()
|
||||
val completedCall = candidate.toCompletedCall(currentSubstitutor)
|
||||
@@ -99,7 +99,7 @@ class KotlinCallCompleter(
|
||||
it.candidate.toCompletedCall(currentSubstitutor)
|
||||
}
|
||||
c.lambdaArguments.forEach {
|
||||
lambdaAnalyzer.completeLambdaReturnType(it, currentSubstitutor.safeSubstitute(it.returnType))
|
||||
resolutionCallbacks.completeLambdaReturnType(it, currentSubstitutor.safeSubstitute(it.returnType))
|
||||
}
|
||||
return ResolvedKotlinCall.CompletedResolvedKotlinCall(completedCall, competedCalls)
|
||||
}
|
||||
@@ -199,19 +199,19 @@ class KotlinCallCompleter(
|
||||
return expectedType != null || csBuilder.isProperType(returnType)
|
||||
}
|
||||
|
||||
private fun SimpleKotlinResolutionCandidate.competeCall(c: Context, lambdaAnalyzer: LambdaAnalyzer) {
|
||||
while (!oneStepToEndOrLambda(c, lambdaAnalyzer)) {
|
||||
private fun SimpleKotlinResolutionCandidate.competeCall(c: Context, resolutionCallbacks: KotlinResolutionCallbacks) {
|
||||
while (!oneStepToEndOrLambda(c, resolutionCallbacks)) {
|
||||
// do nothing -- be happy
|
||||
}
|
||||
}
|
||||
|
||||
// true if it is the end (happy or not)
|
||||
private fun SimpleKotlinResolutionCandidate.oneStepToEndOrLambda(c: Context, lambdaAnalyzer: LambdaAnalyzer): Boolean {
|
||||
private fun SimpleKotlinResolutionCandidate.oneStepToEndOrLambda(c: Context, resolutionCallbacks: KotlinResolutionCallbacks): Boolean {
|
||||
if (c.hasContradiction) return true
|
||||
|
||||
val lambda = c.lambdaArguments.find { canWeAnalyzeIt(c, it) }
|
||||
if (lambda != null) {
|
||||
analyzeLambda(c, lambdaAnalyzer, callContext, kotlinCall, lambda)
|
||||
analyzeLambda(c, resolutionCallbacks, callContext, kotlinCall, lambda)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ class KotlinCallCompleter(
|
||||
if (variable is LambdaTypeVariable) {
|
||||
val resolvedLambda = c.lambdaArguments.find { it.argument == variable.lambdaArgument } ?: return true
|
||||
if (canWeAnalyzeIt(c, resolvedLambda)) {
|
||||
analyzeLambda(c, lambdaAnalyzer, callContext, kotlinCall, resolvedLambda)
|
||||
analyzeLambda(c, resolutionCallbacks, callContext, kotlinCall, resolvedLambda)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ class KotlinCallCompleter(
|
||||
return true
|
||||
}
|
||||
|
||||
private fun analyzeLambda(c: Context, lambdaAnalyzer: LambdaAnalyzer, topLevelCallContext: KotlinCallContext, topLevelCall: KotlinCall, lambda: ResolvedLambdaArgument) {
|
||||
private fun analyzeLambda(c: Context, resolutionCallbacks: KotlinResolutionCallbacks, topLevelCallContext: KotlinCallContext, topLevelCall: KotlinCall, lambda: ResolvedLambdaArgument) {
|
||||
val currentSubstitutor = c.buildCurrentSubstitutor()
|
||||
fun substitute(type: UnwrappedType) = currentSubstitutor.safeSubstitute(type)
|
||||
|
||||
@@ -246,7 +246,7 @@ class KotlinCallCompleter(
|
||||
val parameters = lambda.parameters.map(::substitute)
|
||||
val expectedType = lambda.returnType.takeIf { c.canBeProper(it) }?.let(::substitute)
|
||||
lambda.analyzed = true
|
||||
lambda.resultArguments = lambdaAnalyzer.analyzeAndGetLambdaResultArguments(topLevelCall, lambda.argument, receiver, parameters, expectedType)
|
||||
lambda.resultArguments = resolutionCallbacks.analyzeAndGetLambdaResultArguments(topLevelCall, lambda.argument, receiver, parameters, expectedType)
|
||||
|
||||
for (innerCall in lambda.resultArguments) {
|
||||
// todo strange code -- why top-level kotlinCall? may be it isn't right outer call
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.model
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckArguments
|
||||
import org.jetbrains.kotlin.resolve.calls.components.LambdaAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
class KotlinCallContext(
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val lambdaAnalyzer: LambdaAnalyzer,
|
||||
val resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
val argumentsToParametersMapper: ArgumentsToParametersMapper,
|
||||
val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
|
||||
val resultTypeResolver: ResultTypeResolver,
|
||||
|
||||
Reference in New Issue
Block a user