Refactoring: create separate util function for create constructors resolution candidates
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -483,8 +483,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private
|
private static Pair<Collection<ResolutionCandidate<CallableDescriptor>>, BasicCallResolutionContext> prepareCandidatesAndContextForConstructorCall(
|
||||||
Pair<Collection<ResolutionCandidate<CallableDescriptor>>, BasicCallResolutionContext> prepareCandidatesAndContextForConstructorCall(
|
|
||||||
@NotNull KotlinType superType,
|
@NotNull KotlinType superType,
|
||||||
@NotNull BasicCallResolutionContext context
|
@NotNull BasicCallResolutionContext context
|
||||||
) {
|
) {
|
||||||
@@ -506,8 +505,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Collection<ResolutionCandidate<CallableDescriptor>> candidates =
|
Collection<ResolutionCandidate<CallableDescriptor>> candidates =
|
||||||
taskPrioritizer.<CallableDescriptor>convertWithImpliedThisAndNoReceiver(
|
CallResolverUtilKt.createResolutionCandidatesForConstructors(context.scope, context.call, superClass, knownTypeParametersSubstitutor);
|
||||||
context.scope, superClass.getConstructors(), context.call, knownTypeParametersSubstitutor);
|
|
||||||
|
|
||||||
return new Pair<Collection<ResolutionCandidate<CallableDescriptor>>, BasicCallResolutionContext>(candidates, context);
|
return new Pair<Collection<ResolutionCandidate<CallableDescriptor>>, BasicCallResolutionContext>(candidates, context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,20 +19,23 @@ package org.jetbrains.kotlin.resolve.calls.callResolverUtil
|
|||||||
import com.google.common.collect.Lists
|
import com.google.common.collect.Lists
|
||||||
import com.intellij.util.containers.ContainerUtil
|
import com.intellij.util.containers.ContainerUtil
|
||||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.EXPECTED_TYPE_POSITION
|
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.EXPECTED_TYPE_POSITION
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.getNestedTypeVariables
|
import org.jetbrains.kotlin.resolve.calls.inference.getNestedTypeVariables
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||||
import org.jetbrains.kotlin.resolve.validation.InfixValidator
|
import org.jetbrains.kotlin.resolve.validation.InfixValidator
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
||||||
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
enum class ResolveArgumentsMode {
|
enum class ResolveArgumentsMode {
|
||||||
@@ -163,3 +166,35 @@ fun getEffectiveExpectedType(parameterDescriptor: ValueParameterDescriptor, argu
|
|||||||
|
|
||||||
return parameterDescriptor.type
|
return parameterDescriptor.type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createResolutionCandidatesForConstructors(
|
||||||
|
lexicalScope: LexicalScope,
|
||||||
|
call: Call,
|
||||||
|
classWithConstructors: ClassDescriptor,
|
||||||
|
knownSubstitutor: TypeSubstitutor? = null
|
||||||
|
): Collection<ResolutionCandidate<CallableDescriptor>> {
|
||||||
|
val constructors = classWithConstructors.constructors
|
||||||
|
|
||||||
|
if (constructors.isEmpty()) return emptyList()
|
||||||
|
|
||||||
|
val receiverKind: ExplicitReceiverKind
|
||||||
|
val dispatchReceiver: ReceiverValue?
|
||||||
|
|
||||||
|
if (classWithConstructors.isInner) {
|
||||||
|
val outerClassType = (classWithConstructors.containingDeclaration as? ClassDescriptor)?.defaultType ?: return emptyList()
|
||||||
|
val substitutedOuterClassType = knownSubstitutor?.let { it.substitute(outerClassType, Variance.INVARIANT) } ?: outerClassType
|
||||||
|
|
||||||
|
val receiver = lexicalScope.getImplicitReceiversHierarchy().firstOrNull {
|
||||||
|
KotlinTypeChecker.DEFAULT.isSubtypeOf(it.type, substitutedOuterClassType)
|
||||||
|
} ?: return emptyList()
|
||||||
|
|
||||||
|
receiverKind = ExplicitReceiverKind.DISPATCH_RECEIVER
|
||||||
|
dispatchReceiver = receiver.value
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
receiverKind = ExplicitReceiverKind.NO_EXPLICIT_RECEIVER
|
||||||
|
dispatchReceiver = null
|
||||||
|
}
|
||||||
|
|
||||||
|
return constructors.map { ResolutionCandidate.create<CallableDescriptor>(call, it, dispatchReceiver, null, receiverKind, knownSubstitutor) }
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -425,7 +425,7 @@ class TaskPrioritizer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <D : CallableDescriptor> convertWithImpliedThisAndNoReceiver(
|
private fun <D : CallableDescriptor> convertWithImpliedThisAndNoReceiver(
|
||||||
scope: LexicalScope,
|
scope: LexicalScope,
|
||||||
descriptors: Collection<D>,
|
descriptors: Collection<D>,
|
||||||
call: Call,
|
call: Call,
|
||||||
@@ -434,7 +434,7 @@ class TaskPrioritizer(
|
|||||||
return convertWithImpliedThis(scope, null, descriptors, NO_EXPLICIT_RECEIVER, call, knownSubstitutor)
|
return convertWithImpliedThis(scope, null, descriptors, NO_EXPLICIT_RECEIVER, call, knownSubstitutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <D : CallableDescriptor> convertWithImpliedThis(
|
private fun <D : CallableDescriptor> convertWithImpliedThis(
|
||||||
scope: LexicalScope,
|
scope: LexicalScope,
|
||||||
receiverValue: ReceiverValue?,
|
receiverValue: ReceiverValue?,
|
||||||
descriptors: Collection<D>,
|
descriptors: Collection<D>,
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ Resolved call:
|
|||||||
|
|
||||||
Resulting descriptor: constructor B(arg: String) defined in A.B
|
Resulting descriptor: constructor B(arg: String) defined in A.B
|
||||||
|
|
||||||
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
Explicit receiver kind = DISPATCH_RECEIVER
|
||||||
Dispatch receiver = Class{A}
|
Dispatch receiver = Class{A}
|
||||||
Extension receiver = NO_RECEIVER
|
Extension receiver = NO_RECEIVER
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ Resolved call:
|
|||||||
|
|
||||||
Resulting descriptor: constructor B(x: String) defined in A.B
|
Resulting descriptor: constructor B(x: String) defined in A.B
|
||||||
|
|
||||||
Explicit receiver kind = NO_EXPLICIT_RECEIVER
|
Explicit receiver kind = DISPATCH_RECEIVER
|
||||||
Dispatch receiver = Class{A}
|
Dispatch receiver = Class{A}
|
||||||
Extension receiver = NO_RECEIVER
|
Extension receiver = NO_RECEIVER
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user