KT-9638 Optimize imports: don't create import for static methods from superclasses

#KT-9638 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-10-18 20:44:27 +03:00
parent edd2d853b1
commit 27228c2fcc
9 changed files with 139 additions and 19 deletions
@@ -281,16 +281,28 @@ public fun LexicalScope.addImportScope(importScope: JetScope): LexicalScope {
val fileScope = getFileScope()
val scopeWithAdditionImport =
LexicalChainedScope(fileScope, fileScope.ownerDescriptor, false, null, "Scope with addition import", importScope)
return LexicalScopeWrapper(this, scopeWithAdditionImport)
return replaceFileScope(scopeWithAdditionImport)
}
public fun LexicalScope.replaceFileScope(fileScopeReplace: LexicalScope): LexicalScope {
if (this is FileScope) return fileScopeReplace
return LexicalScopeWrapper(this, fileScopeReplace)
}
public fun LexicalScope.withNoFileScope(): LexicalScope = replaceFileScope(MemberScopeToFileScopeAdapter(JetScope.Empty))
private class LexicalScopeWrapper(val delegate: LexicalScope, val fileScopeReplace: LexicalScope): LexicalScope by delegate {
override val parent: LexicalScope? by lazy(LazyThreadSafetyMode.NONE) {
if (delegate is FileScope) {
assert(delegate !is FileScope) { "We should replace FileScope($delegate) to $fileScopeReplace" }
val parent = delegate.parent!!
if (parent is FileScope) {
fileScopeReplace
}
else {
LexicalScopeWrapper(delegate.parent!!, fileScopeReplace)
LexicalScopeWrapper(parent, fileScopeReplace)
}
}
}