Renamed FileScope to ImportingScope and it now may have parent. But all implementations currently have parent == null

This commit is contained in:
Valentin Kipyatkov
2015-10-23 17:57:58 +03:00
parent 294559a94f
commit 712e294eac
10 changed files with 80 additions and 60 deletions
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.psi.KtScript; import org.jetbrains.kotlin.psi.KtScript;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer; import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer;
import org.jetbrains.kotlin.resolve.lazy.LazyFileScope; import org.jetbrains.kotlin.resolve.lazy.LazyImportingScope;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@@ -89,7 +89,7 @@ public class LazyTopDownAnalyzerForTopLevel {
} }
private static void resolveAndCheckImports(@NotNull KtFile file, @NotNull KotlinCodeAnalyzer resolveSession) { private static void resolveAndCheckImports(@NotNull KtFile file, @NotNull KotlinCodeAnalyzer resolveSession) {
LazyFileScope fileScope = resolveSession.getFileScopeProvider().getFileScope(file); LazyImportingScope fileScope = resolveSession.getFileScopeProvider().getFileScope(file);
fileScope.forceResolveAllImports(); fileScope.forceResolveAllImports();
} }
} }
@@ -20,10 +20,10 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.scopes.KtScope import org.jetbrains.kotlin.resolve.scopes.KtScope
public interface FileScopeProvider { public interface FileScopeProvider {
fun getFileScope(file: KtFile): LazyFileScope fun getFileScope(file: KtFile): LazyImportingScope
public object ThrowException : FileScopeProvider { public object ThrowException : FileScopeProvider {
override fun getFileScope(file: KtFile): LazyFileScope { override fun getFileScope(file: KtFile): LazyImportingScope {
throw UnsupportedOperationException("Should not be called") throw UnsupportedOperationException("Should not be called")
} }
} }
@@ -51,7 +51,7 @@ public class FileScopeProviderImpl(
override fun getFileScope(file: KtFile) = fileScopes(file) override fun getFileScope(file: KtFile) = fileScopes(file)
private fun createFileScope(file: KtFile): LazyFileScope { private fun createFileScope(file: KtFile): LazyImportingScope {
val debugName = "LazyFileScope for file " + file.getName() val debugName = "LazyFileScope for file " + file.getName()
val tempTrace = TemporaryBindingTrace.create(bindingTrace, "Transient trace for default imports lazy resolve") val tempTrace = TemporaryBindingTrace.create(bindingTrace, "Transient trace for default imports lazy resolve")
@@ -89,7 +89,7 @@ public class FileScopeProviderImpl(
scopeChain.add(LazyImportScope(packageFragment, allUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES, "All under imports in $debugName (invisible classes only)")) scopeChain.add(LazyImportScope(packageFragment, allUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES, "All under imports in $debugName (invisible classes only)"))
scopeChain.add(LazyImportScope(packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES, "Default all under imports in $debugName (invisible classes only)")) scopeChain.add(LazyImportScope(packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES, "Default all under imports in $debugName (invisible classes only)"))
val lazyFileScope = LazyFileScope(scopeChain, aliasImportResolver, allUnderImportResolver, packageFragment, debugName) val lazyFileScope = LazyImportingScope(scopeChain, aliasImportResolver, allUnderImportResolver, packageFragment, debugName)
bindingTrace.recordScope(lazyFileScope, file) bindingTrace.recordScope(lazyFileScope, file)
return lazyFileScope return lazyFileScope
} }
@@ -22,17 +22,20 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtImportDirective import org.jetbrains.kotlin.psi.KtImportDirective
import org.jetbrains.kotlin.resolve.scopes.ChainedScope import org.jetbrains.kotlin.resolve.scopes.ChainedScope
import org.jetbrains.kotlin.resolve.scopes.FileScope import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.KtScope import org.jetbrains.kotlin.resolve.scopes.KtScope
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
class LazyFileScope( class LazyImportingScope(
scopeChain: List<KtScope>, scopeChain: List<KtScope>,
private val aliasImportResolver: LazyImportResolver, private val aliasImportResolver: LazyImportResolver,
private val allUnderImportResolver: LazyImportResolver, private val allUnderImportResolver: LazyImportResolver,
containingDeclaration: PackageFragmentDescriptor, containingDeclaration: PackageFragmentDescriptor,
debugName: String debugName: String
) : ChainedScope(containingDeclaration, debugName, *scopeChain.toTypedArray()), FileScope { ) : ChainedScope(containingDeclaration, debugName, *scopeChain.toTypedArray()), ImportingScope {
override val parent: ImportingScope?
get() = null
override fun getDeclaredDescriptors() = emptyList<DeclarationDescriptor>() override fun getDeclaredDescriptors() = emptyList<DeclarationDescriptor>()
override fun printStructure(p: Printer) = printScopeStructure(p) override fun printStructure(p: Printer) = printScopeStructure(p)
@@ -207,7 +207,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
} }
private LazyAnnotations createAnnotations(KtFile file, List<KtAnnotationEntry> annotationEntries) { private LazyAnnotations createAnnotations(KtFile file, List<KtAnnotationEntry> annotationEntries) {
LazyFileScope scope = fileScopeProvider.getFileScope(file); LazyImportingScope scope = fileScopeProvider.getFileScope(file);
LazyAnnotationsContextImpl lazyAnnotationContext = LazyAnnotationsContextImpl lazyAnnotationContext =
new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope); new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope);
return new LazyAnnotations(lazyAnnotationContext, annotationEntries); return new LazyAnnotations(lazyAnnotationContext, annotationEntries);
@@ -21,21 +21,21 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.lazy.LazyFileScope import org.jetbrains.kotlin.resolve.lazy.LazyImportingScope
import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.resolve.scopes.*
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.collectionUtils.concat import org.jetbrains.kotlin.util.collectionUtils.concat
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
public fun LexicalScope.getFileScope(): FileScope { public fun LexicalScope.getFileScope(): ImportingScope {
var currentScope = this var currentScope = this
while(currentScope.parent != null) { while(currentScope.parent != null) {
currentScope = currentScope.parent!! currentScope = currentScope.parent!!
} }
assert(currentScope is FileScope) { assert(currentScope is ImportingScope) {
"Not FileScope without parent: $currentScope" // todo improve debug message "Not FileScope without parent: $currentScope" // todo improve debug message
} }
return currentScope as FileScope return currentScope as ImportingScope
} }
/** /**
@@ -45,7 +45,7 @@ public fun LexicalScope.getImplicitReceiversHierarchy(): List<ReceiverParameterD
// todo remove hack // todo remove hack
var jetScopeRefactoringHack: KtScope? = null var jetScopeRefactoringHack: KtScope? = null
val receivers = collectFromMeAndParent { val receivers = collectFromMeAndParent {
if (it is MemberScopeToFileScopeAdapter) { if (it is MemberScopeToImportingScopeAdapter) {
jetScopeRefactoringHack = it.memberScope jetScopeRefactoringHack = it.memberScope
} }
it.implicitReceiver it.implicitReceiver
@@ -60,7 +60,7 @@ public fun LexicalScope.getImplicitReceiversHierarchy(): List<ReceiverParameterD
} }
public fun LexicalScope.getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = collectAllFromMeAndParent { public fun LexicalScope.getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = collectAllFromMeAndParent {
if(it is MemberScopeToFileScopeAdapter) { // todo remove this hack if(it is MemberScopeToImportingScopeAdapter) { // todo remove this hack
it.memberScope.getDeclarationsByLabel(labelName) it.memberScope.getDeclarationsByLabel(labelName)
} }
else if (it.isOwnerDescriptorAccessibleByLabel && it.ownerDescriptor.name == labelName) { else if (it.isOwnerDescriptorAccessibleByLabel && it.ownerDescriptor.name == labelName) {
@@ -78,7 +78,7 @@ public fun LexicalScope.getDescriptorsFiltered(
): Collection<DeclarationDescriptor> { ): Collection<DeclarationDescriptor> {
if (kindFilter.kindMask == 0) return listOf() if (kindFilter.kindMask == 0) return listOf()
return collectAllFromMeAndParent { return collectAllFromMeAndParent {
if (it is FileScope) { if (it is ImportingScope) {
it.getDescriptors(kindFilter, nameFilter) it.getDescriptors(kindFilter, nameFilter)
} else { } else {
it.getDeclaredDescriptors() it.getDeclaredDescriptors()
@@ -93,13 +93,13 @@ public fun LexicalScope.getLocalVariable(name: Name): VariableDescriptor? {
if (it is LexicalScopeWrapper) { if (it is LexicalScopeWrapper) {
return it.delegate.getLocalVariable(name) return it.delegate.getLocalVariable(name)
} }
else if (it is LazyFileScope) { else if (it is LazyImportingScope) {
return it.getLocalVariable(name) // todo: remove hack for repl interpreter return it.getLocalVariable(name) // todo: remove hack for repl interpreter
} }
else if (it is MemberScopeToFileScopeAdapter) { // todo remove hack else if (it is MemberScopeToImportingScopeAdapter) { // todo remove hack
return it.memberScope.getLocalVariable(name) return it.memberScope.getLocalVariable(name)
} }
else if (it !is FileScope && it !is LexicalChainedScope) { // todo check this else if (it !is ImportingScope && it !is LexicalChainedScope) { // todo check this
it.getDeclaredVariables(name, NoLookupLocation.UNSORTED).singleOrNull()?.let { return it } it.getDeclaredVariables(name, NoLookupLocation.UNSORTED).singleOrNull()?.let { return it }
} }
} }
@@ -117,11 +117,11 @@ public fun LexicalScope.takeSnapshot(): LexicalScope = if (this is LexicalWritab
public fun LexicalScope.asJetScope(): KtScope { public fun LexicalScope.asJetScope(): KtScope {
if (this is KtScope) return this if (this is KtScope) return this
if (this is MemberScopeToFileScopeAdapter) return this.memberScope if (this is MemberScopeToImportingScopeAdapter) return this.memberScope
return LexicalToJetScopeAdapter(this) return LexicalToJetScopeAdapter(this)
} }
public fun KtScope.memberScopeAsFileScope(): FileScope = MemberScopeToFileScopeAdapter(this) public fun KtScope.memberScopeAsFileScope(): ImportingScope = MemberScopeToImportingScopeAdapter(this)
@Deprecated("Remove this method after scope refactoring") @Deprecated("Remove this method after scope refactoring")
public fun KtScope.asLexicalScope(): LexicalScope public fun KtScope.asLexicalScope(): LexicalScope
@@ -141,7 +141,7 @@ private class LexicalToJetScopeAdapter(lexicalScope: LexicalScope): KtScope {
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> { override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
val fileScope = lexicalScope.getFileScope() val fileScope = lexicalScope.getFileScope()
if (fileScope is MemberScopeToFileScopeAdapter) { if (fileScope is MemberScopeToImportingScopeAdapter) {
return fileScope.memberScope.getProperties(name, location) return fileScope.memberScope.getProperties(name, location)
} }
else { else {
@@ -172,7 +172,7 @@ private class LexicalToJetScopeAdapter(lexicalScope: LexicalScope): KtScope {
override fun getDeclarationsByLabel(labelName: Name) = lexicalScope.getDeclarationsByLabel(labelName) override fun getDeclarationsByLabel(labelName: Name) = lexicalScope.getDeclarationsByLabel(labelName)
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = lexicalScope.collectAllFromMeAndParent { override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = lexicalScope.collectAllFromMeAndParent {
if (it is FileScope) { if (it is ImportingScope) {
it.getDescriptors(kindFilter, nameFilter) it.getDescriptors(kindFilter, nameFilter)
} else it.getDeclaredDescriptors() } else it.getDeclaredDescriptors()
} }
@@ -197,7 +197,10 @@ private class LexicalToJetScopeAdapter(lexicalScope: LexicalScope): KtScope {
} }
} }
private class MemberScopeToFileScopeAdapter(val memberScope: KtScope) : FileScope { private class MemberScopeToImportingScopeAdapter(val memberScope: KtScope) : ImportingScope {
override val parent: ImportingScope?
get() = null
override fun getPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name) override fun getPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation) override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
@@ -226,7 +229,7 @@ private class MemberScopeToFileScopeAdapter(val memberScope: KtScope) : FileScop
override fun getDeclaredFunctions(name: Name, location: LookupLocation) = memberScope.getFunctions(name, location) override fun getDeclaredFunctions(name: Name, location: LookupLocation) = memberScope.getFunctions(name, location)
override fun equals(other: Any?) = other is MemberScopeToFileScopeAdapter && other.memberScope == memberScope override fun equals(other: Any?) = other is MemberScopeToImportingScopeAdapter && other.memberScope == memberScope
override fun hashCode() = memberScope.hashCode() override fun hashCode() = memberScope.hashCode()
@@ -285,19 +288,19 @@ public fun LexicalScope.addImportScope(importScope: KtScope): LexicalScope {
} }
public fun LexicalScope.replaceFileScope(fileScopeReplace: LexicalScope): LexicalScope { public fun LexicalScope.replaceFileScope(fileScopeReplace: LexicalScope): LexicalScope {
if (this is FileScope) return fileScopeReplace if (this is ImportingScope) return fileScopeReplace
return LexicalScopeWrapper(this, fileScopeReplace) return LexicalScopeWrapper(this, fileScopeReplace)
} }
public fun LexicalScope.withNoFileScope(): LexicalScope = replaceFileScope(MemberScopeToFileScopeAdapter(KtScope.Empty)) public fun LexicalScope.withNoFileScope(): LexicalScope = replaceFileScope(MemberScopeToImportingScopeAdapter(KtScope.Empty))
private class LexicalScopeWrapper(val delegate: LexicalScope, val fileScopeReplace: LexicalScope): LexicalScope by delegate { private class LexicalScopeWrapper(val delegate: LexicalScope, val fileScopeReplace: LexicalScope): LexicalScope by delegate {
override val parent: LexicalScope? by lazy(LazyThreadSafetyMode.NONE) { override val parent: LexicalScope? by lazy(LazyThreadSafetyMode.NONE) {
assert(delegate !is FileScope) { "We should replace FileScope($delegate) to $fileScopeReplace" } assert(delegate !is ImportingScope) { "We should replace FileScope($delegate) to $fileScopeReplace" }
val parent = delegate.parent!! val parent = delegate.parent!!
if (parent is FileScope) { if (parent is ImportingScope) {
fileScopeReplace fileScopeReplace
} }
else { else {
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.FunctionDescriptorResolver;
import org.jetbrains.kotlin.resolve.OverloadUtil; import org.jetbrains.kotlin.resolve.OverloadUtil;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform; import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
import org.jetbrains.kotlin.resolve.scopes.FileScope; import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt; import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
import org.jetbrains.kotlin.test.ConfigurationKind; import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetLiteFixture; import org.jetbrains.kotlin.test.JetLiteFixture;
@@ -171,7 +171,7 @@ public class JetOverloadTest extends JetLiteFixture {
private FunctionDescriptor makeFunction(String funDecl) { private FunctionDescriptor makeFunction(String funDecl) {
KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl); KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
FileScope scope = ScopeUtilsKt.memberScopeAsFileScope(JvmPlatform.INSTANCE$.getBuiltIns().getBuiltInsPackageScope()); ImportingScope scope = ScopeUtilsKt.memberScopeAsFileScope(JvmPlatform.INSTANCE$.getBuiltIns().getBuiltInsPackageScope());
return functionDescriptorResolver.resolveFunctionDescriptor(root, scope, function, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY); return functionDescriptorResolver.resolveFunctionDescriptor(root, scope, function, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
} }
} }
@@ -18,35 +18,47 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
// see ScopeUtils.kt in the frontend module // see ScopeUtils.kt in the frontend module
public interface LexicalScope { interface LexicalScope {
public val parent: LexicalScope? val parent: LexicalScope?
public val ownerDescriptor: DeclarationDescriptor val ownerDescriptor: DeclarationDescriptor
public val isOwnerDescriptorAccessibleByLabel: Boolean val isOwnerDescriptorAccessibleByLabel: Boolean
public val implicitReceiver: ReceiverParameterDescriptor? val implicitReceiver: ReceiverParameterDescriptor?
public fun getDeclaredDescriptors(): Collection<DeclarationDescriptor> /**
* All visible descriptors from current scope possibly filtered by the given name and kind filters
* (that means that the implementation is not obliged to use the filters but may do so when it gives any performance advantage).
*/
open fun getDescriptors(
kindFilter: DescriptorKindFilter = DescriptorKindFilter.ALL,
nameFilter: (Name) -> Boolean = KtScope.ALL_NAME_FILTER
): Collection<DeclarationDescriptor> = getDeclaredDescriptors()
public fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? //TODO: rename to getDescriptors or getAllDescriptors
fun getDeclaredDescriptors(): Collection<DeclarationDescriptor>
// need collection here because there may be extension property foo and usual property foo //TODO: rename to getClassifier
public fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
public fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
public fun printStructure(p: Printer) //TODO: rename to getVariables
fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor>
//TODO: rename to getFunctions
fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
fun printStructure(p: Printer)
} }
public interface FileScope: LexicalScope { // TODO: common base interface instead direct inheritance
override val parent: LexicalScope? interface ImportingScope : LexicalScope {
get() = null override val parent: ImportingScope?
override val isOwnerDescriptorAccessibleByLabel: Boolean override val isOwnerDescriptorAccessibleByLabel: Boolean
get() = false get() = false
@@ -58,14 +70,16 @@ public interface FileScope: LexicalScope {
fun getPackage(name: Name): PackageViewDescriptor? fun getPackage(name: Name): PackageViewDescriptor?
public fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor>
public fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor>
public fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor>
public fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor>
public fun getDescriptors( // please, do not override this method
kindFilter: DescriptorKindFilter = DescriptorKindFilter.ALL, override fun getDeclaredDescriptors(): Collection<DeclarationDescriptor> {
nameFilter: (Name) -> Boolean = KtScope.ALL_NAME_FILTER return getDescriptors()
): Collection<DeclarationDescriptor> }
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor>
} }
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
import org.jetbrains.kotlin.resolve.lazy.LazyFileScope import org.jetbrains.kotlin.resolve.lazy.LazyImportingScope
public fun KtElement.getResolutionFacade(): ResolutionFacade { public fun KtElement.getResolutionFacade(): ResolutionFacade {
return KotlinCacheService.getInstance(getProject()).getResolutionFacade(listOf(this)) return KotlinCacheService.getInstance(getProject()).getResolutionFacade(listOf(this))
@@ -102,6 +102,6 @@ public fun getResolveScope(file: KtFile): GlobalSearchScope {
} }
} }
public fun ResolutionFacade.getFileTopLevelScope(file: KtFile): LazyFileScope { public fun ResolutionFacade.getFileTopLevelScope(file: KtFile): LazyImportingScope {
return frontendService<FileScopeProvider>().getFileScope(file) return frontendService<FileScopeProvider>().getFileScope(file)
} }
@@ -49,7 +49,7 @@ import org.jetbrains.kotlin.renderer.render
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
import org.jetbrains.kotlin.resolve.scopes.FileScope import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
@@ -86,9 +86,9 @@ public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection()
} }
} }
private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, fileScope: FileScope): SyntheticJavaPropertyDescriptor? { private fun conflictingSyntheticExtension(descriptor: PropertyDescriptor, importingScope: ImportingScope): SyntheticJavaPropertyDescriptor? {
val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return null
return fileScope return importingScope
.getSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE) .getSyntheticExtensionProperties(listOf(extensionReceiverType), descriptor.name, NoLookupLocation.FROM_IDE)
.firstIsInstanceOrNull() .firstIsInstanceOrNull()
} }