KT-59563 [SLC] Fix type erasure in $annotations methods of extension properties
This commit is contained in:
committed by
Space Team
parent
3d60ed8874
commit
134b02c754
+19
-2
@@ -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> = PsiTypeParameter.EMPTY_ARRAY
|
||||
|
||||
internal fun getPropertyTypeParameters(): Array<PsiTypeParameter> =
|
||||
_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)
|
||||
},
|
||||
)
|
||||
|
||||
+14
-8
@@ -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<KtReceiverParameterSymbol>,
|
||||
methodName: String,
|
||||
method: SymbolLightMethodBase,
|
||||
private val forPropertyAnnotations: Boolean
|
||||
) : SymbolLightParameterBase(method) {
|
||||
private inline fun <T> 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<KtCallableSymbol>,
|
||||
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()
|
||||
|
||||
+15
-3
@@ -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 <T> int getExtensionProperty(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List<? extends T>);// <T> getExtensionProperty(java.util.List<? extends T>)
|
||||
public static final <T> int getExtensionProperty1(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() T);// <T> getExtensionProperty1(T)
|
||||
|
||||
public static final <T> int getExtensionProperty2(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List<? extends T>);// <T> getExtensionProperty2(java.util.List<? extends T>)
|
||||
|
||||
public static final <X, Y extends java.util.List<? extends X>, Z extends java.util.Map<X, ? extends Y>> int getExtensionProperty3(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() Z);// <X, Y extends java.util.List<? extends X>, Z extends java.util.Map<X, ? extends Y>> getExtensionProperty3(Z)
|
||||
|
||||
public static final int getDeprecated();// getDeprecated()
|
||||
|
||||
|
||||
+5
-1
@@ -55,7 +55,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ {
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
public static final java.lang.String getNullable();// getNullable()
|
||||
|
||||
public static final <T> int getExtensionProperty(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List<? extends T>);// <T> getExtensionProperty(java.util.List<? extends T>)
|
||||
public static final <T> int getExtensionProperty1(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() T);// <T> getExtensionProperty1(T)
|
||||
|
||||
public static final <T> int getExtensionProperty2(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List<? extends T>);// <T> getExtensionProperty2(java.util.List<? extends T>)
|
||||
|
||||
public static final <X, Y extends java.util.List<? extends X>, Z extends java.util.Map<X, ? extends Y>> int getExtensionProperty3(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() Z);// <X, Y extends java.util.List<? extends X>, Z extends java.util.Map<X, ? extends Y>> getExtensionProperty3(Z)
|
||||
|
||||
public static final int getDeprecated();// getDeprecated()
|
||||
|
||||
|
||||
+10
-2
@@ -21,8 +21,16 @@ class C {
|
||||
}
|
||||
}
|
||||
|
||||
@Anno("propery")
|
||||
val <T: Any> @receiver:Anno("receiver") List<T>.extensionProperty: Int
|
||||
@Anno("property")
|
||||
val <T: Any> @receiver:Anno("receiver") T.extensionProperty1: Int
|
||||
get() = 0
|
||||
|
||||
@Anno("property")
|
||||
val <T: Any> @receiver:Anno("receiver") List<T>.extensionProperty2: Int
|
||||
get() = 0
|
||||
|
||||
@Anno("property")
|
||||
val <X, Y: List<X>, Z: Map<X, Y>> @receiver:Anno("receiver") Z.extensionProperty3: Int
|
||||
get() = 0
|
||||
|
||||
@Anno("nullable")
|
||||
|
||||
+5
-1
@@ -53,7 +53,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ {
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
public static final java.lang.String getNullable();// getNullable()
|
||||
|
||||
public static final <T> int getExtensionProperty(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List<? extends T>);// <T> getExtensionProperty(java.util.List<? extends T>)
|
||||
public static final <T> int getExtensionProperty1(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() T);// <T> getExtensionProperty1(T)
|
||||
|
||||
public static final <T> int getExtensionProperty2(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() java.util.List<? extends T>);// <T> getExtensionProperty2(java.util.List<? extends T>)
|
||||
|
||||
public static final <X, Y extends java.util.List<? extends X>, Z extends java.util.Map<X, ? extends Y>> int getExtensionProperty3(@Anno(p = "receiver") @org.jetbrains.annotations.NotNull() Z);// <X, Y extends java.util.List<? extends X>, Z extends java.util.Map<X, ? extends Y>> getExtensionProperty3(Z)
|
||||
|
||||
public static final int getDeprecated();// getDeprecated()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user