Analysis API: rework KtSymbol hierarchy

- make some symbols to be KtPossiblyMemberSymbols
- introduce KtDeclarationSymbol for declarations
This commit is contained in:
Ilya Kirillov
2021-11-30 13:10:12 +01:00
parent 22e31ea414
commit 985c6fa0b8
11 changed files with 34 additions and 25 deletions
@@ -5,8 +5,8 @@
package org.jetbrains.kotlin.analysis.api.components
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
/**
@@ -125,7 +125,7 @@ public enum class RendererModifier(public val includeByDefault: Boolean) {
}
public abstract class KtSymbolDeclarationRendererProvider : KtAnalysisSessionComponent() {
public abstract fun renderMember(symbol: KtPossibleMemberSymbol, options: KtDeclarationRendererOptions): String
public abstract fun renderDeclaration(symbol: KtDeclarationSymbol, options: KtDeclarationRendererOptions): String
public abstract fun render(type: KtType, options: KtTypeRendererOptions): String
}
@@ -136,8 +136,8 @@ public interface KtSymbolDeclarationRendererMixIn : KtAnalysisSessionMixIn {
/**
* Render symbol into the representable Kotlin string
*/
public fun KtPossibleMemberSymbol.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String =
analysisSession.symbolDeclarationRendererProvider.renderMember(this, options)
public fun KtDeclarationSymbol.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String =
analysisSession.symbolDeclarationRendererProvider.renderDeclaration(this, options)
/**
* Render kotlin type into the representable Kotlin type string
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.analysis.api.components
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
import org.jetbrains.kotlin.analysis.api.types.KtFlexibleType
@@ -38,7 +39,7 @@ public abstract class KtTypeProvider : KtAnalysisSessionComponent() {
public abstract fun getAllSuperTypes(type: KtType, shouldApproximate: Boolean): List<KtType>
public abstract fun getDispatchReceiverType(symbol: KtPossibleMemberSymbol): KtType?
public abstract fun getDispatchReceiverType(symbol: KtCallableSymbol): KtType?
}
public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
@@ -133,7 +134,7 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Avoid using this function")
public fun KtPossibleMemberSymbol.getDispatchReceiverType(): KtType? =
public fun KtCallableSymbol.getDispatchReceiverType(): KtType? =
analysisSession.typeProvider.getDispatchReceiverType(this)
}
@@ -39,7 +39,7 @@ public object DebugSymbolRenderer {
withIndent {
@Suppress("DEPRECATION")
(symbol as? KtPossibleMemberSymbol)?.getDispatchReceiverType()?.let { dispatchType ->
(symbol as? KtCallableSymbol)?.getDispatchReceiverType()?.let { dispatchType ->
appendLine().append("getDispatchReceiver()").append(": ")
renderType(dispatchType)
}
@@ -5,12 +5,13 @@
package org.jetbrains.kotlin.analysis.api.symbols
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithKind
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.name.CallableId
public abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind {
public abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind, KtPossibleMemberSymbol, KtDeclarationSymbol {
public abstract val callableIdIfNonLocal: CallableId?
public abstract val returnType: KtType
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.types.Variance
public sealed class KtClassifierSymbol : KtSymbol, KtPossiblyNamedSymbol, KtPossibleMemberSymbol
public sealed class KtClassifierSymbol : KtSymbol, KtPossiblyNamedSymbol, KtDeclarationSymbol
public val KtClassifierSymbol.nameOrAnonymous: Name
get() = name ?: SpecialNames.ANONYMOUS
@@ -26,7 +26,7 @@ public abstract class KtTypeParameterSymbol : KtClassifierSymbol(), KtNamedSymbo
public abstract val isReified: Boolean
}
public sealed class KtClassLikeSymbol : KtClassifierSymbol(), KtSymbolWithKind {
public sealed class KtClassLikeSymbol : KtClassifierSymbol(), KtSymbolWithKind, KtPossibleMemberSymbol {
public abstract val classIdIfNonLocal: ClassId?
abstract override fun createPointer(): KtSymbolPointer<KtClassLikeSymbol>
@@ -0,0 +1,12 @@
/*
* 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.symbols
/**
* Represents a symbol of declaration which can be directly expressed in source code.
* Eg, classes, type parameters or functions ar [KtDeclarationSymbol], but files and packages are not
*/
public sealed interface KtDeclarationSymbol : KtSymbol
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtExpression
public sealed class KtVariableLikeSymbol : KtCallableSymbol(), KtNamedSymbol, KtSymbolWithKind {
public sealed class KtVariableLikeSymbol : KtCallableSymbol(), KtNamedSymbol, KtSymbolWithKind, KtPossibleMemberSymbol {
abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol>
}
@@ -37,7 +37,7 @@ public abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
final override val name: Name get() = fieldName
final override val psi: PsiElement? get() = null
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
final override val origin: KtSymbolOrigin get() = KtSymbolOrigin.PROPERTY_BACKING_FIELD
override val origin: KtSymbolOrigin get() = KtSymbolOrigin.PROPERTY_BACKING_FIELD
final override val callableIdIfNonLocal: CallableId? get() = null
final override val isExtension: Boolean get() = false
final override val receiverType: KtType? get() = null