[FIR] Don't fail on serialization of annotations which are not lays on classpath

This commit is contained in:
Dmitriy Novozhilov
2021-08-31 12:19:33 +03:00
committed by TeamCityServer
parent ed0b65e19c
commit f85c137360
@@ -17,10 +17,11 @@ import org.jetbrains.kotlin.name.Name
class FirAnnotationSerializer(private val session: FirSession, internal val stringTable: FirElementAwareStringTable) { class FirAnnotationSerializer(private val session: FirSession, internal val stringTable: FirElementAwareStringTable) {
fun serializeAnnotation(annotation: FirAnnotationCall): ProtoBuf.Annotation = ProtoBuf.Annotation.newBuilder().apply { fun serializeAnnotation(annotation: FirAnnotationCall): ProtoBuf.Annotation = ProtoBuf.Annotation.newBuilder().apply {
val annotationSymbol = annotation.typeRef.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.toSymbol(session) val lookupTag = annotation.typeRef.coneTypeSafe<ConeClassLikeType>()?.lookupTag
val annotationClass = annotationSymbol?.fir ?: error("Annotation type is not a class: ${annotationSymbol?.fir}") ?: error { "Annotation without proper lookup tag: ${annotation.annotationTypeRef.coneType}" }
id = stringTable.getFqNameIndex(annotationClass) id = lookupTag.toSymbol(session)?.let { stringTable.getFqNameIndex(it.fir) }
?: stringTable.getQualifiedClassNameIndex(lookupTag.classId)
fun addArgument(argumentExpression: FirExpression, parameterName: Name) { fun addArgument(argumentExpression: FirExpression, parameterName: Name) {
val argument = ProtoBuf.Annotation.Argument.newBuilder() val argument = ProtoBuf.Annotation.Argument.newBuilder()