[Analysis API FIR] refactoring, extract base part of KtFirDelegatingScope into a separate class
For further reuse
This commit is contained in:
committed by
Space Team
parent
41976a2932
commit
55bbc5eb02
+6
-6
@@ -88,7 +88,7 @@ internal class KtFirScopeProvider(
|
|||||||
)
|
)
|
||||||
}?.applyIf(classSymbol is KtEnumEntrySymbol, ::EnumEntryContainingNamesAwareScope)
|
}?.applyIf(classSymbol is KtEnumEntrySymbol, ::EnumEntryContainingNamesAwareScope)
|
||||||
?: return getEmptyScope()
|
?: return getEmptyScope()
|
||||||
return KtFirDelegatingScope(firScope, builder)
|
return KtFirDelegatingNamesAwareScope(firScope, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getStaticMemberScope(symbol: KtSymbolWithMembers): KtScope {
|
override fun getStaticMemberScope(symbol: KtSymbolWithMembers): KtScope {
|
||||||
@@ -100,13 +100,13 @@ internal class KtFirScopeProvider(
|
|||||||
getScopeSession(),
|
getScopeSession(),
|
||||||
)
|
)
|
||||||
} ?: return getEmptyScope()
|
} ?: return getEmptyScope()
|
||||||
return KtFirDelegatingScope(firScope, builder)
|
return KtFirDelegatingNamesAwareScope(firScope, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDeclaredMemberScope(classSymbol: KtSymbolWithMembers): KtScope {
|
override fun getDeclaredMemberScope(classSymbol: KtSymbolWithMembers): KtScope {
|
||||||
val useSiteSession = analysisSession.useSiteSession
|
val useSiteSession = analysisSession.useSiteSession
|
||||||
if (classSymbol is KtFirScriptSymbol) {
|
if (classSymbol is KtFirScriptSymbol) {
|
||||||
return KtFirDelegatingScope(
|
return KtFirDelegatingNamesAwareScope(
|
||||||
FirScriptDeclarationsScope(useSiteSession, classSymbol.firSymbol.fir),
|
FirScriptDeclarationsScope(useSiteSession, classSymbol.firSymbol.fir),
|
||||||
builder
|
builder
|
||||||
)
|
)
|
||||||
@@ -117,11 +117,11 @@ internal class KtFirScopeProvider(
|
|||||||
else -> useSiteSession.declaredMemberScope(it)
|
else -> useSiteSession.declaredMemberScope(it)
|
||||||
}
|
}
|
||||||
} ?: return getEmptyScope()
|
} ?: return getEmptyScope()
|
||||||
return KtFirDelegatingScope(firScope, builder)
|
return KtFirDelegatingNamesAwareScope(firScope, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDelegatedMemberScope(classSymbol: KtSymbolWithMembers): KtScope {
|
override fun getDelegatedMemberScope(classSymbol: KtSymbolWithMembers): KtScope {
|
||||||
val declaredScope = (getDeclaredMemberScope(classSymbol) as? KtFirDelegatingScope)?.firScope
|
val declaredScope = (getDeclaredMemberScope(classSymbol) as? KtFirDelegatingNamesAwareScope)?.firScope
|
||||||
?: return getEmptyScope()
|
?: return getEmptyScope()
|
||||||
val firScope = classSymbol.withFirForScope { fir ->
|
val firScope = classSymbol.withFirForScope { fir ->
|
||||||
fir.lazyResolveToPhase(FirResolvePhase.STATUS)
|
fir.lazyResolveToPhase(FirResolvePhase.STATUS)
|
||||||
@@ -233,7 +233,7 @@ internal class KtFirScopeProvider(
|
|||||||
is FirAbstractSimpleImportingScope -> KtFirNonStarImportingScope(firScope, builder)
|
is FirAbstractSimpleImportingScope -> KtFirNonStarImportingScope(firScope, builder)
|
||||||
is FirAbstractStarImportingScope -> KtFirStarImportingScope(firScope, builder, analysisSession.useSiteScopeDeclarationProvider)
|
is FirAbstractStarImportingScope -> KtFirStarImportingScope(firScope, builder, analysisSession.useSiteScopeDeclarationProvider)
|
||||||
is FirPackageMemberScope -> createPackageScope(firScope.fqName)
|
is FirPackageMemberScope -> createPackageScope(firScope.fqName)
|
||||||
is FirContainingNamesAwareScope -> KtFirDelegatingScope(firScope, builder)
|
is FirContainingNamesAwareScope -> KtFirDelegatingNamesAwareScope(firScope, builder)
|
||||||
else -> TODO(firScope::class.toString())
|
else -> TODO(firScope::class.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.analysis.api.fir.components
|
|||||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
|
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
|
||||||
import org.jetbrains.kotlin.analysis.api.components.KtScopeSubstitution
|
import org.jetbrains.kotlin.analysis.api.components.KtScopeSubstitution
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.scopes.KtFirDelegatingScope
|
import org.jetbrains.kotlin.analysis.api.fir.scopes.KtFirDelegatingNamesAwareScope
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.scopes.KtFirDelegatingTypeScope
|
import org.jetbrains.kotlin.analysis.api.fir.scopes.KtFirDelegatingTypeScope
|
||||||
import org.jetbrains.kotlin.analysis.api.impl.base.scopes.KtCompositeScope
|
import org.jetbrains.kotlin.analysis.api.impl.base.scopes.KtCompositeScope
|
||||||
import org.jetbrains.kotlin.analysis.api.impl.base.scopes.KtCompositeTypeScope
|
import org.jetbrains.kotlin.analysis.api.impl.base.scopes.KtCompositeTypeScope
|
||||||
@@ -23,7 +23,7 @@ internal class KtFirScopeSubstitution(
|
|||||||
@OptIn(KtAnalysisApiInternals::class)
|
@OptIn(KtAnalysisApiInternals::class)
|
||||||
override fun getDeclarationScope(scope: KtTypeScope): KtScope {
|
override fun getDeclarationScope(scope: KtTypeScope): KtScope {
|
||||||
return when (scope) {
|
return when (scope) {
|
||||||
is KtFirDelegatingTypeScope -> KtFirDelegatingScope(scope.firScope, analysisSession.firSymbolBuilder)
|
is KtFirDelegatingTypeScope -> KtFirDelegatingNamesAwareScope(scope.firScope, analysisSession.firSymbolBuilder)
|
||||||
is KtCompositeTypeScope -> KtCompositeScope(scope.subScopes.map(::getDeclarationScope), token)
|
is KtCompositeTypeScope -> KtCompositeScope(scope.subScopes.map(::getDeclarationScope), token)
|
||||||
else -> unexpectedElementError<KtTypeScope>(scope)
|
else -> unexpectedElementError<KtTypeScope>(scope)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-25
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.analysis.api.fir.scopes
|
package org.jetbrains.kotlin.analysis.api.fir.scopes
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||||
@@ -15,28 +14,14 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
|||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
internal open class KtFirDelegatingScope(
|
internal abstract class KtFirBasedScope<S : FirScope>(
|
||||||
val firScope: FirContainingNamesAwareScope,
|
protected val firScope: S,
|
||||||
private val builder: KtSymbolByFirBuilder,
|
protected val builder: KtSymbolByFirBuilder,
|
||||||
) : KtScope {
|
) : KtScope {
|
||||||
override val token: KtLifetimeToken get() = builder.token
|
final override val token: KtLifetimeToken get() = builder.token
|
||||||
|
|
||||||
private val allNamesCached by cached {
|
|
||||||
getPossibleCallableNames() + getPossibleClassifierNames()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAllPossibleNames(): Set<Name> = withValidityAssertion { allNamesCached }
|
|
||||||
|
|
||||||
override fun getPossibleCallableNames(): Set<Name> = withValidityAssertion {
|
|
||||||
firScope.getCallableNames()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
|
||||||
firScope.getClassifierNames()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
|
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||||
firScope.getCallableSymbols(getPossibleCallableNames().filter(nameFilter), builder)
|
firScope.getCallableSymbols(getPossibleCallableNames().filter(nameFilter), builder)
|
||||||
@@ -61,10 +46,5 @@ internal open class KtFirDelegatingScope(
|
|||||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||||
emptySequence()
|
emptySequence()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mayContainName(name: Name): Boolean = withValidityAssertion {
|
|
||||||
name in getAllPossibleNames()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
-1
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
internal class KtFirDelegatedMemberScope(
|
internal class KtFirDelegatedMemberScope(
|
||||||
firScope: FirContainingNamesAwareScope,
|
firScope: FirContainingNamesAwareScope,
|
||||||
builder: KtSymbolByFirBuilder
|
builder: KtSymbolByFirBuilder
|
||||||
) : KtFirDelegatingScope(firScope, builder) {
|
) : KtFirDelegatingNamesAwareScope(firScope, builder) {
|
||||||
|
|
||||||
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
|
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||||
return super.getCallableSymbols(nameFilter).filter { it.origin == KtSymbolOrigin.DELEGATED }
|
return super.getCallableSymbols(nameFilter).filter { it.origin == KtSymbolOrigin.DELEGATED }
|
||||||
|
|||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.api.fir.scopes
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||||
|
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||||
|
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
|
internal open class KtFirDelegatingNamesAwareScope(
|
||||||
|
firScope: FirContainingNamesAwareScope,
|
||||||
|
builder: KtSymbolByFirBuilder,
|
||||||
|
) : KtFirBasedScope<FirContainingNamesAwareScope>(firScope, builder) {
|
||||||
|
private val allNamesCached by cached {
|
||||||
|
getPossibleCallableNames() + getPossibleClassifierNames()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllPossibleNames(): Set<Name> = withValidityAssertion { allNamesCached }
|
||||||
|
|
||||||
|
override fun getPossibleCallableNames(): Set<Name> = withValidityAssertion {
|
||||||
|
firScope.getCallableNames()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||||
|
firScope.getClassifierNames()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mayContainName(name: Name): Boolean = withValidityAssertion {
|
||||||
|
name in getAllPossibleNames()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user