FIR IDE: make KtCallableSymbol to be always KtPossiblyExtensionSymbol

This commit is contained in:
Ilya Kirillov
2021-05-03 17:05:54 +02:00
committed by TeamCityServer
parent 0ba6412f96
commit accc0e3761
10 changed files with 23 additions and 19 deletions
@@ -436,7 +436,7 @@ private fun KtSymbolBasedDeclarationDescriptor.getDispatchReceiverParameter(ktSy
} }
private fun <T> T.getExtensionReceiverParameter( private fun <T> T.getExtensionReceiverParameter(
ktSymbol: KtPossibleExtensionSymbol ktSymbol: KtCallableSymbol,
): ReceiverParameterDescriptor? where T : KtSymbolBasedDeclarationDescriptor, T : CallableDescriptor { ): ReceiverParameterDescriptor? where T : KtSymbolBasedDeclarationDescriptor, T : CallableDescriptor {
val receiverTypeAndAnnotation = ktSymbol.receiverType ?: return null val receiverTypeAndAnnotation = ktSymbol.receiverType ?: return null
val receiverValue = ExtensionReceiver(this, receiverTypeAndAnnotation.type.toKotlinType(context), null) val receiverValue = ExtensionReceiver(this, receiverTypeAndAnnotation.type.toKotlinType(context), null)
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeNameFilter
import org.jetbrains.kotlin.idea.frontend.api.symbols.* import org.jetbrains.kotlin.idea.frontend.api.symbols.*
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.isExtension
import org.jetbrains.kotlin.idea.frontend.api.types.KtClassType import org.jetbrains.kotlin.idea.frontend.api.types.KtClassType
import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.references.mainReference
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtConstructorSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFunctionSymbol 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.KtPropertySymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtPossibleExtensionSymbol
import org.jetbrains.kotlin.idea.j2k.IdeaDocCommentConverter import org.jetbrains.kotlin.idea.j2k.IdeaDocCommentConverter
import org.jetbrains.kotlin.idea.kdoc.KDocElementFactory import org.jetbrains.kotlin.idea.kdoc.KDocElementFactory
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
@@ -85,7 +84,7 @@ internal fun KtAnalysisSession.generateMember(
): KtCallableDeclaration = with(ktClassMember) { ): KtCallableDeclaration = with(ktClassMember) {
val bodyType = when { val bodyType = when {
targetClass?.hasExpectModifier() == true -> BodyType.NO_BODY targetClass?.hasExpectModifier() == true -> BodyType.NO_BODY
(symbol as? KtPossibleExtensionSymbol)?.isExtension == true && mode == MemberGenerateMode.OVERRIDE -> BodyType.FROM_TEMPLATE symbol.isExtension && mode == MemberGenerateMode.OVERRIDE -> BodyType.FROM_TEMPLATE
else -> bodyType else -> bodyType
} }
@@ -13,5 +13,9 @@ import org.jetbrains.kotlin.name.CallableId
abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind { abstract class KtCallableSymbol : KtSymbol, KtSymbolWithKind {
abstract val callableIdIfNonLocal: CallableId? abstract val callableIdIfNonLocal: CallableId?
abstract val annotatedType: KtTypeAndAnnotations abstract val annotatedType: KtTypeAndAnnotations
abstract val receiverType: KtTypeAndAnnotations?
abstract val isExtension: Boolean
abstract override fun createPointer(): KtSymbolPointer<KtCallableSymbol> abstract override fun createPointer(): KtSymbolPointer<KtCallableSymbol>
} }
@@ -17,7 +17,7 @@ abstract class KtFunctionLikeSymbol : KtCallableSymbol(), KtSymbolWithKind {
abstract override fun createPointer(): KtSymbolPointer<KtFunctionLikeSymbol> abstract override fun createPointer(): KtSymbolPointer<KtFunctionLikeSymbol>
} }
abstract class KtAnonymousFunctionSymbol : KtFunctionLikeSymbol(), KtPossibleExtensionSymbol { abstract class KtAnonymousFunctionSymbol : KtFunctionLikeSymbol() {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
@@ -26,7 +26,6 @@ abstract class KtAnonymousFunctionSymbol : KtFunctionLikeSymbol(), KtPossibleExt
abstract class KtFunctionSymbol : KtFunctionLikeSymbol(), abstract class KtFunctionSymbol : KtFunctionLikeSymbol(),
KtNamedSymbol, KtNamedSymbol,
KtPossibleExtensionSymbol,
KtPossibleMemberSymbol, KtPossibleMemberSymbol,
KtSymbolWithTypeParameters, KtSymbolWithTypeParameters,
KtSymbolWithModality, KtSymbolWithModality,
@@ -52,6 +51,8 @@ abstract class KtConstructorSymbol : KtFunctionLikeSymbol(),
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null
abstract override fun createPointer(): KtSymbolPointer<KtConstructorSymbol> abstract override fun createPointer(): KtSymbolPointer<KtConstructorSymbol>
} }
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtPossibleMemberSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtPossibleMemberSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithModality import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithModality
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.isExtension
import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtDeclaration
import javax.swing.Icon import javax.swing.Icon
@@ -17,6 +17,8 @@ sealed class KtPropertyAccessorSymbol : KtCallableSymbol(),
KtSymbolWithKind { KtSymbolWithKind {
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null
abstract val isDefault: Boolean abstract val isDefault: Boolean
abstract val isInline: Boolean abstract val isInline: Boolean
@@ -36,6 +36,8 @@ abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
final override val origin: KtSymbolOrigin get() = KtSymbolOrigin.PROPERTY_BACKING_FIELD final override val origin: KtSymbolOrigin get() = KtSymbolOrigin.PROPERTY_BACKING_FIELD
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null
abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol> abstract override fun createPointer(): KtSymbolPointer<KtVariableLikeSymbol>
@@ -47,8 +49,11 @@ abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMembers, KtSymbolWithKind { abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMembers, KtSymbolWithKind {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null
abstract val containingEnumClassIdIfNonLocal: ClassId? abstract val containingEnumClassIdIfNonLocal: ClassId?
abstract override fun createPointer(): KtSymbolPointer<KtEnumEntrySymbol> abstract override fun createPointer(): KtSymbolPointer<KtEnumEntrySymbol>
} }
@@ -64,12 +69,13 @@ abstract class KtJavaFieldSymbol :
KtSymbolWithVisibility, KtSymbolWithVisibility,
KtSymbolWithKind { KtSymbolWithKind {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER final override val symbolKind: KtSymbolKind get() = KtSymbolKind.MEMBER
final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null
abstract override fun createPointer(): KtSymbolPointer<KtJavaFieldSymbol> abstract override fun createPointer(): KtSymbolPointer<KtJavaFieldSymbol>
} }
sealed class KtPropertySymbol : KtVariableSymbol(), sealed class KtPropertySymbol : KtVariableSymbol(),
KtPossibleExtensionSymbol,
KtPossibleMemberSymbol, KtPossibleMemberSymbol,
KtSymbolWithModality, KtSymbolWithModality,
KtSymbolWithVisibility, KtSymbolWithVisibility,
@@ -114,6 +120,8 @@ abstract class KtSyntheticJavaPropertySymbol : KtPropertySymbol() {
abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind { abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind {
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null
abstract override fun createPointer(): KtSymbolPointer<KtLocalVariableSymbol> abstract override fun createPointer(): KtSymbolPointer<KtLocalVariableSymbol>
} }
@@ -121,6 +129,8 @@ abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind {
abstract class KtValueParameterSymbol : KtVariableLikeSymbol(), KtSymbolWithKind, KtAnnotatedSymbol { abstract class KtValueParameterSymbol : KtVariableLikeSymbol(), KtSymbolWithKind, KtAnnotatedSymbol {
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
final override val callableIdIfNonLocal: CallableId? get() = null final override val callableIdIfNonLocal: CallableId? get() = null
final override val isExtension: Boolean get() = false
final override val receiverType: KtTypeAndAnnotations? get() = null
abstract val hasDefaultValue: Boolean abstract val hasDefaultValue: Boolean
abstract val isVararg: Boolean abstract val isVararg: Boolean
@@ -12,12 +12,4 @@ import org.jetbrains.kotlin.idea.frontend.api.types.KtType
abstract class KtTypeAndAnnotations : ValidityTokenOwner { abstract class KtTypeAndAnnotations : ValidityTokenOwner {
abstract val type: KtType abstract val type: KtType
abstract val annotations: List<KtAnnotationCall> abstract val annotations: List<KtAnnotationCall>
} }
interface KtPossibleExtensionSymbol {
val receiverType: KtTypeAndAnnotations?
val isExtension: Boolean
}
val KtCallableSymbol.isExtension: Boolean
get() = (this as? KtPossibleExtensionSymbol)?.isExtension == true
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtTypeAndAnnotations import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtTypeAndAnnotations
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtPossibleExtensionSymbol
import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi.KtParameter
internal class FirLightParameterForReceiver private constructor( internal class FirLightParameterForReceiver private constructor(
@@ -34,7 +33,6 @@ internal class FirLightParameterForReceiver private constructor(
): FirLightParameterForReceiver? { ): FirLightParameterForReceiver? {
if (callableSymbol !is KtNamedSymbol) return null if (callableSymbol !is KtNamedSymbol) return null
if (callableSymbol !is KtPossibleExtensionSymbol) return null
if (!callableSymbol.isExtension) return null if (!callableSymbol.isExtension) return null
val extensionTypeAndAnnotations = callableSymbol.receiverType ?: return null val extensionTypeAndAnnotations = callableSymbol.receiverType ?: return null