K2: fix field annotation handling around serialization
#KT-57135 Fixed
This commit is contained in:
committed by
Space Team
parent
dc38ce24f7
commit
f6bf7560a6
+13
-2
@@ -11,10 +11,12 @@ import org.jetbrains.kotlin.fir.FirSession
|
|||||||
import org.jetbrains.kotlin.fir.containingClassForStaticMemberAttr
|
import org.jetbrains.kotlin.fir.containingClassForStaticMemberAttr
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.*
|
import org.jetbrains.kotlin.fir.declarations.builder.*
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.sourceElement
|
import org.jetbrains.kotlin.fir.declarations.utils.sourceElement
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionStub
|
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionStub
|
||||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||||
@@ -402,14 +404,23 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
|||||||
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
||||||
annotations +=
|
annotations +=
|
||||||
c.annotationDeserializer.loadPropertyAnnotations(c.containerSource, proto, classProto, local.nameResolver, local.typeTable)
|
c.annotationDeserializer.loadPropertyAnnotations(c.containerSource, proto, classProto, local.nameResolver, local.typeTable)
|
||||||
annotations +=
|
val backingFieldAnnotations = mutableListOf<FirAnnotation>()
|
||||||
|
backingFieldAnnotations +=
|
||||||
c.annotationDeserializer.loadPropertyBackingFieldAnnotations(
|
c.annotationDeserializer.loadPropertyBackingFieldAnnotations(
|
||||||
c.containerSource, proto, local.nameResolver, local.typeTable
|
c.containerSource, proto, local.nameResolver, local.typeTable
|
||||||
)
|
)
|
||||||
annotations +=
|
backingFieldAnnotations +=
|
||||||
c.annotationDeserializer.loadPropertyDelegatedFieldAnnotations(
|
c.annotationDeserializer.loadPropertyDelegatedFieldAnnotations(
|
||||||
c.containerSource, proto, local.nameResolver, local.typeTable
|
c.containerSource, proto, local.nameResolver, local.typeTable
|
||||||
)
|
)
|
||||||
|
backingField = FirDefaultPropertyBackingField(
|
||||||
|
c.moduleData,
|
||||||
|
backingFieldAnnotations,
|
||||||
|
returnTypeRef,
|
||||||
|
isVar,
|
||||||
|
symbol,
|
||||||
|
status
|
||||||
|
)
|
||||||
if (hasGetter) {
|
if (hasGetter) {
|
||||||
this.getter = loadPropertyGetter(
|
this.getter = loadPropertyGetter(
|
||||||
proto,
|
proto,
|
||||||
|
|||||||
+1
-1
@@ -331,7 +331,7 @@ class FirElementSerializer private constructor(
|
|||||||
var hasSetter = false
|
var hasSetter = false
|
||||||
|
|
||||||
val hasAnnotations = property.nonSourceAnnotations(session).isNotEmpty()
|
val hasAnnotations = property.nonSourceAnnotations(session).isNotEmpty()
|
||||||
// TODO: hasAnnotations(descriptor) || hasAnnotations(descriptor.backingField) || hasAnnotations(descriptor.delegateField)
|
|| property.backingField?.nonSourceAnnotations(session)?.isNotEmpty() == true
|
||||||
|
|
||||||
val modality = property.modality!!
|
val modality = property.modality!!
|
||||||
val defaultAccessorFlags = Flags.getAccessorFlags(
|
val defaultAccessorFlags = Flags.getAccessorFlags(
|
||||||
|
|||||||
+3
-5
@@ -59,20 +59,18 @@ abstract class FirSerializerExtensionBase(
|
|||||||
versionRequirementTable: MutableVersionRequirementTable?,
|
versionRequirementTable: MutableVersionRequirementTable?,
|
||||||
childSerializer: FirElementSerializer
|
childSerializer: FirElementSerializer
|
||||||
) {
|
) {
|
||||||
val regularPropertyAnnotations = mutableListOf<FirAnnotation>()
|
|
||||||
val fieldPropertyAnnotations = mutableListOf<FirAnnotation>()
|
val fieldPropertyAnnotations = mutableListOf<FirAnnotation>()
|
||||||
val delegatePropertyAnnotations = mutableListOf<FirAnnotation>()
|
val delegatePropertyAnnotations = mutableListOf<FirAnnotation>()
|
||||||
|
|
||||||
for (annotation in property.nonSourceAnnotations(session)) {
|
for (annotation in property.backingField?.nonSourceAnnotations(session).orEmpty()) {
|
||||||
val destination = when (annotation.useSiteTarget) {
|
val destination = when (annotation.useSiteTarget) {
|
||||||
AnnotationUseSiteTarget.FIELD -> fieldPropertyAnnotations
|
|
||||||
AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD -> delegatePropertyAnnotations
|
AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD -> delegatePropertyAnnotations
|
||||||
else -> regularPropertyAnnotations
|
else -> fieldPropertyAnnotations
|
||||||
}
|
}
|
||||||
destination += annotation
|
destination += annotation
|
||||||
}
|
}
|
||||||
|
|
||||||
regularPropertyAnnotations.serializeAnnotations(proto, protocol.propertyAnnotation)
|
property.nonSourceAnnotations(session).serializeAnnotations(proto, protocol.propertyAnnotation)
|
||||||
fieldPropertyAnnotations.serializeAnnotations(proto, protocol.propertyBackingFieldAnnotation)
|
fieldPropertyAnnotations.serializeAnnotations(proto, protocol.propertyBackingFieldAnnotation)
|
||||||
delegatePropertyAnnotations.serializeAnnotations(proto, protocol.propertyDelegatedFieldAnnotation)
|
delegatePropertyAnnotations.serializeAnnotations(proto, protocol.propertyDelegatedFieldAnnotation)
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -7,7 +7,7 @@ public final class Class : R|kotlin/Any| {
|
|||||||
public constructor(): R|test/Class|
|
public constructor(): R|test/Class|
|
||||||
|
|
||||||
public final companion object Companion : R|kotlin/Any| {
|
public final companion object Companion : R|kotlin/Any| {
|
||||||
@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ public final annotation class Anno : R|kotlin/Annotation| {
|
|||||||
public final class Class : R|kotlin/Any| {
|
public final class Class : R|kotlin/Any| {
|
||||||
@R|test/Anno|(t = R|java/lang/annotation/ElementType.METHOD|) public final fun foo(): R|kotlin/Unit|
|
@R|test/Anno|(t = R|java/lang/annotation/ElementType.METHOD|) public final fun foo(): R|kotlin/Unit|
|
||||||
|
|
||||||
@FIELD:R|test/Anno|(t = R|java/lang/annotation/ElementType.FIELD|) public final var bar: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|(t = R|java/lang/annotation/ElementType.FIELD|) public final var bar: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ public final annotation class Anno : R|kotlin/Annotation| {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class Class : R|kotlin/Any| {
|
public final class Class : R|kotlin/Any| {
|
||||||
@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
@FIELD:R|test/Anno|(t = R|java/lang/annotation/ElementType.FIELD|) public final val bar: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|(t = R|java/lang/annotation/ElementType.FIELD|) public final val bar: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
|
|
||||||
@R|test/Anno|(t = R|java/lang/annotation/ElementType.METHOD|) public final fun foo(): R|kotlin/Unit|
|
@R|test/Anno|(t = R|java/lang/annotation/ElementType.METHOD|) public final fun foo(): R|kotlin/Unit|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
@FIELD:R|test/Anno|(t = <implicitArrayOf>(R|java/lang/annotation/ElementType.PACKAGE|)) public final val bar: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|(t = <implicitArrayOf>(R|java/lang/annotation/ElementType.PACKAGE|)) public final val bar: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
|
|
||||||
@R|test/Anno|(t = <implicitArrayOf>()) public final fun baz(): R|kotlin/Unit|
|
@R|test/Anno|(t = <implicitArrayOf>()) public final fun baz(): R|kotlin/Unit|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
@FIELD:R|test/Anno|(t = <implicitArrayOf>(String(prosper))) public final val bar: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|(t = <implicitArrayOf>(String(prosper))) public final val bar: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
|
|
||||||
@R|test/Anno|(t = <implicitArrayOf>()) public final fun baz(): R|kotlin/Unit|
|
@R|test/Anno|(t = <implicitArrayOf>()) public final fun baz(): R|kotlin/Unit|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ public final annotation class Anno : R|kotlin/Annotation| {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class Class : R|kotlin/Any| {
|
public final class Class : R|kotlin/Any| {
|
||||||
@PROPERTY_DELEGATE_FIELD:R|test/Anno|() public final val property: R|kotlin/String|
|
field:@PROPERTY_DELEGATE_FIELD:R|test/Anno|() public final val property: R|kotlin/String|
|
||||||
public get(): R|kotlin/String|
|
public get(): R|kotlin/String|
|
||||||
|
|
||||||
public constructor(): R|test/Class|
|
public constructor(): R|test/Class|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ public final annotation class Anno : R|kotlin/Annotation| {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class Class : R|kotlin/Any| {
|
public final class Class : R|kotlin/Any| {
|
||||||
@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
field:@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
|
||||||
public get(): R|kotlin/Int|
|
public get(): R|kotlin/Int|
|
||||||
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
compiler/testData/loadJava/compiledKotlinWithStdlib/annotations/JvmFieldInInterfaceCompanion.fir.txt
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
public abstract interface I : R|kotlin/Any| {
|
public abstract interface I : R|kotlin/Any| {
|
||||||
public final companion object Companion : R|kotlin/Any| {
|
public final companion object Companion : R|kotlin/Any| {
|
||||||
@FIELD:R|kotlin/jvm/JvmField|() public final val x: R|kotlin/String|
|
field:@FIELD:R|kotlin/jvm/JvmField|() public final val x: R|kotlin/String|
|
||||||
public get(): R|kotlin/String|
|
public get(): R|kotlin/String|
|
||||||
|
|
||||||
@FIELD:R|kotlin/jvm/JvmField|() public final val y: R|kotlin/String|
|
field:@FIELD:R|kotlin/jvm/JvmField|() public final val y: R|kotlin/String|
|
||||||
public get(): R|kotlin/String|
|
public get(): R|kotlin/String|
|
||||||
|
|
||||||
private constructor(): R|test/I.Companion|
|
private constructor(): R|test/I.Companion|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
@R|test/A|(s = String(1)) @R|kotlin/jvm/JvmName|(name = String(bar)) public final fun foo(): R|kotlin/String|
|
@R|test/A|(s = String(1)) @R|kotlin/jvm/JvmName|(name = String(bar)) public final fun foo(): R|kotlin/String|
|
||||||
|
|
||||||
@FIELD:R|test/A|(s = String(2)) public final var v: R|kotlin/Int|
|
field:@FIELD:R|test/A|(s = String(2)) public final var v: R|kotlin/Int|
|
||||||
@R|test/A|(s = String(3)) @R|kotlin/jvm/JvmName|(name = String(vget)) public get(): R|kotlin/Int|
|
@R|test/A|(s = String(3)) @R|kotlin/jvm/JvmName|(name = String(vget)) public get(): R|kotlin/Int|
|
||||||
@R|test/A|(s = String(4)) @R|kotlin/jvm/JvmName|(name = String(vset)) public set(<set-?>: R|kotlin/Int|): R|kotlin/Unit|
|
@R|test/A|(s = String(4)) @R|kotlin/jvm/JvmName|(name = String(vset)) public set(<set-?>: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
@R|test/A|(s = String(1)) @R|kotlin/jvm/JvmName|(name = String(bar)) public final fun foo(): R|kotlin/String|
|
@R|test/A|(s = String(1)) @R|kotlin/jvm/JvmName|(name = String(bar)) public final fun foo(): R|kotlin/String|
|
||||||
|
|
||||||
@FIELD:R|test/A|(s = String(2)) public final var v: R|kotlin/Int|
|
field:@FIELD:R|test/A|(s = String(2)) public final var v: R|kotlin/Int|
|
||||||
@R|test/A|(s = String(3)) @R|kotlin/jvm/JvmName|(name = String(vget)) public get(): R|kotlin/Int|
|
@R|test/A|(s = String(3)) @R|kotlin/jvm/JvmName|(name = String(vget)) public get(): R|kotlin/Int|
|
||||||
@R|test/A|(s = String(4)) @R|kotlin/jvm/JvmName|(name = String(vset)) public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
@R|test/A|(s = String(4)) @R|kotlin/jvm/JvmName|(name = String(vset)) public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user