diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/methods/SymbolLightAnnotationsMethod.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/methods/SymbolLightAnnotationsMethod.kt index 3945702148f..fb0fd4b7e8e 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/methods/SymbolLightAnnotationsMethod.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/methods/SymbolLightAnnotationsMethod.kt @@ -23,9 +23,11 @@ import org.jetbrains.kotlin.light.classes.symbol.modifierLists.GranularModifiers import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightMemberModifierList import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightParameterForReceiver import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightParameterList +import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightTypeParameterList import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.psi.KtCallableDeclaration import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.utils.addToStdlib.ifTrue internal class SymbolLightAnnotationsMethod private constructor( lightMemberOrigin: LightMemberOrigin?, @@ -126,14 +128,29 @@ internal class SymbolLightAnnotationsMethod private constructor( override fun getTypeParameterList(): PsiTypeParameterList? = null override fun getTypeParameters(): Array = PsiTypeParameter.EMPTY_ARRAY + internal fun getPropertyTypeParameters(): Array = + _propertyTypeParameterList?.typeParameters ?: PsiTypeParameter.EMPTY_ARRAY + + private val _propertyTypeParameterList: PsiTypeParameterList? by lazyPub { + propertyHasTypeParameters().ifTrue { + SymbolLightTypeParameterList( + owner = this, + symbolWithTypeParameterPointer = containingPropertySymbolPointer, + ktModule = ktModule, + ktDeclaration = containingPropertyDeclaration, + ) + } + } + + private fun propertyHasTypeParameters(): Boolean = hasTypeParameters(ktModule, containingPropertyDeclaration, containingPropertySymbolPointer) + private val _parametersList by lazyPub { SymbolLightParameterList( parent = this@SymbolLightAnnotationsMethod, parameterPopulator = { builder -> SymbolLightParameterForReceiver.tryGet( callableSymbolPointer = containingPropertySymbolPointer, - method = this@SymbolLightAnnotationsMethod, - forPropertyAnnotations = true + method = this@SymbolLightAnnotationsMethod )?.let(builder::addParameter) }, ) diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/parameters/SymbolLightParameterForReceiver.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/parameters/SymbolLightParameterForReceiver.kt index 669b5e7f148..d7f861efb34 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/parameters/SymbolLightParameterForReceiver.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/parameters/SymbolLightParameterForReceiver.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.light.classes.symbol.* import org.jetbrains.kotlin.light.classes.symbol.annotations.* +import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAnnotationsMethod import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList import org.jetbrains.kotlin.psi.KtParameter @@ -27,7 +28,6 @@ internal class SymbolLightParameterForReceiver private constructor( private val receiverPointer: KtSymbolPointer, methodName: String, method: SymbolLightMethodBase, - private val forPropertyAnnotations: Boolean ) : SymbolLightParameterBase(method) { private inline fun withReceiverSymbol(crossinline action: context(KtAnalysisSession) (KtReceiverParameterSymbol) -> T): T = receiverPointer.withSymbol(ktModule, action) @@ -35,8 +35,7 @@ internal class SymbolLightParameterForReceiver private constructor( companion object { fun tryGet( callableSymbolPointer: KtSymbolPointer, - method: SymbolLightMethodBase, - forPropertyAnnotations: Boolean = false + method: SymbolLightMethodBase ): SymbolLightParameterForReceiver? = callableSymbolPointer.withSymbol(method.ktModule) { callableSymbol -> if (callableSymbol !is KtNamedSymbol) return@withSymbol null if (!callableSymbol.isExtension) return@withSymbol null @@ -46,13 +45,12 @@ internal class SymbolLightParameterForReceiver private constructor( receiverPointer = receiverSymbol.createPointer(), methodName = callableSymbol.name.asString(), method = method, - forPropertyAnnotations = forPropertyAnnotations, ) } } private val _name: String by lazyPub { - if (forPropertyAnnotations) "p0" else AsmUtil.getLabeledThisName(methodName, AsmUtil.LABELED_THIS_PARAMETER, AsmUtil.RECEIVER_PARAMETER_NAME) + if (method is SymbolLightAnnotationsMethod) "p0" else AsmUtil.getLabeledThisName(methodName, AsmUtil.LABELED_THIS_PARAMETER, AsmUtil.RECEIVER_PARAMETER_NAME) } override fun getNameIdentifier(): PsiIdentifier? = null @@ -67,7 +65,7 @@ internal class SymbolLightParameterForReceiver private constructor( override fun getModifierList(): PsiModifierList = _modifierList private val _modifierList: PsiModifierList by lazyPub { - if (forPropertyAnnotations) + if (method is SymbolLightAnnotationsMethod) SymbolLightClassModifierList(containingDeclaration = this) else SymbolLightClassModifierList( containingDeclaration = this, @@ -92,7 +90,16 @@ internal class SymbolLightParameterForReceiver private constructor( val psiType = ktType.asPsiTypeElement(this, allowErrorTypes = true)?.let { annotateByKtType(it.type, ktType, it, modifierList) } - if (forPropertyAnnotations) TypeConversionUtil.erasure(psiType) else psiType + if (method is SymbolLightAnnotationsMethod) { + val erased = TypeConversionUtil.erasure(psiType) + val name = erased.canonicalText + method.getPropertyTypeParameters() + .firstOrNull { it.name == name } + ?.superTypes + ?.firstOrNull() + ?.let { TypeConversionUtil.erasure(it) } + ?: erased + } else psiType } ?: nonExistentType() } @@ -101,7 +108,6 @@ internal class SymbolLightParameterForReceiver private constructor( override fun equals(other: Any?): Boolean = this === other || other is SymbolLightParameterForReceiver && ktModule == other.ktModule && - forPropertyAnnotations == other.forPropertyAnnotations && compareSymbolPointers(receiverPointer, other.receiverPointer) override fun hashCode(): Int = _name.hashCode() diff --git a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.fir.java b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.fir.java index 589a3d3f67b..35ecf2c2b49 100644 --- a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.fir.java +++ b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.fir.java @@ -74,9 +74,17 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ { @java.lang.Deprecated() public static void getNullable$annotations();// getNullable$annotations() - @Anno(p = "propery") + @Anno(p = "property") @java.lang.Deprecated() - public static void getExtensionProperty$annotations(java.util.List);// getExtensionProperty$annotations(java.util.List) + public static void getExtensionProperty1$annotations(java.lang.Object);// getExtensionProperty1$annotations(java.lang.Object) + + @Anno(p = "property") + @java.lang.Deprecated() + public static void getExtensionProperty2$annotations(java.util.List);// getExtensionProperty2$annotations(java.util.List) + + @Anno(p = "property") + @java.lang.Deprecated() + public static void getExtensionProperty3$annotations(java.util.Map);// getExtensionProperty3$annotations(java.util.Map) @java.lang.Deprecated() @kotlin.Deprecated(message = "deprecated") @@ -88,7 +96,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ { @org.jetbrains.annotations.Nullable() public static final java.lang.String getNullable();// getNullable() - public static final int getExtensionProperty(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List);// getExtensionProperty(java.util.List) + public static final int getExtensionProperty1(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() T);// getExtensionProperty1(T) + + public static final int getExtensionProperty2(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List);// getExtensionProperty2(java.util.List) + + public static final , Z extends java.util.Map> int getExtensionProperty3(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() Z);// , Z extends java.util.Map> getExtensionProperty3(Z) public static final int getDeprecated();// getDeprecated() diff --git a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.java b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.java index 5ebeba3a654..868b1037890 100644 --- a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.java +++ b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.java @@ -55,7 +55,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ { @org.jetbrains.annotations.Nullable() public static final java.lang.String getNullable();// getNullable() - public static final int getExtensionProperty(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List);// getExtensionProperty(java.util.List) + public static final int getExtensionProperty1(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() T);// getExtensionProperty1(T) + + public static final int getExtensionProperty2(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List);// getExtensionProperty2(java.util.List) + + public static final , Z extends java.util.Map> int getExtensionProperty3(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() Z);// , Z extends java.util.Map> getExtensionProperty3(Z) public static final int getDeprecated();// getDeprecated() diff --git a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.kt b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.kt index 081d01f4d58..d699ece321f 100644 --- a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.kt +++ b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.kt @@ -21,8 +21,16 @@ class C { } } -@Anno("propery") -val @receiver:Anno("receiver") List.extensionProperty: Int +@Anno("property") +val @receiver:Anno("receiver") T.extensionProperty1: Int + get() = 0 + +@Anno("property") +val @receiver:Anno("receiver") List.extensionProperty2: Int + get() = 0 + +@Anno("property") +val , Z: Map> @receiver:Anno("receiver") Z.extensionProperty3: Int get() = 0 @Anno("nullable") diff --git a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.lib.java b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.lib.java index 2600bb131bc..18e98a0dbb9 100644 --- a/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.lib.java +++ b/compiler/testData/asJava/lightClasses/lightClassByPsi/propertyAnnotations.lib.java @@ -53,7 +53,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ { @org.jetbrains.annotations.Nullable() public static final java.lang.String getNullable();// getNullable() - public static final int getExtensionProperty(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List);// getExtensionProperty(java.util.List) + public static final int getExtensionProperty1(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() T);// getExtensionProperty1(T) + + public static final int getExtensionProperty2(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List);// getExtensionProperty2(java.util.List) + + public static final , Z extends java.util.Map> int getExtensionProperty3(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() Z);// , Z extends java.util.Map> getExtensionProperty3(Z) public static final int getDeprecated();// getDeprecated()