Refactoring of Importer - PlatformToKotlinClassMap is the same for all imports
This commit is contained in:
@@ -25,14 +25,16 @@ import org.jetbrains.kotlin.resolve.scopes.WritableScope
|
||||
import java.util.ArrayList
|
||||
|
||||
public trait Importer {
|
||||
public fun addAllUnderImport(descriptor: DeclarationDescriptor, platformToKotlinClassMap: PlatformToKotlinClassMap)
|
||||
|
||||
public fun addAllUnderImport(descriptor: DeclarationDescriptor)
|
||||
public fun addAliasImport(descriptor: DeclarationDescriptor, aliasName: Name)
|
||||
|
||||
public open class StandardImporter(private val fileScope: WritableScope) : Importer {
|
||||
public open class StandardImporter(
|
||||
private val fileScope: WritableScope,
|
||||
private val platformToKotlinClassMap: PlatformToKotlinClassMap
|
||||
) : Importer {
|
||||
|
||||
override fun addAllUnderImport(descriptor: DeclarationDescriptor, platformToKotlinClassMap: PlatformToKotlinClassMap) {
|
||||
importAllUnderDeclaration(descriptor, platformToKotlinClassMap)
|
||||
override fun addAllUnderImport(descriptor: DeclarationDescriptor) {
|
||||
importAllUnderDeclaration(descriptor)
|
||||
}
|
||||
|
||||
override fun addAliasImport(descriptor: DeclarationDescriptor, aliasName: Name) {
|
||||
@@ -49,7 +51,7 @@ public trait Importer {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun importAllUnderDeclaration(descriptor: DeclarationDescriptor, platformToKotlinClassMap: PlatformToKotlinClassMap) {
|
||||
protected fun importAllUnderDeclaration(descriptor: DeclarationDescriptor) {
|
||||
if (descriptor is PackageViewDescriptor) {
|
||||
val scope = NoSubpackagesInPackageScope(descriptor)
|
||||
fileScope.importScope(createFilteringScope(scope, descriptor, platformToKotlinClassMap))
|
||||
@@ -71,17 +73,21 @@ public trait Importer {
|
||||
}
|
||||
}
|
||||
|
||||
public class DelayedImporter(fileScope: WritableScope) : StandardImporter(fileScope) {
|
||||
public class DelayedImporter(
|
||||
fileScope: WritableScope,
|
||||
platformToKotlinClassMap: PlatformToKotlinClassMap
|
||||
) : StandardImporter(fileScope, platformToKotlinClassMap) {
|
||||
|
||||
private trait DelayedImportEntry
|
||||
|
||||
private class AllUnderImportEntry(val first: DeclarationDescriptor, val second: PlatformToKotlinClassMap) : DelayedImportEntry
|
||||
private class AllUnderImportEntry(val descriptor: DeclarationDescriptor) : DelayedImportEntry
|
||||
|
||||
private class AliasImportEntry(val first: DeclarationDescriptor, val second: Name) : DelayedImportEntry
|
||||
private class AliasImportEntry(val descriptor: DeclarationDescriptor, val name: Name) : DelayedImportEntry
|
||||
|
||||
private val imports = ArrayList<DelayedImportEntry>()
|
||||
|
||||
override fun addAllUnderImport(descriptor: DeclarationDescriptor, platformToKotlinClassMap: PlatformToKotlinClassMap) {
|
||||
imports.add(AllUnderImportEntry(descriptor, platformToKotlinClassMap))
|
||||
override fun addAllUnderImport(descriptor: DeclarationDescriptor) {
|
||||
imports.add(AllUnderImportEntry(descriptor))
|
||||
}
|
||||
|
||||
override fun addAliasImport(descriptor: DeclarationDescriptor, aliasName: Name) {
|
||||
@@ -91,18 +97,18 @@ public trait Importer {
|
||||
public fun processImports() {
|
||||
for (anImport in imports) {
|
||||
if (anImport is AllUnderImportEntry) {
|
||||
importAllUnderDeclaration(anImport.first, anImport.second)
|
||||
importAllUnderDeclaration(anImport.descriptor)
|
||||
}
|
||||
else {
|
||||
anImport as AliasImportEntry
|
||||
importDeclarationAlias(anImport.first, anImport.second)
|
||||
importDeclarationAlias(anImport.descriptor, anImport.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object DoNothingImporter : Importer {
|
||||
override fun addAllUnderImport(descriptor: DeclarationDescriptor, platformToKotlinClassMap: PlatformToKotlinClassMap) {
|
||||
override fun addAllUnderImport(descriptor: DeclarationDescriptor) {
|
||||
}
|
||||
|
||||
override fun addAliasImport(descriptor: DeclarationDescriptor, aliasName: Name) {
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ImportsResolver {
|
||||
) {
|
||||
@NotNull JetScope rootScope = JetModuleUtil.getSubpackagesOfRootScope(module);
|
||||
|
||||
Importer.DelayedImporter delayedImporter = new Importer.DelayedImporter(fileScope);
|
||||
Importer.DelayedImporter delayedImporter = new Importer.DelayedImporter(fileScope, module.getPlatformToKotlinClassMap());
|
||||
if (lookupMode == LookupMode.EVERYTHING) {
|
||||
fileScope.clearImports();
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class ImportsResolver {
|
||||
|
||||
JetImportDirective defaultImportDirective = importsFactory.createImportDirective(defaultImportPath);
|
||||
qualifiedExpressionResolver.processImportReference(defaultImportDirective, rootScope, fileScope, delayedImporter,
|
||||
temporaryTrace, module, lookupMode);
|
||||
temporaryTrace, lookupMode);
|
||||
}
|
||||
|
||||
Map<JetImportDirective, Collection<? extends DeclarationDescriptor>> resolvedDirectives = Maps.newHashMap();
|
||||
@@ -120,7 +120,7 @@ public class ImportsResolver {
|
||||
for (JetImportDirective importDirective : importDirectives) {
|
||||
Collection<? extends DeclarationDescriptor> descriptors =
|
||||
qualifiedExpressionResolver.processImportReference(importDirective, rootScopeForFile, fileScope, delayedImporter,
|
||||
trace, module, lookupMode);
|
||||
trace, lookupMode);
|
||||
if (!descriptors.isEmpty()) {
|
||||
resolvedDirectives.put(importDirective, descriptors);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ public class QualifiedExpressionResolver {
|
||||
@NotNull JetScope scopeToCheckVisibility,
|
||||
@NotNull Importer importer,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull ModuleDescriptor module,
|
||||
@NotNull LookupMode lookupMode
|
||||
) {
|
||||
if (importDirective.isAbsoluteInRootPackage()) {
|
||||
@@ -93,7 +92,7 @@ public class QualifiedExpressionResolver {
|
||||
}
|
||||
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
importer.addAllUnderImport(descriptor, module.getPlatformToKotlinClassMap());
|
||||
importer.addAllUnderImport(descriptor);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -69,14 +69,14 @@ public class LazyImportScope(private val resolveSession: ResolveSession,
|
||||
val directiveImportScope = WritableScopeImpl(JetScope.Empty, containingDeclaration, RedeclarationHandler.DO_NOTHING, "Scope for import '" + directive.getDebugText() + "' resolve in " + toString())
|
||||
directiveImportScope.changeLockLevel(WritableScope.LockLevel.BOTH)
|
||||
|
||||
val importer = Importer.StandardImporter(directiveImportScope)
|
||||
val importer = Importer.StandardImporter(directiveImportScope, resolveSession.getModuleDescriptor().platformToKotlinClassMap)
|
||||
directiveUnderResolve = directive
|
||||
|
||||
val descriptors: Collection<DeclarationDescriptor>
|
||||
try {
|
||||
val resolver = resolveSession.getQualifiedExpressionResolver()
|
||||
descriptors = resolver.processImportReference(directive, rootScope, containingDeclaration.getMemberScope(),
|
||||
importer, traceForImportResolve, resolveSession.getModuleDescriptor(), mode)
|
||||
importer, traceForImportResolve, mode)
|
||||
if (mode == LookupMode.EVERYTHING) {
|
||||
ImportsResolver.checkPlatformTypesMappedToKotlin(containingDeclaration.getModule(), traceForImportResolve, directive, descriptors)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user