FIR: more precise annotation argument serialization
This commit is contained in:
committed by
teamcityserver
parent
491267b4f7
commit
3127fad23d
+17
-4
@@ -7,11 +7,13 @@ package org.jetbrains.kotlin.fir.serialization
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.impl.FirResolvedArgumentList
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.serialization.constant.ConstantValue
|
import org.jetbrains.kotlin.fir.serialization.constant.ConstantValue
|
||||||
import org.jetbrains.kotlin.fir.serialization.constant.toConstantValue
|
import org.jetbrains.kotlin.fir.serialization.constant.toConstantValue
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||||
|
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 {
|
||||||
@@ -20,13 +22,24 @@ class FirAnnotationSerializer(private val session: FirSession, internal val stri
|
|||||||
|
|
||||||
id = stringTable.getFqNameIndex(annotationClass)
|
id = stringTable.getFqNameIndex(annotationClass)
|
||||||
|
|
||||||
for (argumentExpression in annotation.argumentList.arguments) {
|
fun addArgument(argumentExpression: FirExpression, parameterName: Name) {
|
||||||
if (argumentExpression !is FirNamedArgumentExpression) continue
|
|
||||||
val argument = ProtoBuf.Annotation.Argument.newBuilder()
|
val argument = ProtoBuf.Annotation.Argument.newBuilder()
|
||||||
argument.nameId = stringTable.getStringIndex(argumentExpression.name.asString())
|
argument.nameId = stringTable.getStringIndex(parameterName.asString())
|
||||||
argument.setValue(valueProto(argumentExpression.toConstantValue() ?: continue))
|
argument.setValue(valueProto(argumentExpression.toConstantValue() ?: return))
|
||||||
addArgument(argument)
|
addArgument(argument)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val argumentList = annotation.argumentList
|
||||||
|
if (argumentList is FirResolvedArgumentList) {
|
||||||
|
for ((argumentExpression, parameter) in argumentList.mapping) {
|
||||||
|
addArgument(argumentExpression, parameter.name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (argumentExpression in argumentList.arguments) {
|
||||||
|
if (argumentExpression !is FirNamedArgumentExpression) continue
|
||||||
|
addArgument(argumentExpression, argumentExpression.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
internal fun valueProto(constant: ConstantValue<*>): ProtoBuf.Annotation.Argument.Value.Builder =
|
internal fun valueProto(constant: ConstantValue<*>): ProtoBuf.Annotation.Argument.Value.Builder =
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// EMIT_JVM_TYPE_ANNOTATIONS
|
// EMIT_JVM_TYPE_ANNOTATIONS
|
||||||
// JVM_TARGET: 1.8
|
// JVM_TARGET: 1.8
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// EMIT_JVM_TYPE_ANNOTATIONS
|
// EMIT_JVM_TYPE_ANNOTATIONS
|
||||||
// JVM_TARGET: 1.8
|
// JVM_TARGET: 1.8
|
||||||
|
|||||||
Reference in New Issue
Block a user