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.modifierLists.SymbolLightMemberModifierList
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightParameterForReceiver
|
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.SymbolLightParameterList
|
||||||
|
import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightTypeParameterList
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
|
||||||
|
|
||||||
internal class SymbolLightAnnotationsMethod private constructor(
|
internal class SymbolLightAnnotationsMethod private constructor(
|
||||||
lightMemberOrigin: LightMemberOrigin?,
|
lightMemberOrigin: LightMemberOrigin?,
|
||||||
@@ -126,14 +128,29 @@ internal class SymbolLightAnnotationsMethod private constructor(
|
|||||||
override fun getTypeParameterList(): PsiTypeParameterList? = null
|
override fun getTypeParameterList(): PsiTypeParameterList? = null
|
||||||
override fun getTypeParameters(): Array<PsiTypeParameter> = PsiTypeParameter.EMPTY_ARRAY
|
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 {
|
private val _parametersList by lazyPub {
|
||||||
SymbolLightParameterList(
|
SymbolLightParameterList(
|
||||||
parent = this@SymbolLightAnnotationsMethod,
|
parent = this@SymbolLightAnnotationsMethod,
|
||||||
parameterPopulator = { builder ->
|
parameterPopulator = { builder ->
|
||||||
SymbolLightParameterForReceiver.tryGet(
|
SymbolLightParameterForReceiver.tryGet(
|
||||||
callableSymbolPointer = containingPropertySymbolPointer,
|
callableSymbolPointer = containingPropertySymbolPointer,
|
||||||
method = this@SymbolLightAnnotationsMethod,
|
method = this@SymbolLightAnnotationsMethod
|
||||||
forPropertyAnnotations = true
|
|
||||||
)?.let(builder::addParameter)
|
)?.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.descriptors.annotations.AnnotationUseSiteTarget
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.*
|
import org.jetbrains.kotlin.light.classes.symbol.*
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.*
|
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.methods.SymbolLightMethodBase
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList
|
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList
|
||||||
import org.jetbrains.kotlin.psi.KtParameter
|
import org.jetbrains.kotlin.psi.KtParameter
|
||||||
@@ -27,7 +28,6 @@ internal class SymbolLightParameterForReceiver private constructor(
|
|||||||
private val receiverPointer: KtSymbolPointer<KtReceiverParameterSymbol>,
|
private val receiverPointer: KtSymbolPointer<KtReceiverParameterSymbol>,
|
||||||
methodName: String,
|
methodName: String,
|
||||||
method: SymbolLightMethodBase,
|
method: SymbolLightMethodBase,
|
||||||
private val forPropertyAnnotations: Boolean
|
|
||||||
) : SymbolLightParameterBase(method) {
|
) : SymbolLightParameterBase(method) {
|
||||||
private inline fun <T> withReceiverSymbol(crossinline action: context(KtAnalysisSession) (KtReceiverParameterSymbol) -> T): T =
|
private inline fun <T> withReceiverSymbol(crossinline action: context(KtAnalysisSession) (KtReceiverParameterSymbol) -> T): T =
|
||||||
receiverPointer.withSymbol(ktModule, action)
|
receiverPointer.withSymbol(ktModule, action)
|
||||||
@@ -35,8 +35,7 @@ internal class SymbolLightParameterForReceiver private constructor(
|
|||||||
companion object {
|
companion object {
|
||||||
fun tryGet(
|
fun tryGet(
|
||||||
callableSymbolPointer: KtSymbolPointer<KtCallableSymbol>,
|
callableSymbolPointer: KtSymbolPointer<KtCallableSymbol>,
|
||||||
method: SymbolLightMethodBase,
|
method: SymbolLightMethodBase
|
||||||
forPropertyAnnotations: Boolean = false
|
|
||||||
): SymbolLightParameterForReceiver? = callableSymbolPointer.withSymbol(method.ktModule) { callableSymbol ->
|
): SymbolLightParameterForReceiver? = callableSymbolPointer.withSymbol(method.ktModule) { callableSymbol ->
|
||||||
if (callableSymbol !is KtNamedSymbol) return@withSymbol null
|
if (callableSymbol !is KtNamedSymbol) return@withSymbol null
|
||||||
if (!callableSymbol.isExtension) return@withSymbol null
|
if (!callableSymbol.isExtension) return@withSymbol null
|
||||||
@@ -46,13 +45,12 @@ internal class SymbolLightParameterForReceiver private constructor(
|
|||||||
receiverPointer = receiverSymbol.createPointer(),
|
receiverPointer = receiverSymbol.createPointer(),
|
||||||
methodName = callableSymbol.name.asString(),
|
methodName = callableSymbol.name.asString(),
|
||||||
method = method,
|
method = method,
|
||||||
forPropertyAnnotations = forPropertyAnnotations,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _name: String by lazyPub {
|
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
|
override fun getNameIdentifier(): PsiIdentifier? = null
|
||||||
@@ -67,7 +65,7 @@ internal class SymbolLightParameterForReceiver private constructor(
|
|||||||
override fun getModifierList(): PsiModifierList = _modifierList
|
override fun getModifierList(): PsiModifierList = _modifierList
|
||||||
|
|
||||||
private val _modifierList: PsiModifierList by lazyPub {
|
private val _modifierList: PsiModifierList by lazyPub {
|
||||||
if (forPropertyAnnotations)
|
if (method is SymbolLightAnnotationsMethod)
|
||||||
SymbolLightClassModifierList(containingDeclaration = this)
|
SymbolLightClassModifierList(containingDeclaration = this)
|
||||||
else SymbolLightClassModifierList(
|
else SymbolLightClassModifierList(
|
||||||
containingDeclaration = this,
|
containingDeclaration = this,
|
||||||
@@ -92,7 +90,16 @@ internal class SymbolLightParameterForReceiver private constructor(
|
|||||||
val psiType = ktType.asPsiTypeElement(this, allowErrorTypes = true)?.let {
|
val psiType = ktType.asPsiTypeElement(this, allowErrorTypes = true)?.let {
|
||||||
annotateByKtType(it.type, ktType, it, modifierList)
|
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()
|
} ?: nonExistentType()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +108,6 @@ internal class SymbolLightParameterForReceiver private constructor(
|
|||||||
override fun equals(other: Any?): Boolean = this === other ||
|
override fun equals(other: Any?): Boolean = this === other ||
|
||||||
other is SymbolLightParameterForReceiver &&
|
other is SymbolLightParameterForReceiver &&
|
||||||
ktModule == other.ktModule &&
|
ktModule == other.ktModule &&
|
||||||
forPropertyAnnotations == other.forPropertyAnnotations &&
|
|
||||||
compareSymbolPointers(receiverPointer, other.receiverPointer)
|
compareSymbolPointers(receiverPointer, other.receiverPointer)
|
||||||
|
|
||||||
override fun hashCode(): Int = _name.hashCode()
|
override fun hashCode(): Int = _name.hashCode()
|
||||||
|
|||||||
+15
-3
@@ -74,9 +74,17 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ {
|
|||||||
@java.lang.Deprecated()
|
@java.lang.Deprecated()
|
||||||
public static void getNullable$annotations();// getNullable$annotations()
|
public static void getNullable$annotations();// getNullable$annotations()
|
||||||
|
|
||||||
@Anno(p = "propery")
|
@Anno(p = "property")
|
||||||
@java.lang.Deprecated()
|
@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()
|
@java.lang.Deprecated()
|
||||||
@kotlin.Deprecated(message = "deprecated")
|
@kotlin.Deprecated(message = "deprecated")
|
||||||
@@ -88,7 +96,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ {
|
|||||||
@org.jetbrains.annotations.Nullable()
|
@org.jetbrains.annotations.Nullable()
|
||||||
public static final java.lang.String getNullable();// getNullable()
|
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()
|
public static final int getDeprecated();// getDeprecated()
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -55,7 +55,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ {
|
|||||||
@org.jetbrains.annotations.Nullable()
|
@org.jetbrains.annotations.Nullable()
|
||||||
public static final java.lang.String getNullable();// getNullable()
|
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()
|
public static final int getDeprecated();// getDeprecated()
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -21,8 +21,16 @@ class C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Anno("propery")
|
@Anno("property")
|
||||||
val <T: Any> @receiver:Anno("receiver") List<T>.extensionProperty: Int
|
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
|
get() = 0
|
||||||
|
|
||||||
@Anno("nullable")
|
@Anno("nullable")
|
||||||
|
|||||||
+5
-1
@@ -53,7 +53,11 @@ public final class PropertyAnnotationsKt /* PropertyAnnotationsKt*/ {
|
|||||||
@org.jetbrains.annotations.Nullable()
|
@org.jetbrains.annotations.Nullable()
|
||||||
public static final java.lang.String getNullable();// getNullable()
|
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()
|
public static final int getDeprecated();// getDeprecated()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user