Introduce ImportingScope::computeImportedNames
This commit is contained in:
@@ -22,15 +22,17 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.BaseImportingScope
|
import org.jetbrains.kotlin.resolve.scopes.BaseImportingScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ResolutionScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.computeAllNames
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
|
||||||
|
|
||||||
class AllUnderImportScope(
|
class AllUnderImportScope(
|
||||||
descriptor: DeclarationDescriptor,
|
descriptor: DeclarationDescriptor,
|
||||||
excludedImportNames: Collection<FqName>
|
excludedImportNames: Collection<FqName>
|
||||||
) : BaseImportingScope(null) {
|
) : BaseImportingScope(null) {
|
||||||
|
|
||||||
private val scopes: List<ResolutionScope> = if (descriptor is ClassDescriptor) {
|
private val scopes: List<MemberScope> = if (descriptor is ClassDescriptor) {
|
||||||
listOf(descriptor.staticScope, descriptor.unsubstitutedInnerClassesScope)
|
listOf(descriptor.staticScope, descriptor.unsubstitutedInnerClassesScope)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -49,6 +51,8 @@ class AllUnderImportScope(
|
|||||||
excludedImportNames.mapNotNull { if (it.parent() == fqName) it.shortName() else null }.toSet()
|
excludedImportNames.mapNotNull { if (it.parent() == fqName) it.shortName() else null }.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun computeImportedNames(): Set<Name>? = scopes.flatMapToNullable(hashSetOf(), MemberScope::computeAllNames)
|
||||||
|
|
||||||
override fun getContributedDescriptors(
|
override fun getContributedDescriptors(
|
||||||
kindFilter: DescriptorKindFilter,
|
kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean,
|
nameFilter: (Name) -> Boolean,
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ class LazyExplicitImportScope(
|
|||||||
return descriptors
|
return descriptors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun computeImportedNames() = setOf(aliasName)
|
||||||
|
|
||||||
override fun printStructure(p: Printer) {
|
override fun printStructure(p: Printer) {
|
||||||
p.println(this::class.java.simpleName, ": ", aliasName)
|
p.println(this::class.java.simpleName, ": ", aliasName)
|
||||||
}
|
}
|
||||||
@@ -148,4 +150,4 @@ class LazyExplicitImportScope(
|
|||||||
private fun <D : CallableMemberDescriptor> Collection<D>.choseOnlyVisibleOrAll() =
|
private fun <D : CallableMemberDescriptor> Collection<D>.choseOnlyVisibleOrAll() =
|
||||||
filter { isVisible(it, packageFragmentForVisibilityCheck, position = QualifierPosition.IMPORT) }.
|
filter { isVisible(it, packageFragmentForVisibilityCheck, position = QualifierPosition.IMPORT) }.
|
||||||
takeIf { it.isNotEmpty() } ?: this
|
takeIf { it.isNotEmpty() } ?: this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
|||||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
import org.jetbrains.kotlin.psi.KtImportDirective
|
||||||
import org.jetbrains.kotlin.psi.KtImportsFactory
|
import org.jetbrains.kotlin.psi.KtImportsFactory
|
||||||
import org.jetbrains.kotlin.resolve.*
|
import org.jetbrains.kotlin.resolve.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.SubpackagesImportingScope
|
|
||||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||||
import org.jetbrains.kotlin.script.getScriptExternalDependencies
|
import org.jetbrains.kotlin.script.getScriptExternalDependencies
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
@@ -220,6 +217,8 @@ class FileScopeFactory(
|
|||||||
).filter { it !is PackageViewDescriptor } // subpackages of the current package not accessible by the short name
|
).filter { it !is PackageViewDescriptor } // subpackages of the current package not accessible by the short name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun computeImportedNames() = packageView.memberScope.computeAllNames()
|
||||||
|
|
||||||
override fun toString() = "Scope for current package (${filteringKind.name})"
|
override fun toString() = "Scope for current package (${filteringKind.name})"
|
||||||
|
|
||||||
override fun printStructure(p: Printer) {
|
override fun printStructure(p: Printer) {
|
||||||
|
|||||||
@@ -121,12 +121,15 @@ interface ImportingScope : HierarchicalScope {
|
|||||||
return getContributedDescriptors(kindFilter, nameFilter, changeNamesForAliased = false)
|
return getContributedDescriptors(kindFilter, nameFilter, changeNamesForAliased = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun computeImportedNames(): Set<Name>?
|
||||||
|
|
||||||
object Empty : BaseImportingScope(null) {
|
object Empty : BaseImportingScope(null) {
|
||||||
override fun printStructure(p: Printer) {
|
override fun printStructure(p: Printer) {
|
||||||
p.println("ImportingScope.Empty")
|
p.println("ImportingScope.Empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun definitelyDoesNotContainName(name: Name) = true
|
override fun definitelyDoesNotContainName(name: Name) = true
|
||||||
|
override fun computeImportedNames() = emptySet<Name>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -48,4 +48,5 @@ class SubpackagesImportingScope(
|
|||||||
//TODO: kept old behavior, but it seems very strange (super call seems more applicable)
|
//TODO: kept old behavior, but it seems very strange (super call seems more applicable)
|
||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean, changeNamesForAliased: Boolean): Collection<DeclarationDescriptor>
|
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean, changeNamesForAliased: Boolean): Collection<DeclarationDescriptor>
|
||||||
= emptyList()
|
= emptyList()
|
||||||
|
override fun computeImportedNames() = emptySet<Name>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,8 @@ private class MemberScopeToImportingScopeAdapter(override val parent: ImportingS
|
|||||||
|
|
||||||
override fun toString() = "${this::class.java.simpleName} for $memberScope"
|
override fun toString() = "${this::class.java.simpleName} for $memberScope"
|
||||||
|
|
||||||
|
override fun computeImportedNames() = memberScope.computeAllNames()
|
||||||
|
|
||||||
override fun printStructure(p: Printer) {
|
override fun printStructure(p: Printer) {
|
||||||
p.println(this::class.java.simpleName)
|
p.println(this::class.java.simpleName)
|
||||||
p.pushIndent()
|
p.pushIndent()
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescri
|
|||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean, changeNamesForAliased: Boolean)
|
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean, changeNamesForAliased: Boolean)
|
||||||
= descriptors
|
= descriptors
|
||||||
|
|
||||||
|
override fun computeImportedNames() = descriptors.mapTo(hashSetOf()) { it.name }
|
||||||
|
|
||||||
override fun printStructure(p: Printer) {
|
override fun printStructure(p: Printer) {
|
||||||
p.println(this::class.java.name)
|
p.println(this::class.java.name)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user