Frontend plugins to upstream
Change-Id: Id9203c92d0a711e4f21565bd225a465bd41db476
This commit is contained in:
@@ -585,6 +585,8 @@ class KotlinCoreEnvironment private constructor(
|
|||||||
IrGenerationExtension.registerExtensionPoint(project)
|
IrGenerationExtension.registerExtensionPoint(project)
|
||||||
ScriptEvaluationExtension.registerExtensionPoint(project)
|
ScriptEvaluationExtension.registerExtensionPoint(project)
|
||||||
ShellExtension.registerExtensionPoint(project)
|
ShellExtension.registerExtensionPoint(project)
|
||||||
|
TypeResolutionInterceptorExtension.registerExtensionPoint(project)
|
||||||
|
CallResolutionInterceptorExtension.registerExtensionPoint(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun registerExtensionsFromPlugins(project: MockProject, configuration: CompilerConfiguration) {
|
internal fun registerExtensionsFromPlugins(project: MockProject, configuration: CompilerConfiguration) {
|
||||||
|
|||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package org.jetbrains.kotlin.extensions
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.CandidateResolver
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tower.NewResolutionOldInference
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.ResolutionScope
|
||||||
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingFacade
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
interface CallResolutionInterceptorExtension {
|
||||||
|
companion object : ProjectExtensionDescriptor<CallResolutionInterceptorExtension>(
|
||||||
|
"org.jetbrains.kotlin.callResolutionInterceptorExtension",
|
||||||
|
CallResolutionInterceptorExtension::class.java
|
||||||
|
)
|
||||||
|
|
||||||
|
fun interceptCandidates(
|
||||||
|
candidates: Collection<NewResolutionOldInference.MyCandidate>,
|
||||||
|
context: BasicCallResolutionContext,
|
||||||
|
candidateResolver: CandidateResolver,
|
||||||
|
callResolver: CallResolver?,
|
||||||
|
name: Name,
|
||||||
|
kind: NewResolutionOldInference.ResolutionKind,
|
||||||
|
tracing: TracingStrategy
|
||||||
|
): Collection<NewResolutionOldInference.MyCandidate> {
|
||||||
|
return candidates
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interceptCandidates(
|
||||||
|
candidates: Collection<FunctionDescriptor>,
|
||||||
|
scopeTower: ImplicitScopeTower,
|
||||||
|
resolutionContext: BasicCallResolutionContext,
|
||||||
|
resolutionScope: ResolutionScope,
|
||||||
|
callResolver: CallResolver?,
|
||||||
|
name: Name,
|
||||||
|
location: LookupLocation
|
||||||
|
): Collection<FunctionDescriptor> {
|
||||||
|
return candidates
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.extensions
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtLambdaExpression
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
||||||
|
|
||||||
|
interface TypeResolutionInterceptorExtension {
|
||||||
|
companion object : ProjectExtensionDescriptor<TypeResolutionInterceptorExtension>(
|
||||||
|
"org.jetbrains.kotlin.typeResolutionInterceptorExtension",
|
||||||
|
TypeResolutionInterceptorExtension::class.java
|
||||||
|
)
|
||||||
|
|
||||||
|
fun interceptFunctionLiteralDescriptor(
|
||||||
|
expression: KtLambdaExpression,
|
||||||
|
context: ExpressionTypingContext,
|
||||||
|
descriptor: AnonymousFunctionDescriptor
|
||||||
|
): AnonymousFunctionDescriptor = descriptor
|
||||||
|
|
||||||
|
fun interceptType(
|
||||||
|
element: KtElement,
|
||||||
|
context: ExpressionTypingContext,
|
||||||
|
resultType: KotlinType
|
||||||
|
): KotlinType = resultType
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.container.useImpl
|
|||||||
import org.jetbrains.kotlin.container.useInstance
|
import org.jetbrains.kotlin.container.useInstance
|
||||||
import org.jetbrains.kotlin.context.ModuleContext
|
import org.jetbrains.kotlin.context.ModuleContext
|
||||||
import org.jetbrains.kotlin.contracts.ContractDeserializerImpl
|
import org.jetbrains.kotlin.contracts.ContractDeserializerImpl
|
||||||
|
import org.jetbrains.kotlin.extensions.CallResolutionInterceptorExtension
|
||||||
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
||||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||||
@@ -73,6 +74,8 @@ fun StorageComponentContainer.configureModule(
|
|||||||
extension.registerModuleComponents(this, platform, moduleContext.module)
|
extension.registerModuleComponents(this, platform, moduleContext.module)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useInstance(CandidateInterceptor(CallResolutionInterceptorExtension.getInstances(moduleContext.project)))
|
||||||
|
|
||||||
useImpl<NewKotlinTypeCheckerImpl>()
|
useImpl<NewKotlinTypeCheckerImpl>()
|
||||||
|
|
||||||
if (languageVersionSettings.isTypeRefinementEnabled) {
|
if (languageVersionSettings.isTypeRefinementEnabled) {
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.extensions.CallResolutionInterceptorExtension
|
||||||
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.CandidateResolver
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tower.NewResolutionOldInference
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.ResolutionScope
|
||||||
|
|
||||||
|
class CandidateInterceptor(private val extensions: Collection<CallResolutionInterceptorExtension>) {
|
||||||
|
fun interceptCandidates(
|
||||||
|
candidates: Collection<NewResolutionOldInference.MyCandidate>,
|
||||||
|
context: BasicCallResolutionContext,
|
||||||
|
candidateResolver: CandidateResolver,
|
||||||
|
callResolver: CallResolver?,
|
||||||
|
name: Name,
|
||||||
|
kind: NewResolutionOldInference.ResolutionKind,
|
||||||
|
tracing: TracingStrategy
|
||||||
|
): Collection<NewResolutionOldInference.MyCandidate> {
|
||||||
|
return extensions.fold(candidates) { candidates, extension ->
|
||||||
|
extension.interceptCandidates(candidates, context, candidateResolver, callResolver, name, kind, tracing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interceptCandidates(
|
||||||
|
candidates: Collection<FunctionDescriptor>,
|
||||||
|
scopeTower: ImplicitScopeTower,
|
||||||
|
resolutionContext: BasicCallResolutionContext,
|
||||||
|
resolutionScope: ResolutionScope,
|
||||||
|
callResolver: CallResolver?,
|
||||||
|
name: Name,
|
||||||
|
location: LookupLocation
|
||||||
|
): Collection<FunctionDescriptor> {
|
||||||
|
return extensions.fold(candidates) { candidates, extension ->
|
||||||
|
extension.interceptCandidates(candidates, scopeTower, resolutionContext, resolutionScope, callResolver, name, location)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.extensions.TypeResolutionInterceptorExtension
|
||||||
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtLambdaExpression
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
||||||
|
|
||||||
|
class TypeResolutionInterceptor(private val project: Project) {
|
||||||
|
val extensions = TypeResolutionInterceptorExtension.getInstances(project)
|
||||||
|
fun interceptFunctionLiteralDescriptor(
|
||||||
|
expression: KtLambdaExpression,
|
||||||
|
context: ExpressionTypingContext,
|
||||||
|
descriptor: AnonymousFunctionDescriptor
|
||||||
|
): AnonymousFunctionDescriptor {
|
||||||
|
var resultDescriptor = descriptor
|
||||||
|
for (extension in extensions) {
|
||||||
|
resultDescriptor = extension.interceptFunctionLiteralDescriptor(
|
||||||
|
expression,
|
||||||
|
context,
|
||||||
|
descriptor
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return resultDescriptor
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interceptType(
|
||||||
|
element: KtElement,
|
||||||
|
context: ExpressionTypingContext,
|
||||||
|
resultType: KotlinType
|
||||||
|
): KotlinType {
|
||||||
|
var type = resultType
|
||||||
|
for (extension in extensions) {
|
||||||
|
type = extension.interceptType(element, context, type)
|
||||||
|
}
|
||||||
|
return type
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isEmpty() = extensions.isEmpty()
|
||||||
|
}
|
||||||
@@ -681,7 +681,7 @@ public class CallResolver {
|
|||||||
OverloadResolutionResultsImpl<D> result;
|
OverloadResolutionResultsImpl<D> result;
|
||||||
if (!(resolutionTask.resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates)) {
|
if (!(resolutionTask.resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates)) {
|
||||||
assert resolutionTask.name != null;
|
assert resolutionTask.name != null;
|
||||||
result = newResolutionOldInference.runResolution(context, resolutionTask.name, resolutionTask.resolutionKind, tracing);
|
result = newResolutionOldInference.runResolution(context, resolutionTask.name, resolutionTask.resolutionKind, tracing, this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert resolutionTask.givenCandidates != null;
|
assert resolutionTask.givenCandidates != null;
|
||||||
|
|||||||
+26
-11
@@ -27,7 +27,9 @@ import org.jetbrains.kotlin.psi.Call
|
|||||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||||
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.CandidateInterceptor
|
||||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
||||||
import org.jetbrains.kotlin.resolve.calls.CandidateResolver
|
import org.jetbrains.kotlin.resolve.calls.CandidateResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isBinaryRemOperator
|
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isBinaryRemOperator
|
||||||
@@ -49,10 +51,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.*
|
|||||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation
|
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation
|
||||||
import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope
|
import org.jetbrains.kotlin.resolve.scopes.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.canBeResolvedWithoutDeprecation
|
import org.jetbrains.kotlin.resolve.scopes.utils.canBeResolvedWithoutDeprecation
|
||||||
import org.jetbrains.kotlin.types.DeferredType
|
import org.jetbrains.kotlin.types.DeferredType
|
||||||
@@ -74,7 +73,8 @@ class NewResolutionOldInference(
|
|||||||
private val languageVersionSettings: LanguageVersionSettings,
|
private val languageVersionSettings: LanguageVersionSettings,
|
||||||
private val coroutineInferenceSupport: CoroutineInferenceSupport,
|
private val coroutineInferenceSupport: CoroutineInferenceSupport,
|
||||||
private val deprecationResolver: DeprecationResolver,
|
private val deprecationResolver: DeprecationResolver,
|
||||||
private val typeApproximator: TypeApproximator
|
private val typeApproximator: TypeApproximator,
|
||||||
|
private val candidateInterceptor: CandidateInterceptor
|
||||||
) {
|
) {
|
||||||
sealed class ResolutionKind {
|
sealed class ResolutionKind {
|
||||||
abstract internal fun createTowerProcessor(
|
abstract internal fun createTowerProcessor(
|
||||||
@@ -162,7 +162,8 @@ class NewResolutionOldInference(
|
|||||||
context: BasicCallResolutionContext,
|
context: BasicCallResolutionContext,
|
||||||
name: Name,
|
name: Name,
|
||||||
kind: ResolutionKind,
|
kind: ResolutionKind,
|
||||||
tracing: TracingStrategy
|
tracing: TracingStrategy,
|
||||||
|
callResolver: CallResolver
|
||||||
): OverloadResolutionResultsImpl<D> {
|
): OverloadResolutionResultsImpl<D> {
|
||||||
val explicitReceiver = context.call.explicitReceiver
|
val explicitReceiver = context.call.explicitReceiver
|
||||||
val detailedReceiver = if (explicitReceiver is QualifierReceiver?) {
|
val detailedReceiver = if (explicitReceiver is QualifierReceiver?) {
|
||||||
@@ -173,7 +174,7 @@ class NewResolutionOldInference(
|
|||||||
|
|
||||||
val dynamicScope = dynamicCallableDescriptors.createDynamicDescriptorScope(context.call, context.scope.ownerDescriptor)
|
val dynamicScope = dynamicCallableDescriptors.createDynamicDescriptorScope(context.call, context.scope.ownerDescriptor)
|
||||||
val scopeTower = ImplicitScopeTowerImpl(
|
val scopeTower = ImplicitScopeTowerImpl(
|
||||||
context, dynamicScope, syntheticScopes, context.call.createLookupLocation(), typeApproximator
|
context, dynamicScope, syntheticScopes, context.call.createLookupLocation(), typeApproximator, callResolver, candidateInterceptor
|
||||||
)
|
)
|
||||||
|
|
||||||
val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)
|
val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)
|
||||||
@@ -207,6 +208,8 @@ class NewResolutionOldInference(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
candidates = candidateInterceptor.interceptCandidates(candidates, context, candidateResolver, callResolver, name, kind, tracing)
|
||||||
|
|
||||||
if (candidates.isEmpty()) {
|
if (candidates.isEmpty()) {
|
||||||
if (reportAdditionalDiagnosticIfNoCandidates(context, nameToResolve, kind, scopeTower, detailedReceiver)) {
|
if (reportAdditionalDiagnosticIfNoCandidates(context, nameToResolve, kind, scopeTower, detailedReceiver)) {
|
||||||
return OverloadResolutionResultsImpl.nameNotFound()
|
return OverloadResolutionResultsImpl.nameNotFound()
|
||||||
@@ -353,12 +356,14 @@ class NewResolutionOldInference(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ImplicitScopeTowerImpl(
|
public class ImplicitScopeTowerImpl(
|
||||||
val resolutionContext: ResolutionContext<*>,
|
val resolutionContext: BasicCallResolutionContext,
|
||||||
override val dynamicScope: MemberScope,
|
override val dynamicScope: MemberScope,
|
||||||
override val syntheticScopes: SyntheticScopes,
|
override val syntheticScopes: SyntheticScopes,
|
||||||
override val location: LookupLocation,
|
override val location: LookupLocation,
|
||||||
override val typeApproximator: TypeApproximator
|
override val typeApproximator: TypeApproximator,
|
||||||
|
val callResolver: CallResolver,
|
||||||
|
val candidateInterceptor: CandidateInterceptor
|
||||||
) : ImplicitScopeTower {
|
) : ImplicitScopeTower {
|
||||||
private val cache = HashMap<ReceiverValue, ReceiverValueWithSmartCastInfo>()
|
private val cache = HashMap<ReceiverValue, ReceiverValueWithSmartCastInfo>()
|
||||||
|
|
||||||
@@ -373,9 +378,19 @@ class NewResolutionOldInference(
|
|||||||
|
|
||||||
override val isNewInferenceEnabled: Boolean
|
override val isNewInferenceEnabled: Boolean
|
||||||
get() = resolutionContext.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
|
get() = resolutionContext.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
|
||||||
|
|
||||||
|
override fun interceptCandidates(
|
||||||
|
resolutionScope: ResolutionScope,
|
||||||
|
name: Name,
|
||||||
|
candidates: Collection<FunctionDescriptor>,
|
||||||
|
location: LookupLocation
|
||||||
|
): Collection<FunctionDescriptor> {
|
||||||
|
val project = resolutionContext.call.callElement.project
|
||||||
|
return candidateInterceptor.interceptCandidates(candidates, this, resolutionContext, resolutionScope, callResolver, name, location)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class MyCandidate(
|
class MyCandidate(
|
||||||
// Diagnostics that are already computed
|
// Diagnostics that are already computed
|
||||||
// if resultingApplicability is successful they must be the same as `diagnostics`,
|
// if resultingApplicability is successful they must be the same as `diagnostics`,
|
||||||
// otherwise they might be a bit different but result remains unsuccessful
|
// otherwise they might be a bit different but result remains unsuccessful
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
|||||||
import org.jetbrains.kotlin.contracts.EffectSystem
|
import org.jetbrains.kotlin.contracts.EffectSystem
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
|
import org.jetbrains.kotlin.extensions.CallResolutionInterceptorExtension
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -39,6 +40,7 @@ import org.jetbrains.kotlin.resolve.calls.util.CallMaker
|
|||||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
import org.jetbrains.kotlin.resolve.scopes.*
|
import org.jetbrains.kotlin.resolve.scopes.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
@@ -67,7 +69,8 @@ class PSICallResolver(
|
|||||||
private val kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter,
|
private val kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter,
|
||||||
private val deprecationResolver: DeprecationResolver,
|
private val deprecationResolver: DeprecationResolver,
|
||||||
private val moduleDescriptor: ModuleDescriptor,
|
private val moduleDescriptor: ModuleDescriptor,
|
||||||
private val callableReferenceResolver: CallableReferenceResolver
|
private val callableReferenceResolver: CallableReferenceResolver,
|
||||||
|
private val candidateInterceptor: CandidateInterceptor
|
||||||
) {
|
) {
|
||||||
private val givenCandidatesName = Name.special("<given candidates>")
|
private val givenCandidatesName = Name.special("<given candidates>")
|
||||||
|
|
||||||
@@ -397,6 +400,16 @@ class PSICallResolver(
|
|||||||
context.transformToReceiverWithSmartCastInfo(implicitReceiver.value)
|
context.transformToReceiverWithSmartCastInfo(implicitReceiver.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun interceptCandidates(
|
||||||
|
resolutionScope: ResolutionScope,
|
||||||
|
name: Name,
|
||||||
|
candidates: Collection<FunctionDescriptor>,
|
||||||
|
location: LookupLocation
|
||||||
|
): Collection<FunctionDescriptor> {
|
||||||
|
val project = context.call.callElement.project
|
||||||
|
return candidateInterceptor.interceptCandidates(candidates, this, context, resolutionScope, null, name, location)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class FactoryProviderForInvoke(
|
private inner class FactoryProviderForInvoke(
|
||||||
|
|||||||
+6
-1
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.descriptors.*;
|
|||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
|
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||||
|
import org.jetbrains.kotlin.extensions.TypeResolutionInterceptorExtension;
|
||||||
import org.jetbrains.kotlin.incremental.KotlinLookupLocation;
|
import org.jetbrains.kotlin.incremental.KotlinLookupLocation;
|
||||||
import org.jetbrains.kotlin.lexer.KtKeywordToken;
|
import org.jetbrains.kotlin.lexer.KtKeywordToken;
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
@@ -1635,7 +1636,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (baseExpression == null) {
|
if (baseExpression == null) {
|
||||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||||
}
|
}
|
||||||
return facade.getTypeInfo(baseExpression, context, isStatement);
|
KotlinType newExpectedType = components.typeResolutionInterceptor.interceptType(baseExpression, context, context.expectedType);
|
||||||
|
KotlinTypeInfo resultTypeInfo = facade.getTypeInfo(baseExpression, newExpectedType == context.expectedType ? context : context.replaceExpectedType(newExpectedType), isStatement);
|
||||||
|
KotlinType newResultType = components.typeResolutionInterceptor.interceptType(baseExpression, context, resultTypeInfo.getType());
|
||||||
|
if(!components.typeResolutionInterceptor.isEmpty()) components.dataFlowAnalyzer.checkType(newResultType, expression, context);
|
||||||
|
return resultTypeInfo.getType() == newResultType ? resultTypeInfo : resultTypeInfo.replaceType(newResultType);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void resolveAnnotationsOnExpression(KtAnnotatedExpression expression, ExpressionTypingContext context) {
|
protected void resolveAnnotationsOnExpression(KtAnnotatedExpression expression, ExpressionTypingContext context) {
|
||||||
|
|||||||
+6
@@ -64,6 +64,7 @@ public class ExpressionTypingComponents {
|
|||||||
/*package*/ ContractParsingServices contractParsingServices;
|
/*package*/ ContractParsingServices contractParsingServices;
|
||||||
/*package*/ DataFlowValueFactory dataFlowValueFactory;
|
/*package*/ DataFlowValueFactory dataFlowValueFactory;
|
||||||
/*package*/ NewKotlinTypeChecker kotlinTypeChecker;
|
/*package*/ NewKotlinTypeChecker kotlinTypeChecker;
|
||||||
|
/*package*/ TypeResolutionInterceptor typeResolutionInterceptor;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -245,4 +246,9 @@ public class ExpressionTypingComponents {
|
|||||||
public void setKotlinTypeChecker(@NotNull NewKotlinTypeChecker kotlinTypeChecker) {
|
public void setKotlinTypeChecker(@NotNull NewKotlinTypeChecker kotlinTypeChecker) {
|
||||||
this.kotlinTypeChecker = kotlinTypeChecker;
|
this.kotlinTypeChecker = kotlinTypeChecker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public void setTypeResolutionInterceptor(@NotNull TypeResolutionInterceptor typeResolutionInterceptor) {
|
||||||
|
this.typeResolutionInterceptor = typeResolutionInterceptor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-6
@@ -21,11 +21,8 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.checkReservedPrefixWord
|
import org.jetbrains.kotlin.psi.psiUtil.checkReservedPrefixWord
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.checkReservedYieldBeforeLambda
|
import org.jetbrains.kotlin.psi.psiUtil.checkReservedYieldBeforeLambda
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries
|
import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.*
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext.EXPECTED_RETURN_TYPE
|
import org.jetbrains.kotlin.resolve.BindingContext.EXPECTED_RETURN_TYPE
|
||||||
import org.jetbrains.kotlin.resolve.BindingContextUtils
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
|
||||||
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
|
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
|
||||||
import org.jetbrains.kotlin.resolve.checkers.UnderscoreChecker
|
import org.jetbrains.kotlin.resolve.checkers.UnderscoreChecker
|
||||||
@@ -147,7 +144,12 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
|
|||||||
val safeReturnType = computeReturnType(expression, context, functionDescriptor, functionTypeExpected)
|
val safeReturnType = computeReturnType(expression, context, functionDescriptor, functionTypeExpected)
|
||||||
functionDescriptor.setReturnType(safeReturnType)
|
functionDescriptor.setReturnType(safeReturnType)
|
||||||
|
|
||||||
val resultType = functionDescriptor.createFunctionType(components.builtIns, suspendFunctionTypeExpected)!!
|
val resultType = components.typeResolutionInterceptor.interceptType(
|
||||||
|
expression,
|
||||||
|
context,
|
||||||
|
functionDescriptor.createFunctionType(components.builtIns, suspendFunctionTypeExpected)!!
|
||||||
|
)
|
||||||
|
|
||||||
if (functionTypeExpected) {
|
if (functionTypeExpected) {
|
||||||
// all checks were done before
|
// all checks were done before
|
||||||
return createTypeInfo(resultType, context)
|
return createTypeInfo(resultType, context)
|
||||||
@@ -175,7 +177,9 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
|
|||||||
components.annotationResolver.resolveAnnotationsWithArguments(context.scope, expression.getAnnotationEntries(), context.trace),
|
components.annotationResolver.resolveAnnotationsWithArguments(context.scope, expression.getAnnotationEntries(), context.trace),
|
||||||
CallableMemberDescriptor.Kind.DECLARATION, functionLiteral.toSourceElement(),
|
CallableMemberDescriptor.Kind.DECLARATION, functionLiteral.toSourceElement(),
|
||||||
context.expectedType.isSuspendFunctionType()
|
context.expectedType.isSuspendFunctionType()
|
||||||
)
|
).let {
|
||||||
|
TypeResolutionInterceptor(expression.project).interceptFunctionLiteralDescriptor(expression, context, it)
|
||||||
|
}
|
||||||
components.functionDescriptorResolver.initializeFunctionDescriptorAndExplicitReturnType(
|
components.functionDescriptorResolver.initializeFunctionDescriptorAndExplicitReturnType(
|
||||||
context.scope.ownerDescriptor, context.scope, functionLiteral,
|
context.scope.ownerDescriptor, context.scope, functionLiteral,
|
||||||
functionDescriptor, context.trace, context.expectedType, context.dataFlowInfo
|
functionDescriptor, context.trace, context.expectedType, context.dataFlowInfo
|
||||||
|
|||||||
+8
-3
@@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.tower
|
package org.jetbrains.kotlin.resolve.calls.tower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
|
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.DiagnosticReporter
|
import org.jetbrains.kotlin.resolve.calls.model.DiagnosticReporter
|
||||||
@@ -45,6 +43,13 @@ interface ImplicitScopeTower {
|
|||||||
val isNewInferenceEnabled: Boolean
|
val isNewInferenceEnabled: Boolean
|
||||||
|
|
||||||
val typeApproximator: TypeApproximator
|
val typeApproximator: TypeApproximator
|
||||||
|
|
||||||
|
fun interceptCandidates(
|
||||||
|
resolutionScope: ResolutionScope,
|
||||||
|
name: Name,
|
||||||
|
initialResults: Collection<FunctionDescriptor>,
|
||||||
|
location: LookupLocation
|
||||||
|
): Collection<FunctionDescriptor>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ScopeTowerLevel {
|
interface ScopeTowerLevel {
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.tower
|
package org.jetbrains.kotlin.resolve.calls.tower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
|
||||||
@@ -207,7 +210,7 @@ internal class QualifierScopeTowerLevel(scopeTower: ImplicitScopeTower, val qual
|
|||||||
.getContributedFunctionsAndConstructors(
|
.getContributedFunctionsAndConstructors(
|
||||||
name,
|
name,
|
||||||
location,
|
location,
|
||||||
scopeTower.syntheticScopes
|
scopeTower
|
||||||
).map {
|
).map {
|
||||||
createCandidateDescriptor(it, dispatchReceiver = null)
|
createCandidateDescriptor(it, dispatchReceiver = null)
|
||||||
}
|
}
|
||||||
@@ -255,7 +258,7 @@ internal open class ScopeBasedTowerLevel protected constructor(
|
|||||||
): Collection<CandidateWithBoundDispatchReceiver> {
|
): Collection<CandidateWithBoundDispatchReceiver> {
|
||||||
val result: ArrayList<CandidateWithBoundDispatchReceiver> = ArrayList()
|
val result: ArrayList<CandidateWithBoundDispatchReceiver> = ArrayList()
|
||||||
|
|
||||||
resolutionScope.getContributedFunctionsAndConstructors(name, location, scopeTower.syntheticScopes).mapTo(result) {
|
resolutionScope.getContributedFunctionsAndConstructors(name, location, scopeTower).mapTo(result) {
|
||||||
createCandidateDescriptor(
|
createCandidateDescriptor(
|
||||||
it,
|
it,
|
||||||
dispatchReceiver = null,
|
dispatchReceiver = null,
|
||||||
@@ -366,7 +369,7 @@ private fun KotlinType?.getInnerConstructors(name: Name, location: LookupLocatio
|
|||||||
private fun ResolutionScope.getContributedFunctionsAndConstructors(
|
private fun ResolutionScope.getContributedFunctionsAndConstructors(
|
||||||
name: Name,
|
name: Name,
|
||||||
location: LookupLocation,
|
location: LookupLocation,
|
||||||
syntheticScopes: SyntheticScopes
|
scopeTower: ImplicitScopeTower
|
||||||
): Collection<FunctionDescriptor> {
|
): Collection<FunctionDescriptor> {
|
||||||
val result = ArrayList<FunctionDescriptor>(getContributedFunctions(name, location))
|
val result = ArrayList<FunctionDescriptor>(getContributedFunctions(name, location))
|
||||||
|
|
||||||
@@ -374,10 +377,10 @@ private fun ResolutionScope.getContributedFunctionsAndConstructors(
|
|||||||
result.addAll(getConstructorsOfClassifier(it))
|
result.addAll(getConstructorsOfClassifier(it))
|
||||||
}
|
}
|
||||||
|
|
||||||
result.addAll(syntheticScopes.collectSyntheticStaticFunctions(this, name, location))
|
result.addAll(scopeTower.syntheticScopes.collectSyntheticStaticFunctions(this, name, location))
|
||||||
result.addAll(syntheticScopes.collectSyntheticConstructors(this, name, location))
|
result.addAll(scopeTower.syntheticScopes.collectSyntheticConstructors(this, name, location))
|
||||||
|
|
||||||
return result.toList()
|
return scopeTower.interceptCandidates(this, name, result, location).toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getConstructorsOfClassifier(classifier: ClassifierDescriptor?): List<ConstructorDescriptor> {
|
private fun getConstructorsOfClassifier(classifier: ClassifierDescriptor?): List<ConstructorDescriptor> {
|
||||||
|
|||||||
@@ -5,6 +5,15 @@
|
|||||||
<extensionPoints>
|
<extensionPoints>
|
||||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.diagnosticSuppressor"
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.diagnosticSuppressor"
|
||||||
interface="org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor"/>
|
interface="org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.analyzeCompleteHandlerExtension"
|
||||||
|
interface="org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension"
|
||||||
|
area="IDEA_PROJECT"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.callResolutionInterceptorExtension"
|
||||||
|
interface="org.jetbrains.kotlin.extensions.CallResolutionInterceptorExtension"
|
||||||
|
area="IDEA_PROJECT"/>
|
||||||
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.typeResolutionInterceptorExtension"
|
||||||
|
interface="org.jetbrains.kotlin.extensions.TypeResolutionInterceptorExtension"
|
||||||
|
area="IDEA_PROJECT"/>
|
||||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.expressionCodegenExtension"
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.expressionCodegenExtension"
|
||||||
interface="org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension"
|
interface="org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension"
|
||||||
area="IDEA_PROJECT"/>
|
area="IDEA_PROJECT"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user