[Analysis API] fix getScopeContextForFile and clarify its semantic
It was used to get importing scope, so it was renamed to getImportingScopeContext. It was broken after changing the behaviour of `LowLevelFirApiFacadeForResolveOnAir.onAirGetTowerContextProvider` for the whole file ^KT-57966
This commit is contained in:
committed by
Space Team
parent
254092a267
commit
20f921c0bf
+7
@@ -210,6 +210,13 @@ internal class KtFe10ScopeProvider(
|
||||
return KtScopeContext(listOf(KtScopeWithKind(compositeScope, scopeKind, token)), collectImplicitReceivers(fileScope), token)
|
||||
}
|
||||
|
||||
override fun getImportingScopeContext(file: KtFile): KtScopeContext {
|
||||
val importingScopes = getScopeContextForPosition(originalFile = file, positionInFakeFile = file)
|
||||
.scopes
|
||||
.filter { it.kind is KtScopeKind.ImportingScope }
|
||||
return KtScopeContext(importingScopes, _implicitReceivers = emptyList(), token)
|
||||
}
|
||||
|
||||
private inline fun <reified T : DeclarationDescriptor> getDescriptor(symbol: KtSymbol): T? {
|
||||
return when (symbol) {
|
||||
is KtFe10DescSymbol<*> -> symbol.descriptor as? T
|
||||
|
||||
+17
-4
@@ -17,12 +17,10 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossiblyNamedSymbol
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.ResolutionScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
|
||||
internal abstract class KtFe10ScopeResolution : KtScope, KtLifetimeOwner {
|
||||
abstract val analysisContext: Fe10AnalysisContext
|
||||
@@ -90,4 +88,19 @@ internal open class KtFe10ScopeMember(
|
||||
override fun getConstructors(): Sequence<KtConstructorSymbol> = sequence {
|
||||
constructors.forEach { yield(it.toKtConstructorSymbol(analysisContext)) }
|
||||
}
|
||||
}
|
||||
|
||||
internal class KtFe10ScopeImporting(
|
||||
override val scope: ImportingScope,
|
||||
override val analysisContext: Fe10AnalysisContext
|
||||
) : KtFe10ScopeResolution() {
|
||||
override fun getPossibleCallableNames(): Set<Name> = withValidityAssertion {
|
||||
return getCallableSymbols().mapNotNullTo(mutableSetOf()) { (it as? KtPossiblyNamedSymbol)?.name }
|
||||
}
|
||||
|
||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||
return getClassifierSymbols().mapNotNullTo(mutableSetOf()) { (it as? KtPossiblyNamedSymbol)?.name }
|
||||
}
|
||||
|
||||
override fun getConstructors(): Sequence<KtConstructorSymbol> = withValidityAssertion { emptySequence() }
|
||||
}
|
||||
+15
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithDeclaration
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirFile
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.unexpectedElementError
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.getElementTextInContext
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -170,6 +171,20 @@ internal class KtFirScopeProvider(
|
||||
)?.let { convertToKtTypeScope(it) }
|
||||
}
|
||||
|
||||
override fun getImportingScopeContext(file: KtFile): KtScopeContext {
|
||||
val firFile = file.getOrBuildFirFile(firResolveSession)
|
||||
val firFileSession = firFile.moduleData.session
|
||||
val firImportingScopes = createImportingScopes(
|
||||
firFile,
|
||||
firFileSession,
|
||||
analysisSession.getScopeSessionFor(firFileSession),
|
||||
useCaching = true,
|
||||
)
|
||||
|
||||
val ktScopesWithKinds = createScopesWithKind(firImportingScopes.withIndex())
|
||||
return KtScopeContext(ktScopesWithKinds, _implicitReceivers = emptyList(), token)
|
||||
}
|
||||
|
||||
override fun getScopeContextForPosition(
|
||||
originalFile: KtFile,
|
||||
positionInFakeFile: KtElement
|
||||
|
||||
+9
-2
@@ -40,6 +40,8 @@ public abstract class KtScopeProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public abstract fun getSyntheticJavaPropertiesScope(type: KtType): KtTypeScope?
|
||||
|
||||
public abstract fun getImportingScopeContext(file: KtFile): KtScopeContext
|
||||
|
||||
public abstract fun getScopeContextForPosition(
|
||||
originalFile: KtFile,
|
||||
positionInFakeFile: KtElement
|
||||
@@ -112,8 +114,13 @@ public interface KtScopeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtFile.getScopeContextForPosition(positionInFakeFile: KtElement): KtScopeContext =
|
||||
withValidityAssertion { analysisSession.scopeProvider.getScopeContextForPosition(this, positionInFakeFile) }
|
||||
|
||||
public fun KtFile.getScopeContextForFile(): KtScopeContext =
|
||||
withValidityAssertion { analysisSession.scopeProvider.getScopeContextForPosition(this, this) }
|
||||
/**
|
||||
* Returns a [KtScopeContext] formed by all imports in the [KtFile].
|
||||
*
|
||||
* By default, this will also include default importing scopes, which can be filtered by [KtScopeKind]
|
||||
*/
|
||||
public fun KtFile.getImportingScopeContext(): KtScopeContext =
|
||||
withValidityAssertion { analysisSession.scopeProvider.getImportingScopeContext(this) }
|
||||
|
||||
/**
|
||||
* Returns single scope, containing declarations from all scopes that satisfy [filter]. The order of declarations corresponds to the
|
||||
|
||||
Reference in New Issue
Block a user