Analysis API: get rid of KtImportingScope as public API
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal sealed class Import {
|
||||
abstract val packageFqName: FqName
|
||||
abstract val relativeClassName: FqName?
|
||||
abstract val resolvedClassId: ClassId?
|
||||
}
|
||||
|
||||
internal class NonStarImport(
|
||||
override val packageFqName: FqName,
|
||||
override val relativeClassName: FqName?,
|
||||
override val resolvedClassId: ClassId?,
|
||||
val callableName: Name?,
|
||||
) : Import()
|
||||
|
||||
internal class StarImport(
|
||||
override val packageFqName: FqName,
|
||||
override val relativeClassName: FqName?,
|
||||
override val resolvedClassId: ClassId?,
|
||||
) : Import()
|
||||
+8
-8
@@ -7,12 +7,12 @@ 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.scopes.KtNonStarImportingScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.NonStarImport
|
||||
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.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
@@ -25,10 +25,8 @@ internal class KtFirNonStarImportingScope(
|
||||
private val firScope: FirAbstractSimpleImportingScope,
|
||||
private val builder: KtSymbolByFirBuilder,
|
||||
override val token: ValidityToken,
|
||||
) : KtNonStarImportingScope {
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override val imports: List<NonStarImport> by cached {
|
||||
) : KtScope {
|
||||
private val imports: List<NonStarImport> by cached {
|
||||
buildList {
|
||||
firScope.simpleImports.values.forEach { imports ->
|
||||
imports.forEach { import ->
|
||||
@@ -56,6 +54,10 @@ internal class KtFirNonStarImportingScope(
|
||||
firScope.getClassifierSymbols(getPossibleClassifierNames().filter(nameFilter), builder)
|
||||
}
|
||||
|
||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||
emptySequence()
|
||||
}
|
||||
|
||||
override fun getConstructors(): Sequence<KtConstructorSymbol> = emptySequence()
|
||||
|
||||
override fun getPossibleCallableNames(): Set<Name> = withValidityAssertion {
|
||||
@@ -65,6 +67,4 @@ internal class KtFirNonStarImportingScope(
|
||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||
imports.mapNotNullTo((hashSetOf())) { it.relativeClassName?.shortName() }
|
||||
}
|
||||
|
||||
override val isDefaultImportingScope: Boolean = withValidityAssertion { firScope is FirDefaultSimpleImportingScope }
|
||||
}
|
||||
|
||||
+10
-9
@@ -7,21 +7,18 @@ package org.jetbrains.kotlin.analysis.api.fir.scopes
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.Import
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtStarImportingScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.StarImport
|
||||
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.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.providers.createDeclarationProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractStarImportingScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirDefaultStarImportingScope
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class KtFirStarImportingScope(
|
||||
@@ -29,13 +26,11 @@ internal class KtFirStarImportingScope(
|
||||
private val builder: KtSymbolByFirBuilder,
|
||||
project: Project,
|
||||
override val token: ValidityToken,
|
||||
) : KtStarImportingScope, ValidityTokenOwner {
|
||||
override val isDefaultImportingScope: Boolean = withValidityAssertion { firScope is FirDefaultStarImportingScope }
|
||||
|
||||
) : KtScope {
|
||||
//todo use more concrete scope
|
||||
private val declarationProvider = project.createDeclarationProvider(GlobalSearchScope.allScope(project))
|
||||
|
||||
override val imports: List<StarImport> by cached {
|
||||
private val imports: List<StarImport> by cached {
|
||||
firScope.starImports.map { import ->
|
||||
StarImport(
|
||||
import.packageFqName,
|
||||
@@ -69,6 +64,12 @@ internal class KtFirStarImportingScope(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||
emptySequence()
|
||||
}
|
||||
|
||||
|
||||
override fun getPossibleClassifierNames(): Set<Name> = withValidityAssertion {
|
||||
imports.flatMapTo(hashSetOf()) { import ->
|
||||
if (import.relativeClassName == null) {
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.scopes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public interface KtImportingScope : KtScope {
|
||||
public val imports: List<Import>
|
||||
public val isDefaultImportingScope: Boolean
|
||||
|
||||
override fun getPackageSymbols(nameFilter: KtScopeNameFilter): Sequence<KtPackageSymbol> = withValidityAssertion {
|
||||
emptySequence()
|
||||
}
|
||||
}
|
||||
|
||||
public interface KtStarImportingScope : KtImportingScope {
|
||||
override val imports: List<StarImport>
|
||||
}
|
||||
|
||||
public interface KtNonStarImportingScope : KtImportingScope {
|
||||
override val imports: List<NonStarImport>
|
||||
}
|
||||
|
||||
public sealed class Import {
|
||||
public abstract val packageFqName: FqName
|
||||
public abstract val relativeClassName: FqName?
|
||||
public abstract val resolvedClassId: ClassId?
|
||||
}
|
||||
|
||||
public class NonStarImport(
|
||||
public override val packageFqName: FqName,
|
||||
override val relativeClassName: FqName?,
|
||||
override val resolvedClassId: ClassId?,
|
||||
public val callableName: Name?,
|
||||
) : Import()
|
||||
|
||||
public class StarImport(
|
||||
override val packageFqName: FqName,
|
||||
override val relativeClassName: FqName?,
|
||||
override val resolvedClassId: ClassId?,
|
||||
) : Import()
|
||||
Reference in New Issue
Block a user