Analysis API: rework KtSymbol hierarchy
- make some symbols to be KtPossiblyMemberSymbols - introduce KtDeclarationSymbol for declarations
This commit is contained in:
+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