Move import exclusion logic from ModuleDescriptorImpl to frontend

This commit is contained in:
Alexander Udalov
2016-10-19 19:28:17 +03:00
parent 2bf0eb9e69
commit 43c2b21987
7 changed files with 83 additions and 43 deletions
@@ -43,7 +43,10 @@ interface ModuleDescriptor : DeclarationDescriptor {
val defaultImports: List<ImportPath>
val effectivelyExcludedImports: List<FqName>
/**
* @return dependent modules in the same order in which this module depends on them. Does not include `this`
*/
val allDependentModules: List<ModuleDescriptor>
fun <T> getCapability(capability: Capability<T>): T?
@@ -20,18 +20,11 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.isChildOf
import org.jetbrains.kotlin.name.isSubpackageOf
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.sure
import java.lang.IllegalArgumentException
@@ -55,28 +48,8 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
fqName: FqName -> LazyPackageViewDescriptorImpl(this, fqName, storageManager)
}
override val effectivelyExcludedImports: List<FqName> by storageManager.createLazyValue {
val packagesWithAliases = listOf(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME, KotlinBuiltIns.TEXT_PACKAGE_FQ_NAME)
val dependencies = this.dependencies.sure { "Dependencies of module $id were not set" }
val builtinTypeAliases = dependencies.allDependencies.filter { it != this }.flatMap {
packagesWithAliases.map(it::getPackage).flatMap {
it.memberScope.getContributedDescriptors(DescriptorKindFilter.TYPE_ALIASES).filterIsInstance<TypeAliasDescriptor>()
}
}
val nonKotlinDefaultImportedPackages =
defaultImports
.filter { it.isAllUnder }
.mapNotNull {
it.fqnPart().check { !it.isSubpackageOf(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) }
}
val nonKotlinAliasedTypeFqNames =
builtinTypeAliases
.mapNotNull { it.expandedType.constructor.declarationDescriptor?.fqNameSafe }
.filter { nonKotlinDefaultImportedPackages.any(it::isChildOf) }
nonKotlinAliasedTypeFqNames
}
override val allDependentModules: List<ModuleDescriptor>
get() = this.dependencies.sure { "Dependencies of module $id were not set" }.allDependencies.filter { it != this }
override fun getPackage(fqName: FqName): PackageViewDescriptor = packages(fqName)
@@ -62,12 +62,6 @@ public class ErrorUtils {
return emptyList();
}
@NotNull
@Override
public List<FqName> getEffectivelyExcludedImports() {
return emptyList();
}
@NotNull
@Override
public Annotations getAnnotations() {
@@ -94,6 +88,12 @@ public class ErrorUtils {
throw new IllegalStateException("Should not be called!");
}
@NotNull
@Override
public List<ModuleDescriptor> getAllDependentModules() {
return emptyList();
}
@Override
public <R, D> R accept(@NotNull DeclarationDescriptorVisitor<R, D> visitor, D data) {
return null;