FileScopeProvider.AdditionalScopes return ImportingScope's

This commit is contained in:
Valentin Kipyatkov
2015-10-24 12:36:27 +03:00
parent 99aeb305db
commit c93de93332
8 changed files with 44 additions and 25 deletions
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.lazy
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.KtScope
public interface FileScopeProvider {
fun getFileScopeChain(file: KtFile): ImportingScope
@@ -30,7 +29,7 @@ public interface FileScopeProvider {
}
public interface AdditionalScopes {
public val scopes: List<KtScope>
public val scopes: List<ImportingScope>
}
}
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
import org.jetbrains.kotlin.resolve.scopes.utils.withParent
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.sure
@@ -86,7 +87,8 @@ public class FileScopeProviderImpl(
"All under imports in $debugName (invisible classes only)")
for (additionalScope in additionalScopes.flatMap { it.scopes }) {
scope = additionalScope.memberScopeAsImportingScope(scope)
assert(additionalScope.parent == null)
scope = additionalScope.withParent(scope)
}
scope = LazyImportScope(scope, packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES,
@@ -290,6 +290,11 @@ fun LexicalScope.addImportScope(importScope: ImportingScope): LexicalScope {
}
fun ImportingScope.withParent(newParent: ImportingScope?): ImportingScope {
// TODO: it's a hack for Repl
if (this is MemberScopeToImportingScopeAdapter) {
return MemberScopeToImportingScopeAdapter(newParent, memberScope)
}
return object: ImportingScope by this {
override val parent: ImportingScope?
get() = newParent
@@ -317,3 +322,10 @@ private class LexicalScopeWrapper(val delegate: LexicalScope, val newImportingSc
}
}
fun chainImportingScopes(scopes: List<ImportingScope>): ImportingScope? {
return scopes.asReversed()
.fold<ImportingScope, ImportingScope?>(null) { current, scope ->
assert(scope.parent == null)
scope.withParent(current)
}
}