Analysis API: rework KtSymbol hierarchy
- make some symbols to be KtPossiblyMemberSymbols - introduce KtDeclarationSymbol for declarations
This commit is contained in:
+2
-3
@@ -14,8 +14,7 @@ import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.bas
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.render
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.base.KtFe10Type
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.utils.KtFe10TypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint
|
||||
@@ -26,7 +25,7 @@ internal class KtFe10SymbolDeclarationRendererProvider(
|
||||
override val token: ValidityToken
|
||||
get() = analysisSession.token
|
||||
|
||||
override fun renderMember(symbol: KtPossibleMemberSymbol, options: KtDeclarationRendererOptions): String {
|
||||
override fun renderDeclaration(symbol: KtDeclarationSymbol, options: KtDeclarationRendererOptions): String {
|
||||
val descriptor = getSymbolDescriptor(symbol)
|
||||
if (descriptor != null) {
|
||||
return descriptor.render(analysisContext, options)
|
||||
|
||||
+3
-8
@@ -11,16 +11,11 @@ import org.jetbrains.kotlin.analysis.api.components.KtTypeRendererOptions
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.renderer.ConeTypeIdeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.renderer.FirIdeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirReceiverParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.fir.types.KtFirType
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
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.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
|
||||
internal class KtFirSymbolDeclarationRendererProvider(
|
||||
@@ -33,10 +28,10 @@ internal class KtFirSymbolDeclarationRendererProvider(
|
||||
return ConeTypeIdeRenderer(analysisSession.firResolveState.rootModuleSession, options).renderType(type.coneType)
|
||||
}
|
||||
|
||||
override fun renderMember(symbol: KtPossibleMemberSymbol, options: KtDeclarationRendererOptions): String {
|
||||
override fun renderDeclaration(symbol: KtDeclarationSymbol, options: KtDeclarationRendererOptions): String {
|
||||
require(symbol is KtFirSymbol<*>)
|
||||
return symbol.firRef.withFir(FirResolvePhase.BODY_RESOLVE) { fir ->
|
||||
FirIdeRenderer.render(fir as FirMemberDeclaration, options, fir.moduleData.session)
|
||||
FirIdeRenderer.render(fir, options, fir.moduleData.session)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.components.KtDeclarationRendererOptions
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtTypeRendererOptions
|
||||
import org.jetbrains.kotlin.analysis.api.impl.barebone.test.FrontendApiTestConfiguratorService
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.test.framework.AbstractHLApiSingleFileTest
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
@@ -28,7 +29,7 @@ abstract class AbstractRendererTest(configurator: FrontendApiTestConfiguratorSer
|
||||
buildString {
|
||||
ktFile.declarations.forEach { declaration ->
|
||||
analyseForTest(declaration) {
|
||||
val symbol = declaration.getSymbol() as? KtPossibleMemberSymbol ?: return@analyseForTest
|
||||
val symbol = declaration.getSymbol() as? KtDeclarationSymbol ?: return@analyseForTest
|
||||
append(symbol.render(options))
|
||||
appendLine()
|
||||
appendLine()
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ private fun KtAnalysisSession.stringRepresentation(call: KtCall): String {
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
(this@stringValue as? KtPossibleMemberSymbol)?.getDispatchReceiverType()?.let { dispatchReceiverType ->
|
||||
(this@stringValue as? KtCallableSymbol)?.getDispatchReceiverType()?.let { dispatchReceiverType ->
|
||||
append("<dispatch receiver>: ${dispatchReceiverType.render()}")
|
||||
if (valueParameters.isNotEmpty()) append(", ")
|
||||
}
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
+3
-2
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
|
||||
+2
-2
@@ -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>
|
||||
|
||||
+12
@@ -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
|
||||
+2
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user