[FIR IDE] Add KtFileScope to support KtFileSymbol
This commit is contained in:
+5
-2
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.idea.frontend.api.components.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
@@ -82,9 +83,11 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
|
||||
|
||||
fun KtSymbolWithKind.getContainingSymbol(): KtSymbolWithKind? = containingDeclarationProvider.getContainingDeclaration(this)
|
||||
|
||||
fun KtSymbolWithDeclarations.getMemberScope(): KtMemberScope = scopeProvider.getMemberScope(this)
|
||||
fun KtSymbolWithMembers.getMemberScope(): KtMemberScope = scopeProvider.getMemberScope(this)
|
||||
|
||||
fun KtSymbolWithDeclarations.getDeclaredMemberScope(): KtDeclaredMemberScope = scopeProvider.getDeclaredMemberScope(this)
|
||||
fun KtSymbolWithMembers.getDeclaredMemberScope(): KtDeclaredMemberScope = scopeProvider.getDeclaredMemberScope(this)
|
||||
|
||||
fun KtFileSymbol.getFileScope(): KtDeclarationScope<KtSymbolWithDeclarations> = scopeProvider.getFileScope(this)
|
||||
|
||||
fun KtPackageSymbol.getPackageScope(): KtPackageScope = scopeProvider.getPackageScope(this)
|
||||
|
||||
|
||||
+5
-2
@@ -6,15 +6,18 @@
|
||||
package org.jetbrains.kotlin.idea.frontend.api.components
|
||||
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFileSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
abstract class KtScopeProvider : KtAnalysisSessionComponent() {
|
||||
abstract fun getMemberScope(classSymbol: KtSymbolWithDeclarations): KtMemberScope
|
||||
abstract fun getDeclaredMemberScope(classSymbol: KtSymbolWithDeclarations): KtDeclaredMemberScope
|
||||
abstract fun getMemberScope(classSymbol: KtSymbolWithMembers): KtMemberScope
|
||||
abstract fun getDeclaredMemberScope(classSymbol: KtSymbolWithMembers): KtDeclaredMemberScope
|
||||
abstract fun getFileScope(fileSymbol: KtFileSymbol): KtDeclarationScope<KtSymbolWithDeclarations>
|
||||
abstract fun getPackageScope(packageSymbol: KtPackageSymbol): KtPackageScope
|
||||
abstract fun getCompositeScope(subScopes: List<KtScope>): KtCompositeScope
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.frontend.api.scopes
|
||||
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -43,12 +43,16 @@ interface KtCompositeScope : KtScope {
|
||||
val subScopes: List<KtScope>
|
||||
}
|
||||
|
||||
interface KtMemberScope : KtScope {
|
||||
val owner: KtSymbolWithDeclarations
|
||||
interface KtMemberScope : KtDeclarationScope<KtSymbolWithMembers> {
|
||||
override val owner: KtSymbolWithMembers
|
||||
}
|
||||
|
||||
interface KtDeclaredMemberScope : KtScope {
|
||||
val owner: KtSymbolWithDeclarations
|
||||
interface KtDeclaredMemberScope : KtDeclarationScope<KtSymbolWithMembers> {
|
||||
override val owner: KtSymbolWithMembers
|
||||
}
|
||||
|
||||
interface KtDeclarationScope<out T : KtSymbolWithDeclarations> : KtScope {
|
||||
val owner: T
|
||||
}
|
||||
|
||||
interface KtPackageScope : KtScope, KtSubstitutedScope<KtPackageScope> {
|
||||
|
||||
+2
-2
@@ -6,12 +6,12 @@
|
||||
package org.jetbrains.kotlin.idea.frontend.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtAnnotatedSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
|
||||
abstract class KtAnonymousObjectSymbol : KtSymbolWithKind, KtAnnotatedSymbol, KtSymbolWithDeclarations {
|
||||
abstract class KtAnonymousObjectSymbol : KtSymbolWithKind, KtAnnotatedSymbol, KtSymbolWithMembers {
|
||||
abstract val superTypes: List<KtType>
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtAnonymousObjectSymbol>
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtClassType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
@@ -38,7 +37,7 @@ abstract class KtClassOrObjectSymbol : KtClassLikeSymbol(),
|
||||
KtSymbolWithModality<KtSymbolModality>,
|
||||
KtSymbolWithVisibility,
|
||||
KtAnnotatedSymbol,
|
||||
KtSymbolWithDeclarations {
|
||||
KtSymbolWithMembers {
|
||||
abstract val classKind: KtClassKind
|
||||
|
||||
abstract val isInner: Boolean
|
||||
|
||||
-3
@@ -9,8 +9,5 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtAnnotatedSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
abstract class KtFileSymbol : KtAnnotatedSymbol {
|
||||
|
||||
abstract val topLevelCallableSymbols: List<KtCallableSymbol>
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtFileSymbol>
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ sealed class KtVariableLikeSymbol : KtCallableSymbol(), KtTypedSymbol, KtNamedSy
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol>
|
||||
}
|
||||
|
||||
abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithDeclarations, KtSymbolWithKind {
|
||||
abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMembers, KtSymbolWithKind {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
|
||||
abstract val containingEnumClassIdIfNonLocal: ClassId?
|
||||
|
||||
|
||||
+2
@@ -7,4 +7,6 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols.markers
|
||||
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
||||
|
||||
interface KtSymbolWithMembers : KtSymbolWithDeclarations
|
||||
|
||||
interface KtSymbolWithDeclarations : KtSymbol
|
||||
+21
-13
@@ -22,11 +22,14 @@ import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.asJava.classes.createField
|
||||
import org.jetbrains.kotlin.idea.asJava.classes.createMethods
|
||||
import org.jetbrains.kotlin.idea.frontend.api.analyze
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.analyzeWithSymbolAsContext
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtDeclarationScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFileSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtPropertySymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility
|
||||
import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -80,14 +83,17 @@ class FirLightClassForFacade(
|
||||
private val _ownMethods: List<KtLightMethod> by lazyPub {
|
||||
val result = mutableListOf<KtLightMethod>()
|
||||
|
||||
|
||||
val methodsAndProperties = sequence<KtCallableSymbol> {
|
||||
for (fileSymbol in fileSymbols) {
|
||||
for (callableSymbol in fileSymbol.topLevelCallableSymbols) {
|
||||
if (callableSymbol !is KtFunctionSymbol && callableSymbol !is KtPropertySymbol) continue
|
||||
if (callableSymbol !is KtSymbolWithVisibility) continue
|
||||
val isPrivate = callableSymbol.toPsiVisibilityForMember(isTopLevel = true) == PsiModifier.PRIVATE
|
||||
if (isPrivate && multiFileClass) continue
|
||||
yield(callableSymbol)
|
||||
analyzeWithSymbolAsContext(fileSymbol) {
|
||||
for (callableSymbol in fileSymbol.getFileScope().getCallableSymbols()) {
|
||||
if (callableSymbol !is KtFunctionSymbol && callableSymbol !is KtKotlinPropertySymbol) continue
|
||||
if (callableSymbol !is KtSymbolWithVisibility) continue
|
||||
val isPrivate = callableSymbol.toPsiVisibilityForMember(isTopLevel = true) == PsiModifier.PRIVATE
|
||||
if (isPrivate && multiFileClass) continue
|
||||
yield(callableSymbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,17 +107,17 @@ class FirLightClassForFacade(
|
||||
}
|
||||
|
||||
private fun loadFieldsFromFile(
|
||||
fileSymbol: KtFileSymbol,
|
||||
fileScope: KtDeclarationScope<KtSymbolWithDeclarations>,
|
||||
nameGenerator: FirLightField.FieldNameGenerator,
|
||||
result: MutableList<KtLightField>
|
||||
) {
|
||||
for (propertySymbol in fileSymbol.topLevelCallableSymbols) {
|
||||
for (propertySymbol in fileScope.getCallableSymbols()) {
|
||||
|
||||
if (propertySymbol !is KtPropertySymbol) continue
|
||||
if (propertySymbol !is KtKotlinPropertySymbol) continue
|
||||
|
||||
if (propertySymbol is KtKotlinPropertySymbol && propertySymbol.isConst && multiFileClass) continue
|
||||
if (propertySymbol.isConst && multiFileClass) continue
|
||||
|
||||
val isLateInitWithPublicAccessors = if (propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit) {
|
||||
val isLateInitWithPublicAccessors = if (propertySymbol.isLateInit) {
|
||||
val getterIsPublic = propertySymbol.getter?.toPsiVisibilityForMember(isTopLevel = true)
|
||||
?.let { it == PsiModifier.PUBLIC } ?: true
|
||||
val setterIsPublic = propertySymbol.setter?.toPsiVisibilityForMember(isTopLevel = true)
|
||||
@@ -120,7 +126,7 @@ class FirLightClassForFacade(
|
||||
} else false
|
||||
|
||||
val forceStaticAndPropertyVisibility = isLateInitWithPublicAccessors ||
|
||||
(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isConst) ||
|
||||
(propertySymbol.isConst) ||
|
||||
propertySymbol.hasJvmFieldAnnotation()
|
||||
|
||||
createField(
|
||||
@@ -139,7 +145,9 @@ class FirLightClassForFacade(
|
||||
val result = mutableListOf<KtLightField>()
|
||||
val nameGenerator = FirLightField.FieldNameGenerator()
|
||||
for (fileSymbol in fileSymbols) {
|
||||
loadFieldsFromFile(fileSymbol, nameGenerator, result)
|
||||
analyzeWithSymbolAsContext(fileSymbol) {
|
||||
loadFieldsFromFile(fileSymbol.getFileScope(), nameGenerator, result)
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.idea.frontend.api.fir.analyzeWithSymbolAsContext
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtCommonSymbolModality
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolVisibility
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtClassType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -304,7 +304,7 @@ internal fun FirLightClassBase.createInheritanceList(forExtendsList: Boolean, su
|
||||
return listBuilder
|
||||
}
|
||||
|
||||
internal fun KtSymbolWithDeclarations.createInnerClasses(manager: PsiManager): List<FirLightClassForSymbol> {
|
||||
internal fun KtSymbolWithMembers.createInnerClasses(manager: PsiManager): List<FirLightClassForSymbol> {
|
||||
val result = ArrayList<FirLightClassForSymbol>()
|
||||
|
||||
// workaround for ClassInnerStuffCache not supporting classes with null names, see KT-13927
|
||||
|
||||
+16
-5
@@ -28,13 +28,16 @@ import org.jetbrains.kotlin.idea.frontend.api.fir.scopes.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirFileSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.types.KtFirType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.EnclosingDeclarationContext
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.buildCompletionContext
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.weakRef
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFileSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
@@ -53,11 +56,12 @@ internal class KtFirScopeProvider(
|
||||
private val firResolveState by weakRef(firResolveState)
|
||||
private val firScopeStorage = FirScopeRegistry()
|
||||
|
||||
private val memberScopeCache = IdentityHashMap<KtSymbolWithDeclarations, KtMemberScope>()
|
||||
private val declaredMemberScopeCache = IdentityHashMap<KtSymbolWithDeclarations, KtDeclaredMemberScope>()
|
||||
private val memberScopeCache = IdentityHashMap<KtSymbolWithMembers, KtMemberScope>()
|
||||
private val declaredMemberScopeCache = IdentityHashMap<KtSymbolWithMembers, KtDeclaredMemberScope>()
|
||||
private val fileScopeCache = IdentityHashMap<KtFileSymbol, KtDeclarationScope<KtSymbolWithDeclarations>>()
|
||||
private val packageMemberScopeCache = IdentityHashMap<KtPackageSymbol, KtPackageScope>()
|
||||
|
||||
private inline fun <T> KtSymbolWithDeclarations.withFirForScope(crossinline body: (FirClass<*>) -> T): T? = when (this) {
|
||||
private inline fun <T> KtSymbolWithMembers.withFirForScope(crossinline body: (FirClass<*>) -> T): T? = when (this) {
|
||||
is KtFirClassOrObjectSymbol -> firRef.withFir(FirResolvePhase.SUPER_TYPES, body)
|
||||
is KtFirAnonymousObjectSymbol -> firRef.withFir(FirResolvePhase.SUPER_TYPES, body)
|
||||
is KtFirEnumEntrySymbol -> firRef.withFir(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) {
|
||||
@@ -68,7 +72,7 @@ internal class KtFirScopeProvider(
|
||||
else -> error { "Unknown KtSymbolWithDeclarations implementation ${this::class.qualifiedName}" }
|
||||
}
|
||||
|
||||
override fun getMemberScope(classSymbol: KtSymbolWithDeclarations): KtMemberScope = withValidityAssertion {
|
||||
override fun getMemberScope(classSymbol: KtSymbolWithMembers): KtMemberScope = withValidityAssertion {
|
||||
memberScopeCache.getOrPut(classSymbol) {
|
||||
|
||||
val firScope = classSymbol.withFirForScope { fir ->
|
||||
@@ -86,7 +90,7 @@ internal class KtFirScopeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDeclaredMemberScope(classSymbol: KtSymbolWithDeclarations): KtDeclaredMemberScope = withValidityAssertion {
|
||||
override fun getDeclaredMemberScope(classSymbol: KtSymbolWithMembers): KtDeclaredMemberScope = withValidityAssertion {
|
||||
declaredMemberScopeCache.getOrPut(classSymbol) {
|
||||
val firScope = classSymbol.withFirForScope {
|
||||
declaredMemberScope(it)
|
||||
@@ -98,6 +102,13 @@ internal class KtFirScopeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFileScope(fileSymbol: KtFileSymbol): KtDeclarationScope<KtSymbolWithDeclarations> = withValidityAssertion {
|
||||
fileScopeCache.getOrPut(fileSymbol) {
|
||||
check(fileSymbol is KtFirFileSymbol) { "KtFirScopeProvider can only work with KtFirFileSymbol, but ${fileSymbol::class} was provided" }
|
||||
KtFirFileScope(fileSymbol, token, builder)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPackageScope(packageSymbol: KtPackageSymbol): KtPackageScope = withValidityAssertion {
|
||||
packageMemberScopeCache.getOrPut(packageSymbol) {
|
||||
val firPackageScope =
|
||||
|
||||
+2
-3
@@ -9,14 +9,13 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.weakRef
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtDeclaredMemberScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtUnsubstitutedScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
|
||||
internal class KtFirDeclaredMemberScope(
|
||||
override val owner: KtSymbolWithDeclarations,
|
||||
override val owner: KtSymbolWithMembers,
|
||||
firScope: FirClassDeclaredMemberScope,
|
||||
token: ValidityToken,
|
||||
builder: KtSymbolByFirBuilder
|
||||
|
||||
+2
-2
@@ -12,10 +12,10 @@ import org.jetbrains.kotlin.idea.frontend.api.scopes.KtMemberScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassifierSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class KtFirEmptyMemberScope(override val owner: KtSymbolWithDeclarations) : KtMemberScope, KtDeclaredMemberScope, ValidityTokenOwner {
|
||||
internal class KtFirEmptyMemberScope(override val owner: KtSymbolWithMembers) : KtMemberScope, KtDeclaredMemberScope, ValidityTokenOwner {
|
||||
override fun getCallableNames(): Set<Name> = emptySet()
|
||||
|
||||
override fun getClassifierNames(): Set<Name> = emptySet()
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.idea.frontend.api.fir.scopes
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirFileSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtDeclarationScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeNameFilter
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassifierSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class KtFirFileScope(
|
||||
override val owner: KtFirFileSymbol,
|
||||
override val token: ValidityToken,
|
||||
private val builder: KtSymbolByFirBuilder
|
||||
) : KtDeclarationScope<KtSymbolWithDeclarations>,
|
||||
ValidityTokenOwner {
|
||||
|
||||
private val allNamesCached by cached {
|
||||
_callableNames + _classifierNames
|
||||
}
|
||||
|
||||
override fun getAllNames(): Set<Name> = allNamesCached
|
||||
|
||||
private val _callableNames: Set<Name> by cached {
|
||||
val result = mutableSetOf<Name>()
|
||||
owner.firRef.withFir {
|
||||
it.declarations.mapNotNullTo(result) { firDeclaration ->
|
||||
when (firDeclaration) {
|
||||
is FirSimpleFunction -> firDeclaration.name
|
||||
is FirProperty -> firDeclaration.name
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
override fun getCallableNames(): Set<Name> = _callableNames
|
||||
|
||||
private val _classifierNames: Set<Name> by cached {
|
||||
val result = mutableSetOf<Name>()
|
||||
owner.firRef.withFir {
|
||||
it.declarations.mapNotNullTo(result) { firDeclaration ->
|
||||
(firDeclaration as? FirRegularClass)?.name
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
override fun getClassifierNames(): Set<Name> = _classifierNames
|
||||
|
||||
override fun getCallableSymbols(nameFilter: KtScopeNameFilter): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||
owner.firRef.withFir {
|
||||
sequence {
|
||||
it.declarations.forEach { firDeclaration ->
|
||||
val callableDeclaration = when (firDeclaration) {
|
||||
is FirSimpleFunction -> firDeclaration.takeIf { nameFilter(firDeclaration.name) }
|
||||
is FirProperty -> firDeclaration.takeIf { nameFilter(firDeclaration.name) }
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (callableDeclaration != null) {
|
||||
yield(builder.buildCallableSymbol(callableDeclaration))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClassifierSymbols(nameFilter: KtScopeNameFilter): Sequence<KtClassifierSymbol> = withValidityAssertion {
|
||||
owner.firRef.withFir {
|
||||
sequence {
|
||||
it.declarations.forEach { firDeclaration ->
|
||||
val classLikeDeclaration = (firDeclaration as? FirRegularClass)?.takeIf { klass -> nameFilter(klass.name) }
|
||||
if (classLikeDeclaration != null) {
|
||||
yield(builder.buildClassLikeSymbol(classLikeDeclaration))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -9,14 +9,13 @@ import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.weakRef
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtMemberScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtUnsubstitutedScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithMembers
|
||||
|
||||
internal class KtFirMemberScope(
|
||||
override val owner: KtSymbolWithDeclarations,
|
||||
override val owner: KtSymbolWithMembers,
|
||||
firScope: FirTypeScope,
|
||||
token: ValidityToken,
|
||||
builder: KtSymbolByFirBuilder
|
||||
|
||||
+2
-9
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.idea.frontend.api.fir.symbols
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.idea.fir.findPsi
|
||||
@@ -15,9 +14,9 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityToken
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.convertAnnotation
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.firRef
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFileSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtAnnotationCall
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithDeclarations
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
@@ -26,17 +25,11 @@ internal class KtFirFileSymbol(
|
||||
resolveState: FirModuleResolveState,
|
||||
override val token: ValidityToken,
|
||||
private val builder: KtSymbolByFirBuilder
|
||||
) : KtFileSymbol(), KtFirSymbol<FirFile> {
|
||||
) : KtFileSymbol(), KtSymbolWithDeclarations, KtFirSymbol<FirFile> {
|
||||
|
||||
override val firRef = firRef(fir, resolveState)
|
||||
override val psi: PsiElement? by firRef.withFirAndCache { fir -> fir.findPsi(fir.session) }
|
||||
|
||||
override val topLevelCallableSymbols: List<KtCallableSymbol> by firRef.withFirAndCache {
|
||||
it.declarations.mapNotNull { declaration ->
|
||||
if (declaration is FirCallableDeclaration<*>) builder.buildCallableSymbol(declaration) else null
|
||||
}
|
||||
}
|
||||
|
||||
override fun createPointer(): KtSymbolPointer<KtFileSymbol> {
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
||||
TODO("Creating pointers for files from library is not supported yet")
|
||||
|
||||
Reference in New Issue
Block a user