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