[Analysis API] refactoring, simplify constructor KtFirStarImportingScope
This commit is contained in:
committed by
Space Team
parent
50c49838ba
commit
546191d1b3
+1
-1
@@ -231,7 +231,7 @@ internal class KtFirScopeProvider(
|
|||||||
private fun convertToKtScope(firScope: FirScope): KtScope {
|
private fun convertToKtScope(firScope: FirScope): KtScope {
|
||||||
return when (firScope) {
|
return when (firScope) {
|
||||||
is FirAbstractSimpleImportingScope -> KtFirNonStarImportingScope(firScope, builder)
|
is FirAbstractSimpleImportingScope -> KtFirNonStarImportingScope(firScope, builder)
|
||||||
is FirAbstractStarImportingScope -> KtFirStarImportingScope(firScope, builder, analysisSession.useSiteScopeDeclarationProvider)
|
is FirAbstractStarImportingScope -> KtFirStarImportingScope(firScope, analysisSession)
|
||||||
is FirPackageMemberScope -> createPackageScope(firScope.fqName)
|
is FirPackageMemberScope -> createPackageScope(firScope.fqName)
|
||||||
is FirContainingNamesAwareScope -> KtFirDelegatingNamesAwareScope(firScope, builder)
|
is FirContainingNamesAwareScope -> KtFirDelegatingNamesAwareScope(firScope, builder)
|
||||||
else -> TODO(firScope::class.toString())
|
else -> TODO(firScope::class.toString())
|
||||||
|
|||||||
+5
-7
@@ -5,21 +5,19 @@
|
|||||||
|
|
||||||
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.KtFirAnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
||||||
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.analysis.providers.KotlinDeclarationProvider
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractStarImportingScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractStarImportingScope
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
internal class KtFirStarImportingScope(
|
internal class KtFirStarImportingScope(
|
||||||
firScope: FirAbstractStarImportingScope,
|
firScope: FirAbstractStarImportingScope,
|
||||||
builder: KtSymbolByFirBuilder,
|
private val analysisSession: KtFirAnalysisSession,
|
||||||
private val declarationProvider: KotlinDeclarationProvider,
|
) : KtFirBasedScope<FirAbstractStarImportingScope>(firScope, analysisSession.firSymbolBuilder) {
|
||||||
) : KtFirBasedScope<FirAbstractStarImportingScope>(firScope, builder) {
|
|
||||||
|
|
||||||
private val imports: List<StarImport> by cached {
|
private val imports: List<StarImport> by cached {
|
||||||
firScope.starImports.map { import ->
|
firScope.starImports.map { import ->
|
||||||
@@ -37,7 +35,7 @@ internal class KtFirStarImportingScope(
|
|||||||
override fun getPossibleCallableNames(): Set<Name> = withValidityAssertion {
|
override fun getPossibleCallableNames(): Set<Name> = withValidityAssertion {
|
||||||
imports.flatMapTo(hashSetOf()) { import: Import ->
|
imports.flatMapTo(hashSetOf()) { import: Import ->
|
||||||
if (import.relativeClassName == null) { // top level callable
|
if (import.relativeClassName == null) { // top level callable
|
||||||
declarationProvider.getTopLevelCallableNamesInPackage(import.packageFqName)
|
analysisSession.useSiteScopeDeclarationProvider.getTopLevelCallableNamesInPackage(import.packageFqName)
|
||||||
} else { //member
|
} else { //member
|
||||||
val classId = import.resolvedClassId ?: error("Class id should not be null as relativeClassName is not null")
|
val classId = import.resolvedClassId ?: error("Class id should not be null as relativeClassName is not null")
|
||||||
firScope.getStaticsScope(classId)?.getCallableNames().orEmpty()
|
firScope.getStaticsScope(classId)?.getCallableNames().orEmpty()
|
||||||
@@ -52,7 +50,7 @@ internal class KtFirStarImportingScope(
|
|||||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||||
imports.flatMapTo(hashSetOf()) { import ->
|
imports.flatMapTo(hashSetOf()) { import ->
|
||||||
if (import.relativeClassName == null) {
|
if (import.relativeClassName == null) {
|
||||||
declarationProvider.getTopLevelKotlinClassLikeDeclarationNamesInPackage(import.packageFqName)
|
analysisSession.useSiteScopeDeclarationProvider.getTopLevelKotlinClassLikeDeclarationNamesInPackage(import.packageFqName)
|
||||||
} else {
|
} else {
|
||||||
val classId = import.resolvedClassId ?: error("Class id should not be null as relativeClassName is not null")
|
val classId = import.resolvedClassId ?: error("Class id should not be null as relativeClassName is not null")
|
||||||
firScope.getStaticsScope(classId)?.getClassifierNames().orEmpty()
|
firScope.getStaticsScope(classId)?.getClassifierNames().orEmpty()
|
||||||
|
|||||||
Reference in New Issue
Block a user