[NI] Refactoring. Move properties from KotlinCall to external component

This commit is contained in:
Stanislav Erokhin
2017-06-23 08:47:41 +03:00
committed by Mikhail Zarechenskiy
parent ef93088a42
commit 93d80c252f
12 changed files with 79 additions and 75 deletions
@@ -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.IsDescriptorFromSourcePredicateImpl
import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionExternalPredicatesImpl
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>()
useInstance(IsDescriptorFromSourcePredicateImpl)
useImpl<KotlinResolutionExternalPredicatesImpl>()
}
fun StorageComponentContainer.configureModule(
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.builtins.createFunctionType
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
@@ -41,7 +40,6 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategyImpl
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.isHiddenInResolution
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
@@ -221,8 +219,4 @@ class KotlinResolutionCallbacksImpl(
expressionTypingServices.getTypeInfo(psiCallArgument.collectionLiteralExpression, actualContext)
}
override fun isHiddenInResolution(descriptor: DeclarationDescriptor, isSuperCall: Boolean): Boolean {
return descriptor.isHiddenInResolution(languageVersionSettings, isSuperCall)
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
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.model.KotlinCall
import org.jetbrains.kotlin.resolve.isHiddenInResolution
class KotlinResolutionExternalPredicatesImpl(
private val languageVersionSettings: LanguageVersionSettings
) : KotlinResolutionExternalPredicates {
override fun isDescriptorFromSource(descriptor: CallableDescriptor) =
DescriptorToSourceUtils.descriptorToDeclaration(descriptor) != null
override fun isInfixCall(kotlinCall: KotlinCall) =
kotlinCall is PSIKotlinCallImpl && isInfixCall(kotlinCall.psiCall)
override fun isOperatorCall(kotlinCall: KotlinCall) =
(kotlinCall is PSIKotlinCallForInvoke) ||
(kotlinCall is PSIKotlinCallImpl && isConventionCall(kotlinCall.psiCall))
override fun isSuperOrDelegatingConstructorCall(kotlinCall: KotlinCall) =
kotlinCall is PSIKotlinCallImpl && isSuperOrDelegatingConstructorCall(kotlinCall.psiCall)
override fun isHiddenInResolution(descriptor: DeclarationDescriptor, kotlinCall: KotlinCall) =
descriptor.isHiddenInResolution(languageVersionSettings, isSuperOrDelegatingConstructorCall(kotlinCall))
}
@@ -39,10 +39,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.createLookupLocation
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
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.KotlinResolutionCallbacks
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper
import org.jetbrains.kotlin.resolve.calls.components.*
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
@@ -75,11 +72,12 @@ class PSICallResolver(
private val dynamicCallableDescriptors: DynamicCallableDescriptors,
private val syntheticScopes: SyntheticScopes,
private val argumentsToParametersMapper: ArgumentsToParametersMapper,
val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
val resultTypeResolver: ResultTypeResolver,
val callableReferenceResolver: CallableReferenceResolver,
val constraintInjector: ConstraintInjector,
val reflectionTypes: ReflectionTypes,
private val externalPredicates: KotlinResolutionExternalPredicates,
private val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
private val resultTypeResolver: ResultTypeResolver,
private val callableReferenceResolver: CallableReferenceResolver,
private val constraintInjector: ConstraintInjector,
private val reflectionTypes: ReflectionTypes,
private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer,
private val kotlinCallResolver: KotlinCallResolver,
private val typeApproximator: TypeApproximator,
@@ -179,7 +177,8 @@ class PSICallResolver(
}
private fun createCallContext(scopeTower: ASTScopeTower, resolutionCallbacks: KotlinResolutionCallbacks) =
KotlinCallContext(scopeTower, resolutionCallbacks, argumentsToParametersMapper, typeArgumentsToParametersMapper, resultTypeResolver,
KotlinCallContext(scopeTower, resolutionCallbacks, externalPredicates, argumentsToParametersMapper,
typeArgumentsToParametersMapper, resultTypeResolver,
callableReferenceResolver, constraintInjector, reflectionTypes)
private fun <D : CallableDescriptor> convertToOverloadResolutionResults(
@@ -18,11 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallKind
import org.jetbrains.kotlin.resolve.calls.CallTransformer
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.model.*
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
@@ -57,11 +53,7 @@ class PSIKotlinCallImpl(
override val externalArgument: KotlinCallArgument?,
override val startingDataFlowInfo: DataFlowInfo,
override val resultDataFlowInfo: DataFlowInfo
) : PSIKotlinCall() {
override val isInfixCall: Boolean get() = isInfixCall(psiCall)
override val isOperatorCall: Boolean get() = isConventionCall(psiCall)
override val isSuperOrDelegatingConstructorCall: Boolean get() = isSuperOrDelegatingConstructorCall(psiCall)
}
) : PSIKotlinCall()
class PSIKotlinCallForVariable(
val baseCall: PSIKotlinCallImpl,
@@ -80,10 +72,6 @@ class PSIKotlinCallForVariable(
override val psiCall: Call = CallTransformer.stripCallArguments(baseCall.psiCall).let {
if (explicitReceiver == null) CallTransformer.stripReceiver(it) else it
}
override val isInfixCall: Boolean get() = false
override val isOperatorCall: Boolean get() = false
override val isSuperOrDelegatingConstructorCall: Boolean get() = false
}
class PSIKotlinCallForInvoke(
@@ -102,10 +90,6 @@ class PSIKotlinCallForInvoke(
override val psiCall: Call
override val tracingStrategy: TracingStrategy
override val isInfixCall: Boolean get() = false
override val isOperatorCall: Boolean get() = true
override val isSuperOrDelegatingConstructorCall: Boolean get() = false
init {
val variableReceiver = dispatchReceiverForInvokeExtension ?: explicitReceiver
val explicitExtensionReceiver = if (dispatchReceiverForInvokeExtension == null) null else explicitReceiver
@@ -1,25 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.calls.components.IsDescriptorFromSourcePredicate
object IsDescriptorFromSourcePredicateImpl: IsDescriptorFromSourcePredicate {
override fun invoke(p1: CallableDescriptor) = DescriptorToSourceUtils.descriptorToDeclaration(p1) != null
}
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.UnwrappedType
class CallableReferenceOverloadConflictResolver(
builtIns: KotlinBuiltIns,
specificityComparator: TypeSpecificityComparator,
isDescriptorFromSourcePredicate: IsDescriptorFromSourcePredicate,
externalPredicates: KotlinResolutionExternalPredicates,
constraintInjector: ConstraintInjector,
typeResolver: ResultTypeResolver
) : OverloadingConflictResolver<CallableReferenceCandidate>(
@@ -44,7 +44,7 @@ class CallableReferenceOverloadConflictResolver(
{ SimpleConstraintSystemImpl(constraintInjector, typeResolver) },
Companion::createFlatSignature,
{ null },
isDescriptorFromSourcePredicate
{ externalPredicates.isDescriptorFromSource(it) }
) {
companion object {
private fun createFlatSignature(candidate: CallableReferenceCandidate) =
@@ -21,7 +21,14 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.types.UnwrappedType
interface IsDescriptorFromSourcePredicate: (CallableDescriptor) -> Boolean
// stateless component
interface KotlinResolutionExternalPredicates {
fun isDescriptorFromSource(descriptor: CallableDescriptor): Boolean
fun isInfixCall(kotlinCall: KotlinCall): Boolean
fun isOperatorCall(kotlinCall: KotlinCall): Boolean
fun isSuperOrDelegatingConstructorCall(kotlinCall: KotlinCall): Boolean
fun isHiddenInResolution(descriptor: DeclarationDescriptor, kotlinCall: KotlinCall): Boolean
}
// This components hold state (trace). Work with this carefully.
interface KotlinResolutionCallbacks {
@@ -41,6 +48,4 @@ interface KotlinResolutionCallbacks {
resultTypeParameters: List<UnwrappedType>)
fun completeCollectionLiteralCalls(collectionLiteralArgument: ResolvedCollectionLiteralArgument)
fun isHiddenInResolution(descriptor: DeclarationDescriptor, isSuperCall: Boolean = false): Boolean
}
@@ -31,7 +31,7 @@ import java.util.*
class NewOverloadingConflictResolver(
builtIns: KotlinBuiltIns,
specificityComparator: TypeSpecificityComparator,
isDescriptorFromSourcePredicate: IsDescriptorFromSourcePredicate,
externalPredicates: KotlinResolutionExternalPredicates,
constraintInjector: ConstraintInjector,
typeResolver: ResultTypeResolver
) : OverloadingConflictResolver<KotlinResolutionCandidate>(
@@ -45,7 +45,7 @@ class NewOverloadingConflictResolver(
{ SimpleConstraintSystemImpl(constraintInjector, typeResolver) },
Companion::createFlatSignature,
{ (it as? VariableAsFunctionKotlinResolutionCandidate)?.resolvedVariable },
isDescriptorFromSourcePredicate
{ externalPredicates.isDescriptorFromSource(it) }
) {
companion object {
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
internal object CheckInstantiationOfAbstractClass : ResolutionPart {
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
if (candidateDescriptor is ConstructorDescriptor && !kotlinCall.isSuperOrDelegatingConstructorCall) {
if (candidateDescriptor is ConstructorDescriptor && !callContext.externalPredicates.isSuperOrDelegatingConstructorCall(kotlinCall)) {
if (candidateDescriptor.constructedClass.modality == Modality.ABSTRACT) {
return listOf(InstantiationOfAbstractClass)
}
@@ -251,7 +251,8 @@ internal object CheckArguments : ResolutionPart {
internal object CheckInfixResolutionPart : ResolutionPart {
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
if (kotlinCall.isInfixCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) {
if (callContext.externalPredicates.isInfixCall(kotlinCall) &&
(candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) {
return listOf(InfixCallNoInfixModifier)
}
@@ -261,7 +262,8 @@ internal object CheckInfixResolutionPart : ResolutionPart {
internal object CheckOperatorResolutionPart : ResolutionPart {
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
if (kotlinCall.isOperatorCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) {
if (callContext.externalPredicates.isOperatorCall(kotlinCall) &&
(candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) {
return listOf(InvokeConventionCallNoOperatorModifier)
}
@@ -34,10 +34,6 @@ interface KotlinCall {
val argumentsInParenthesis: List<KotlinCallArgument>
val externalArgument: KotlinCallArgument?
val isInfixCall: Boolean
val isOperatorCall: Boolean
val isSuperOrDelegatingConstructorCall: Boolean
}
private fun SimpleKotlinCallArgument.checkReceiverInvariants() {
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
class KotlinCallContext(
val scopeTower: ImplicitScopeTower,
val resolutionCallbacks: KotlinResolutionCallbacks,
val externalPredicates: KotlinResolutionExternalPredicates,
val argumentsToParametersMapper: ArgumentsToParametersMapper,
val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper,
val resultTypeResolver: ResultTypeResolver,
@@ -77,7 +78,7 @@ class SimpleCandidateFactory(val callContext: KotlinCallContext, val kotlinCall:
}
val candidateDiagnostics = towerCandidate.diagnostics.toMutableList()
if (callContext.resolutionCallbacks.isHiddenInResolution(towerCandidate.descriptor, kotlinCall.isSuperOrDelegatingConstructorCall)) {
if (callContext.externalPredicates.isHiddenInResolution(towerCandidate.descriptor, kotlinCall)) {
candidateDiagnostics.add(HiddenDescriptor)
}