Refactoring: get rid KotlinCallKind inside ResolutionKind
This commit is contained in:
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession;
|
||||
import org.jetbrains.kotlin.resolve.calls.context.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CoroutineInferenceUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallKind;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl;
|
||||
@@ -190,7 +189,7 @@ public class CallResolver {
|
||||
@NotNull BasicCallResolutionContext context,
|
||||
@NotNull Name name,
|
||||
@NotNull KtReferenceExpression referenceExpression,
|
||||
@NotNull NewResolutionOldInference.ResolutionKind<D> kind
|
||||
@NotNull NewResolutionOldInference.ResolutionKind kind
|
||||
) {
|
||||
TracingStrategy tracing = TracingStrategyImpl.create(referenceExpression, context.call);
|
||||
return computeTasksAndResolveCall(context, name, tracing, kind);
|
||||
@@ -201,7 +200,7 @@ public class CallResolver {
|
||||
@NotNull BasicCallResolutionContext context,
|
||||
@NotNull Name name,
|
||||
@NotNull TracingStrategy tracing,
|
||||
@NotNull NewResolutionOldInference.ResolutionKind<D> kind
|
||||
@NotNull NewResolutionOldInference.ResolutionKind kind
|
||||
) {
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<D>>time(() -> {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<>(kind, name, null);
|
||||
@@ -227,7 +226,7 @@ public class CallResolver {
|
||||
) {
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<D>>time(() -> {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<>(), null, candidates
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates(), null, candidates
|
||||
);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
});
|
||||
@@ -553,7 +552,7 @@ public class CallResolver {
|
||||
Set<ResolutionCandidate<FunctionDescriptor>> candidates = Collections.singleton(candidate);
|
||||
|
||||
ResolutionTask<FunctionDescriptor> resolutionTask = new ResolutionTask<>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<>(), null, candidates
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates(), null, candidates
|
||||
);
|
||||
|
||||
return doResolveCallOrGetCachedResults(basicCallResolutionContext, resolutionTask, tracing);
|
||||
@@ -569,12 +568,13 @@ public class CallResolver {
|
||||
tracing.bindCall(context.trace, call);
|
||||
|
||||
boolean newInferenceEnabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference);
|
||||
if (newInferenceEnabled && (resolutionTask.resolutionKind.getKotlinCallKind() != KotlinCallKind.UNSUPPORTED)) {
|
||||
NewResolutionOldInference.ResolutionKind resolutionKind = resolutionTask.resolutionKind;
|
||||
if (newInferenceEnabled && PSICallResolver.getDefaultResolutionKinds().contains(resolutionKind)) {
|
||||
assert resolutionTask.name != null;
|
||||
return PSICallResolver.runResolutionAndInference(context, resolutionTask.name, resolutionTask.resolutionKind, tracing);
|
||||
return PSICallResolver.runResolutionAndInference(context, resolutionTask.name, resolutionKind, tracing);
|
||||
}
|
||||
|
||||
if (newInferenceEnabled && resolutionTask.resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates) {
|
||||
if (newInferenceEnabled && resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates) {
|
||||
assert resolutionTask.givenCandidates != null;
|
||||
return PSICallResolver.runResolutionAndInferenceForGivenCandidates(context, resolutionTask.givenCandidates, tracing);
|
||||
}
|
||||
@@ -693,10 +693,10 @@ public class CallResolver {
|
||||
final Collection<ResolutionCandidate<D>> givenCandidates;
|
||||
|
||||
@NotNull
|
||||
final NewResolutionOldInference.ResolutionKind<D> resolutionKind;
|
||||
final NewResolutionOldInference.ResolutionKind resolutionKind;
|
||||
|
||||
private ResolutionTask(
|
||||
@NotNull NewResolutionOldInference.ResolutionKind<D> kind,
|
||||
@NotNull NewResolutionOldInference.ResolutionKind kind,
|
||||
@Nullable Name name,
|
||||
@Nullable Collection<ResolutionCandidate<D>> candidates
|
||||
) {
|
||||
|
||||
+8
-8
@@ -70,7 +70,7 @@ class NewResolutionOldInference(
|
||||
private val coroutineInferenceSupport: CoroutineInferenceSupport,
|
||||
private val deprecationResolver: DeprecationResolver
|
||||
) {
|
||||
sealed class ResolutionKind<D : CallableDescriptor>(val kotlinCallKind: KotlinCallKind = KotlinCallKind.UNSUPPORTED) {
|
||||
sealed class ResolutionKind {
|
||||
abstract internal fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference,
|
||||
name: Name,
|
||||
@@ -80,7 +80,7 @@ class NewResolutionOldInference(
|
||||
context: BasicCallResolutionContext
|
||||
): ScopeTowerProcessor<MyCandidate>
|
||||
|
||||
object Function : ResolutionKind<FunctionDescriptor>(KotlinCallKind.FUNCTION) {
|
||||
object Function : ResolutionKind() {
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
@@ -96,7 +96,7 @@ class NewResolutionOldInference(
|
||||
}
|
||||
}
|
||||
|
||||
object Variable : ResolutionKind<VariableDescriptor>(KotlinCallKind.VARIABLE) {
|
||||
object Variable : ResolutionKind() {
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
@@ -106,7 +106,7 @@ class NewResolutionOldInference(
|
||||
}
|
||||
}
|
||||
|
||||
object CallableReference : ResolutionKind<CallableDescriptor>() {
|
||||
object CallableReference : ResolutionKind() {
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
@@ -120,7 +120,7 @@ class NewResolutionOldInference(
|
||||
}
|
||||
}
|
||||
|
||||
object Invoke : ResolutionKind<FunctionDescriptor>() {
|
||||
object Invoke : ResolutionKind() {
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
@@ -142,7 +142,7 @@ class NewResolutionOldInference(
|
||||
|
||||
}
|
||||
|
||||
class GivenCandidates<D : CallableDescriptor> : ResolutionKind<D>() {
|
||||
class GivenCandidates : ResolutionKind() {
|
||||
override fun createTowerProcessor(
|
||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower, explicitReceiver: DetailedReceiver?, context: BasicCallResolutionContext
|
||||
@@ -155,7 +155,7 @@ class NewResolutionOldInference(
|
||||
fun <D : CallableDescriptor> runResolution(
|
||||
context: BasicCallResolutionContext,
|
||||
name: Name,
|
||||
kind: ResolutionKind<D>,
|
||||
kind: ResolutionKind,
|
||||
tracing: TracingStrategy
|
||||
): OverloadResolutionResultsImpl<D> {
|
||||
val explicitReceiver = context.call.explicitReceiver
|
||||
@@ -349,7 +349,7 @@ class NewResolutionOldInference(
|
||||
private fun reportAdditionalDiagnosticIfNoCandidates(
|
||||
context: BasicCallResolutionContext,
|
||||
name: Name,
|
||||
kind: ResolutionKind<*>,
|
||||
kind: ResolutionKind,
|
||||
scopeTower: ImplicitScopeTower,
|
||||
detailedReceiver: DetailedReceiver?
|
||||
): Boolean {
|
||||
|
||||
@@ -64,16 +64,21 @@ class PSICallResolver(
|
||||
) {
|
||||
private val GIVEN_CANDIDATES_NAME = Name.special("<given candidates>")
|
||||
|
||||
val defaultResolutionKinds = setOf(
|
||||
NewResolutionOldInference.ResolutionKind.Function,
|
||||
NewResolutionOldInference.ResolutionKind.Variable
|
||||
)
|
||||
|
||||
fun <D : CallableDescriptor> runResolutionAndInference(
|
||||
context: BasicCallResolutionContext,
|
||||
name: Name,
|
||||
resolutionKind: NewResolutionOldInference.ResolutionKind<D>,
|
||||
resolutionKind: NewResolutionOldInference.ResolutionKind,
|
||||
tracingStrategy: TracingStrategy
|
||||
): OverloadResolutionResults<D> {
|
||||
val isBinaryRemOperator = isBinaryRemOperator(context.call)
|
||||
val refinedName = refineNameForRemOperator(isBinaryRemOperator, name)
|
||||
|
||||
val kotlinCall = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, refinedName, tracingStrategy)
|
||||
val kotlinCall = toKotlinCall(context, resolutionKind.toKotlinCallKind(), context.call, refinedName, tracingStrategy)
|
||||
val scopeTower = ASTScopeTower(context)
|
||||
val resolutionCallbacks = createResolutionCallbacks(context)
|
||||
|
||||
@@ -89,7 +94,7 @@ class PSICallResolver(
|
||||
result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, scopeTower, resolutionCallbacks, expectedType)
|
||||
}
|
||||
|
||||
if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, resolutionKind.kotlinCallKind, kotlinCall)) {
|
||||
if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, resolutionKind, kotlinCall)) {
|
||||
return OverloadResolutionResultsImpl.nameNotFound()
|
||||
}
|
||||
|
||||
@@ -124,17 +129,17 @@ class PSICallResolver(
|
||||
|
||||
}
|
||||
|
||||
private fun <D : CallableDescriptor> resolveToDeprecatedMod(
|
||||
private fun resolveToDeprecatedMod(
|
||||
remOperatorName: Name,
|
||||
context: BasicCallResolutionContext,
|
||||
resolutionKind: NewResolutionOldInference.ResolutionKind<D>,
|
||||
resolutionKind: NewResolutionOldInference.ResolutionKind,
|
||||
tracingStrategy: TracingStrategy,
|
||||
scopeTower: ImplicitScopeTower,
|
||||
resolutionCallbacks: KotlinResolutionCallbacksImpl,
|
||||
expectedType: UnwrappedType?
|
||||
): CallResolutionResult {
|
||||
val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[remOperatorName]!!
|
||||
val callWithDeprecatedName = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, deprecatedName, tracingStrategy)
|
||||
val callWithDeprecatedName = toKotlinCall(context, resolutionKind.toKotlinCallKind(), context.call, deprecatedName, tracingStrategy)
|
||||
val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, scopeTower, callWithDeprecatedName)
|
||||
return kotlinCallResolver.resolveCall(
|
||||
scopeTower, resolutionCallbacks, callWithDeprecatedName, expectedType,
|
||||
@@ -298,7 +303,7 @@ class PSICallResolver(
|
||||
private fun reportAdditionalDiagnosticIfNoCandidates(
|
||||
context: BasicCallResolutionContext,
|
||||
scopeTower: ImplicitScopeTower,
|
||||
kind: KotlinCallKind,
|
||||
kind: NewResolutionOldInference.ResolutionKind,
|
||||
kotlinCall: KotlinCall
|
||||
): Boolean {
|
||||
val reference = context.call.calleeExpression as? KtReferenceExpression ?: return false
|
||||
@@ -446,6 +451,15 @@ class PSICallResolver(
|
||||
}
|
||||
}
|
||||
|
||||
private fun NewResolutionOldInference.ResolutionKind.toKotlinCallKind(): KotlinCallKind {
|
||||
return when (this) {
|
||||
is NewResolutionOldInference.ResolutionKind.Function -> KotlinCallKind.FUNCTION
|
||||
is NewResolutionOldInference.ResolutionKind.Variable -> KotlinCallKind.VARIABLE
|
||||
is NewResolutionOldInference.ResolutionKind.Invoke -> KotlinCallKind.UNSUPPORTED
|
||||
is NewResolutionOldInference.ResolutionKind.CallableReference -> KotlinCallKind.UNSUPPORTED
|
||||
is NewResolutionOldInference.ResolutionKind.GivenCandidates -> KotlinCallKind.UNSUPPORTED
|
||||
}
|
||||
}
|
||||
|
||||
private fun toKotlinCall(
|
||||
context: BasicCallResolutionContext,
|
||||
@@ -496,8 +510,8 @@ class PSICallResolver(
|
||||
astExternalArgument?.setResultDataFlowInfoIfRelevant(resultDataFlowInfo)
|
||||
|
||||
return PSIKotlinCallImpl(
|
||||
kotlinCallKind, oldCall, tracingStrategy, resolvedExplicitReceiver, name, resolvedTypeArguments, resolvedArgumentsInParenthesis,
|
||||
astExternalArgument, context.dataFlowInfo, resultDataFlowInfo, context.dataFlowInfoForArguments
|
||||
kotlinCallKind, oldCall, tracingStrategy, resolvedExplicitReceiver, name, resolvedTypeArguments,
|
||||
resolvedArgumentsInParenthesis, astExternalArgument, context.dataFlowInfo, resultDataFlowInfo, context.dataFlowInfoForArguments
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user