diff --git a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt index cf6a584460a..0ac7d8320f4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt @@ -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() - useInstance(IsDescriptorFromSourcePredicateImpl) + useImpl() } fun StorageComponentContainer.configureModule( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index 91898d61ce0..78ad50b89a7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -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) - } } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt new file mode 100644 index 00000000000..666d5b6d616 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt @@ -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)) +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index 2a5097562ca..db7d5e5d09d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -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 convertToOverloadResolutionResults( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt index 0ab8eac8825..04a6b853240 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt @@ -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 diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/SpecialComponentImpls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/SpecialComponentImpls.kt deleted file mode 100644 index c73eba9a583..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/SpecialComponentImpls.kt +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt index 5b83f760ec3..46ddefd6e68 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt @@ -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( @@ -44,7 +44,7 @@ class CallableReferenceOverloadConflictResolver( { SimpleConstraintSystemImpl(constraintInjector, typeResolver) }, Companion::createFlatSignature, { null }, - isDescriptorFromSourcePredicate + { externalPredicates.isDescriptorFromSource(it) } ) { companion object { private fun createFlatSignature(candidate: CallableReferenceCandidate) = diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index 50d1c1cebf3..e753b748673 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -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) fun completeCollectionLiteralCalls(collectionLiteralArgument: ResolvedCollectionLiteralArgument) - - fun isHiddenInResolution(descriptor: DeclarationDescriptor, isSuperCall: Boolean = false): Boolean } \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt index 6c34dc17a2f..a0ff7c63712 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt @@ -31,7 +31,7 @@ import java.util.* class NewOverloadingConflictResolver( builtIns: KotlinBuiltIns, specificityComparator: TypeSpecificityComparator, - isDescriptorFromSourcePredicate: IsDescriptorFromSourcePredicate, + externalPredicates: KotlinResolutionExternalPredicates, constraintInjector: ConstraintInjector, typeResolver: ResultTypeResolver ) : OverloadingConflictResolver( @@ -45,7 +45,7 @@ class NewOverloadingConflictResolver( { SimpleConstraintSystemImpl(constraintInjector, typeResolver) }, Companion::createFlatSignature, { (it as? VariableAsFunctionKotlinResolutionCandidate)?.resolvedVariable }, - isDescriptorFromSourcePredicate + { externalPredicates.isDescriptorFromSource(it) } ) { companion object { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index aaef8f0b36e..0c92fd3dda5 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -37,7 +37,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull internal object CheckInstantiationOfAbstractClass : ResolutionPart { override fun SimpleKotlinResolutionCandidate.process(): List { - 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 { - 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 { - if (kotlinCall.isOperatorCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) { + if (callContext.externalPredicates.isOperatorCall(kotlinCall) && + (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) { return listOf(InvokeConventionCallNoOperatorModifier) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt index 83216557d7d..98bf6e2b115 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt @@ -34,10 +34,6 @@ interface KotlinCall { val argumentsInParenthesis: List val externalArgument: KotlinCallArgument? - - val isInfixCall: Boolean - val isOperatorCall: Boolean - val isSuperOrDelegatingConstructorCall: Boolean } private fun SimpleKotlinCallArgument.checkReceiverInvariants() { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt index 03224493483..bbfc3b7e479 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt @@ -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) }