FIR IDE: Add KtCallableSymbol abstraction
- It should incapsulate callable symbols like functions, properties and constructors Co-authored-by: Ilya Kirillov <ilya.kirillov@jetbrains.com>
This commit is contained in:
committed by
Ilya Kirillov
parent
a4a2d92c08
commit
df03e31b86
@@ -16,7 +16,7 @@ interface KtScope : ValidityOwner {
|
||||
|
||||
|
||||
fun getAllSymbols(): Sequence<KtSymbol>
|
||||
fun getCallableSymbols(): Sequence<KtSymbol>
|
||||
fun getCallableSymbols(): Sequence<KtCallableSymbol>
|
||||
fun getClassClassLikeSymbols(): Sequence<KtClassLikeSymbol>
|
||||
|
||||
fun containsName(name: Name): Boolean
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* 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.symbols
|
||||
|
||||
abstract class KtCallableSymbol : KtSymbol
|
||||
+1
-1
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
sealed class KtFunctionLikeSymbol : KtTypedSymbol, KtSymbolWithKind {
|
||||
sealed class KtFunctionLikeSymbol : KtCallableSymbol(), KtTypedSymbol, KtSymbolWithKind {
|
||||
abstract val valueParameters: List<KtParameterSymbol>
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.frontend.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
abstract class KtVariableLikeSymbol : KtTypedSymbol, KtNamedSymbol, KtSymbolWithKind
|
||||
abstract class KtVariableLikeSymbol : KtCallableSymbol(), KtTypedSymbol, KtNamedSymbol, KtSymbolWithKind
|
||||
|
||||
abstract class KtEnumEntrySymbol : KtVariableLikeSymbol() {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
|
||||
|
||||
@@ -29,6 +29,9 @@ interface KtPossibleExtensionSymbol {
|
||||
val receiverType: KtType?
|
||||
}
|
||||
|
||||
val KtCallableSymbol.isExtension: Boolean
|
||||
get() = (this as? KtPossibleExtensionSymbol)?.isExtension == true
|
||||
|
||||
interface KtSymbolWithTypeParameters {
|
||||
val typeParameters: List<KtTypeParameterSymbol>
|
||||
}
|
||||
|
||||
+4
-4
@@ -32,10 +32,7 @@ import org.jetbrains.kotlin.idea.frontend.api.fir.types.KtFirIntersectionType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.types.KtFirTypeArgumentWithVariance
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.types.KtFirTypeParameterType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.weakRef
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtVariableSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -72,6 +69,9 @@ internal class KtSymbolByFirBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Handle all relevant cases
|
||||
fun buildCallableSymbol(fir: FirCallableDeclaration<*>): KtCallableSymbol = buildSymbol(fir) as KtCallableSymbol
|
||||
|
||||
fun buildClassLikeSymbol(fir: FirClassLikeDeclaration<*>): KtClassLikeSymbol = when (fir) {
|
||||
is FirRegularClass -> buildClassSymbol(fir)
|
||||
is FirTypeAlias -> buildTypeAliasSymbol(fir)
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.idea.frontend.api.ValidityOwner
|
||||
import org.jetbrains.kotlin.idea.frontend.api.ValidityOwnerByValidityToken
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtCompositeScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
|
||||
@@ -45,7 +46,7 @@ class KtFirCompositeScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(): Sequence<KtSymbol> = withValidityAssertion {
|
||||
override fun getCallableSymbols(): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||
sequence {
|
||||
subScopes.forEach { yieldAll(it.getCallableSymbols()) }
|
||||
}
|
||||
|
||||
+4
-3
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.symbols.PossiblyFirFakeOverrideSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
|
||||
@@ -48,10 +49,10 @@ internal abstract class KtFirDelegatingScope(private val builder: KtSymbolByFirB
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCallableSymbols(): Sequence<KtSymbol> = withValidityAssertion {
|
||||
override fun getCallableSymbols(): Sequence<KtCallableSymbol> = withValidityAssertion {
|
||||
sequence {
|
||||
firScope.getCallableNames().forEach { name ->
|
||||
val callables = mutableListOf<KtSymbol>()
|
||||
val callables = mutableListOf<KtCallableSymbol>()
|
||||
firScope.processFunctionsByName(name) { firSymbol ->
|
||||
(firSymbol.fir as? FirSimpleFunction)?.let { fir ->
|
||||
callables.add(builder.buildFunctionSymbol(fir, firSymbol.realDeclarationOrigin()))
|
||||
@@ -62,7 +63,7 @@ internal abstract class KtFirDelegatingScope(private val builder: KtSymbolByFirB
|
||||
firSymbol is FirPropertySymbol && firSymbol.isFakeOverride -> {
|
||||
builder.buildVariableSymbol(firSymbol.fir, firSymbol.realDeclarationOrigin())
|
||||
}
|
||||
else -> builder.buildSymbol(firSymbol.fir)
|
||||
else -> builder.buildCallableSymbol(firSymbol.fir)
|
||||
}
|
||||
callables.add(symbol)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user