Minor. moved util method to Companion of LexicalScope
This commit is contained in:
@@ -73,7 +73,7 @@ public fun <C : ResolutionContext<C>> ResolutionContext<C>.recordDataFlowInfo(ex
|
||||
|
||||
public fun BindingTrace.recordScope(scope: LexicalScope, element: KtElement?) {
|
||||
if (element != null) {
|
||||
record(BindingContext.LEXICAL_SCOPE, element, scope.takeSnapshot())
|
||||
record(BindingContext.LEXICAL_SCOPE, element, scope.takeSnapshot() as LexicalScope)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsLexicalScope
|
||||
import org.jetbrains.kotlin.resolve.validation.InfixValidator
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
public class LexicalScopeImpl @JvmOverloads constructor(
|
||||
parent: LexicalScope,
|
||||
parent: HierarchicalScope,
|
||||
override val ownerDescriptor: DeclarationDescriptor,
|
||||
override val isOwnerDescriptorAccessibleByLabel: Boolean,
|
||||
override val implicitReceiver: ReceiverParameterDescriptor?,
|
||||
|
||||
@@ -52,14 +52,21 @@ interface LexicalScope: HierarchicalScope {
|
||||
val isOwnerDescriptorAccessibleByLabel: Boolean
|
||||
|
||||
val implicitReceiver: ReceiverParameterDescriptor?
|
||||
|
||||
companion object {
|
||||
fun empty(parent: HierarchicalScope, ownerDescriptor: DeclarationDescriptor): BaseLexicalScope {
|
||||
return object : BaseLexicalScope(parent, ownerDescriptor) {
|
||||
override fun printStructure(p: Printer) {
|
||||
p.println("Empty lexical scope with owner = $ownerDescriptor and parent = ${parent}.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: common base interface instead direct inheritance
|
||||
interface ImportingScope : HierarchicalScope {
|
||||
override val parent: ImportingScope?
|
||||
|
||||
// methods getDeclaredSmth for this scope will be delegated to importScope
|
||||
|
||||
fun getContributedPackage(name: Name): PackageViewDescriptor?
|
||||
|
||||
fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor>
|
||||
|
||||
@@ -110,13 +110,13 @@ public fun HierarchicalScope.collectSyntheticExtensionProperties(receiverTypes:
|
||||
public fun HierarchicalScope.collectSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
|
||||
= collectAllFromImportingScopes { it.getContributedSyntheticExtensionFunctions(receiverTypes) }
|
||||
|
||||
public fun LexicalScope.takeSnapshot(): LexicalScope = if (this is LexicalWritableScope) takeSnapshot() else this
|
||||
public fun HierarchicalScope.takeSnapshot(): HierarchicalScope = if (this is LexicalWritableScope) takeSnapshot() else this
|
||||
|
||||
@JvmOverloads
|
||||
public fun KtScope.memberScopeAsImportingScope(parentScope: ImportingScope? = null): ImportingScope = MemberScopeToImportingScopeAdapter(parentScope, this)
|
||||
|
||||
@Deprecated("Temporary method for scope migration")
|
||||
public fun KtScope.memberScopeAsLexicalScope(): LexicalScope = memberScopeAsImportingScope().asLexicalScope(getContainingDeclaration())
|
||||
public fun KtScope.memberScopeAsLexicalScope(): LexicalScope = LexicalScope.empty(memberScopeAsImportingScope(), getContainingDeclaration())
|
||||
|
||||
private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: KtScope) : ImportingScope {
|
||||
override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
|
||||
@@ -248,10 +248,3 @@ fun chainImportingScopes(scopes: List<ImportingScope>, tail: ImportingScope? = n
|
||||
scope.withParent(current)
|
||||
}
|
||||
}
|
||||
|
||||
fun ImportingScope?.asLexicalScope(ownerDescriptor: DeclarationDescriptor): LexicalScope
|
||||
= object : BaseLexicalScope(this ?: ImportingScope.Empty, ownerDescriptor) {
|
||||
override fun printStructure(p: Printer) {
|
||||
p.println("Empty lexical scope with owner = $ownerDescriptor and parent = ${this@asLexicalScope}.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.tests.di.ContainerForTests;
|
||||
import org.jetbrains.kotlin.tests.di.InjectionKt;
|
||||
@@ -138,7 +137,7 @@ public class ExpectedResolveDataUtil {
|
||||
emptyModule.setDependencies(emptyModule);
|
||||
emptyModule.initialize(PackageFragmentProvider.Empty.INSTANCE$);
|
||||
|
||||
LexicalScopeImpl lexicalScope = new LexicalScopeImpl(ScopeUtilsKt.asLexicalScope(ImportingScope.Empty.INSTANCE, emptyModule), classDescriptor, false,
|
||||
LexicalScopeImpl lexicalScope = new LexicalScopeImpl(ImportingScope.Empty.INSTANCE, classDescriptor, false,
|
||||
classDescriptor.getThisAsReceiverParameter(),
|
||||
"Scope with implicit this for class: " + classDescriptor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user