Changes after review
- Replace leaking ModuleResolverTracker with use of ModuleDescriptor.Capabilies - Provide API for retrieving ResolverForProject from ResolutionFacade - Update names
This commit is contained in:
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.AnchorProvider
|
||||
|
||||
interface ModuleDescriptor : DeclarationDescriptor {
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor? = null
|
||||
@@ -62,6 +61,4 @@ interface ModuleDescriptor : DeclarationDescriptor {
|
||||
val isValid: Boolean
|
||||
|
||||
fun assertValid()
|
||||
|
||||
val anchorProvider: AnchorProvider
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.resolve.RESOLUTION_ANCHOR_PROVIDER_CAPABILITY
|
||||
|
||||
fun ModuleDescriptor.findClassifierAcrossModuleDependencies(classId: ClassId): ClassifierDescriptor? = withAnchorFallback {
|
||||
val packageViewDescriptor = getPackage(classId.packageFqName)
|
||||
@@ -39,7 +40,7 @@ fun ModuleDescriptor.findClassifierAcrossModuleDependencies(classId: ClassId): C
|
||||
private inline fun ModuleDescriptor.withAnchorFallback(
|
||||
crossinline doSearch: ModuleDescriptor.() -> ClassifierDescriptor?
|
||||
): ClassifierDescriptor? {
|
||||
val anchor = anchorProvider.getAnchor(this)
|
||||
val anchor = getCapability(RESOLUTION_ANCHOR_PROVIDER_CAPABILITY)?.getResolutionAnchor(this)
|
||||
return if (anchor == null) doSearch() else doSearch() ?: anchor.doSearch()
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.AnchorProvider
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.checker.REFINER_CAPABILITY
|
||||
import org.jetbrains.kotlin.types.checker.Ref
|
||||
@@ -40,7 +39,6 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
override val platform: TargetPlatform? = null,
|
||||
capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap(),
|
||||
override val stableName: Name? = null,
|
||||
override val anchorProvider: AnchorProvider = AnchorProvider.Default,
|
||||
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor {
|
||||
private val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.ModuleDescriptor
|
||||
|
||||
abstract class AnchorProvider {
|
||||
open fun getAnchor(moduleDescriptor: ModuleDescriptor): ModuleDescriptor? = null
|
||||
|
||||
companion object Default : AnchorProvider()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.ModuleDescriptor
|
||||
|
||||
interface ResolutionAnchorProvider {
|
||||
fun getResolutionAnchor(moduleDescriptor: ModuleDescriptor): ModuleDescriptor? = null
|
||||
|
||||
companion object {
|
||||
val Default: ResolutionAnchorProvider = object : ResolutionAnchorProvider {
|
||||
override fun getResolutionAnchor(moduleDescriptor: ModuleDescriptor): ModuleDescriptor? = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val RESOLUTION_ANCHOR_PROVIDER_CAPABILITY = ModuleDescriptor.Capability<ResolutionAnchorProvider>("ResolutionAnchorProvider")
|
||||
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform;
|
||||
import org.jetbrains.kotlin.resolve.AnchorProvider;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
@@ -54,12 +53,6 @@ public class ErrorUtils {
|
||||
|
||||
static {
|
||||
ERROR_MODULE = new ModuleDescriptor() {
|
||||
@NotNull
|
||||
@Override
|
||||
public AnchorProvider getAnchorProvider() {
|
||||
return AnchorProvider.Default;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@NotNull Capability<T> capability) {
|
||||
|
||||
Reference in New Issue
Block a user