[FIR] Make toAnnotationLookupTag() return null for generic annotations

This commit is contained in:
Nikolay Lunyak
2021-08-03 14:50:26 +03:00
parent 1a3f47badd
commit 4f2eb8b955
3 changed files with 8 additions and 7 deletions
@@ -837,7 +837,7 @@ class FirElementSerializer private constructor(
private fun MutableVersionRequirementTable.serializeVersionRequirements(annotations: List<FirAnnotationCall>): List<Int> = private fun MutableVersionRequirementTable.serializeVersionRequirements(annotations: List<FirAnnotationCall>): List<Int> =
annotations annotations
.filter { .filter {
it.toAnnotationClassId().asSingleFqName() == RequireKotlinConstants.FQ_NAME it.toAnnotationClassId()?.asSingleFqName() == RequireKotlinConstants.FQ_NAME
} }
.mapNotNull(::serializeVersionRequirementFromRequireKotlin) .mapNotNull(::serializeVersionRequirementFromRequireKotlin)
.map(::get) .map(::get)
@@ -26,14 +26,15 @@ private val RETENTION_CLASS_ID = ClassId.fromString("kotlin/annotation/Retention
private val TARGET_CLASS_ID = ClassId.fromString("kotlin/annotation/Target") private val TARGET_CLASS_ID = ClassId.fromString("kotlin/annotation/Target")
private val JVM_FIELD_CLASS_ID = ClassId.fromString("kotlin/jvm/JvmField") private val JVM_FIELD_CLASS_ID = ClassId.fromString("kotlin/jvm/JvmField")
private fun FirAnnotationCall.toAnnotationLookupTag(): ConeClassLikeLookupTag = private fun FirAnnotationCall.toAnnotationLookupTag(): ConeClassLikeLookupTag? =
(annotationTypeRef.coneType as ConeClassLikeType).lookupTag // this cast fails when we have generic-typed annotations @T
(annotationTypeRef.coneType as? ConeClassLikeType)?.lookupTag
fun FirAnnotationCall.toAnnotationClassId(): ClassId = fun FirAnnotationCall.toAnnotationClassId(): ClassId? =
toAnnotationLookupTag().classId toAnnotationLookupTag()?.classId
private fun FirAnnotationCall.toAnnotationClass(session: FirSession): FirRegularClass? = private fun FirAnnotationCall.toAnnotationClass(session: FirSession): FirRegularClass? =
toAnnotationLookupTag().toSymbol(session)?.fir as? FirRegularClass toAnnotationLookupTag()?.toSymbol(session)?.fir as? FirRegularClass
// TODO: this is temporary solution, we need something better // TODO: this is temporary solution, we need something better
private val FirExpression.callableNameOfMetaAnnotationArgument: Name? private val FirExpression.callableNameOfMetaAnnotationArgument: Name?
@@ -28,7 +28,7 @@ internal fun StringBuilder.renderAnnotations(
} }
private fun FirAnnotationCall.isParameterName(): Boolean { private fun FirAnnotationCall.isParameterName(): Boolean {
return toAnnotationClassId().asSingleFqName() == StandardNames.FqNames.parameterName return toAnnotationClassId()?.asSingleFqName() == StandardNames.FqNames.parameterName
} }
private fun renderAnnotation(annotation: FirAnnotationCall, coneTypeIdeRenderer: ConeTypeIdeRenderer, session: FirSession): String { private fun renderAnnotation(annotation: FirAnnotationCall, coneTypeIdeRenderer: ConeTypeIdeRenderer, session: FirSession): String {