From 1ee1d15b91ba302fb22c5ebd919605b2def9e450 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 1 Oct 2018 18:34:04 +0200 Subject: [PATCH] Support annotations on property accessors in JS/common metadata #KT-14529 Fixed --- .../incremental/ProtoCompareGenerated.kt | 52 ++++++++ .../builtins/DebugBuiltInsProtoBuf.java | 74 ++++++++---- .../kotlin/metadata/js/DebugJsProtoBuf.java | 88 +++++++++----- .../metadata/konan/DebugKonanProtoBuf.java | 112 +++++++++++------- .../kotlin/psi/stubs/KotlinStubVersions.kt | 4 +- .../serialization/SerializerExtensionBase.kt | 6 + .../propertyAccessorAnnotations.kt | 10 ++ .../propertyAccessorAnnotations.txt | 9 ++ .../builtins/BuiltInsSerializerTest.kt | 4 + .../js/KotlinJavascriptSerializerTest.kt | 4 + .../utils/KotlinJavascriptMetadataUtils.kt | 2 +- .../SerializerExtensionProtocol.kt | 2 + .../AnnotationAndConstantLoaderImpl.kt | 7 +- .../builtins/BuiltInSerializerProtocol.kt | 16 ++- core/metadata/src/builtins.proto | 2 + .../builtins/BuiltInsBinaryVersion.kt | 2 +- .../metadata/builtins/BuiltInsProtoBuf.java | 34 ++++++ .../AnnotationLoaderForStubBuilderImpl.kt | 7 +- js/js.serializer/src/js.proto | 2 + .../kotlin/metadata/js/JsProtoBuf.java | 34 ++++++ .../serialization/js/JsSerializerProtocol.kt | 10 +- .../js/test/semantics/BoxJsTestGenerated.java | 5 + .../test/semantics/IrBoxJsTestGenerated.java | 5 + .../jsName/propertyAccessorFromOtherModule.kt | 18 +++ konan/library-reader/src/konan.proto | 2 + .../kotlin/metadata/konan/KonanProtoBuf.java | 34 ++++++ .../konan/KonanSerializerProtocol.kt | 4 +- 27 files changed, 443 insertions(+), 106 deletions(-) create mode 100644 compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.kt create mode 100644 compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.txt create mode 100644 js/js.translator/testData/box/jsName/propertyAccessorFromOtherModule.kt diff --git a/build-common/src/org/jetbrains/kotlin/incremental/ProtoCompareGenerated.kt b/build-common/src/org/jetbrains/kotlin/incremental/ProtoCompareGenerated.kt index 377ebf451b8..e6a9cd0ee3d 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/ProtoCompareGenerated.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/ProtoCompareGenerated.kt @@ -522,6 +522,24 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR } } + if (old.getExtensionCount(JsProtoBuf.propertyGetterAnnotation) != new.getExtensionCount(JsProtoBuf.propertyGetterAnnotation)) { + return false + } + else { + for(i in 0..old.getExtensionCount(JsProtoBuf.propertyGetterAnnotation) - 1) { + if (!checkEquals(old.getExtension(JsProtoBuf.propertyGetterAnnotation, i), new.getExtension(JsProtoBuf.propertyGetterAnnotation, i))) return false + } + } + + if (old.getExtensionCount(JsProtoBuf.propertySetterAnnotation) != new.getExtensionCount(JsProtoBuf.propertySetterAnnotation)) { + return false + } + else { + for(i in 0..old.getExtensionCount(JsProtoBuf.propertySetterAnnotation) - 1) { + if (!checkEquals(old.getExtension(JsProtoBuf.propertySetterAnnotation, i), new.getExtension(JsProtoBuf.propertySetterAnnotation, i))) return false + } + } + if (old.hasExtension(JsProtoBuf.compileTimeValue) != new.hasExtension(JsProtoBuf.compileTimeValue)) return false if (old.hasExtension(JsProtoBuf.compileTimeValue)) { if (!checkEquals(old.getExtension(JsProtoBuf.compileTimeValue), new.getExtension(JsProtoBuf.compileTimeValue))) return false @@ -551,6 +569,24 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR } } + if (old.getExtensionCount(BuiltInsProtoBuf.propertyGetterAnnotation) != new.getExtensionCount(BuiltInsProtoBuf.propertyGetterAnnotation)) { + return false + } + else { + for(i in 0..old.getExtensionCount(BuiltInsProtoBuf.propertyGetterAnnotation) - 1) { + if (!checkEquals(old.getExtension(BuiltInsProtoBuf.propertyGetterAnnotation, i), new.getExtension(BuiltInsProtoBuf.propertyGetterAnnotation, i))) return false + } + } + + if (old.getExtensionCount(BuiltInsProtoBuf.propertySetterAnnotation) != new.getExtensionCount(BuiltInsProtoBuf.propertySetterAnnotation)) { + return false + } + else { + for(i in 0..old.getExtensionCount(BuiltInsProtoBuf.propertySetterAnnotation) - 1) { + if (!checkEquals(old.getExtension(BuiltInsProtoBuf.propertySetterAnnotation, i), new.getExtension(BuiltInsProtoBuf.propertySetterAnnotation, i))) return false + } + } + if (old.hasExtension(BuiltInsProtoBuf.compileTimeValue) != new.hasExtension(BuiltInsProtoBuf.compileTimeValue)) return false if (old.hasExtension(BuiltInsProtoBuf.compileTimeValue)) { if (!checkEquals(old.getExtension(BuiltInsProtoBuf.compileTimeValue), new.getExtension(BuiltInsProtoBuf.compileTimeValue))) return false @@ -1779,6 +1815,14 @@ fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) hashCode = 31 * hashCode + getExtension(JsProtoBuf.propertyAnnotation, i).hashCode(stringIndexes, fqNameIndexes) } + for(i in 0..getExtensionCount(JsProtoBuf.propertyGetterAnnotation) - 1) { + hashCode = 31 * hashCode + getExtension(JsProtoBuf.propertyGetterAnnotation, i).hashCode(stringIndexes, fqNameIndexes) + } + + for(i in 0..getExtensionCount(JsProtoBuf.propertySetterAnnotation) - 1) { + hashCode = 31 * hashCode + getExtension(JsProtoBuf.propertySetterAnnotation, i).hashCode(stringIndexes, fqNameIndexes) + } + if (hasExtension(JsProtoBuf.compileTimeValue)) { hashCode = 31 * hashCode + getExtension(JsProtoBuf.compileTimeValue).hashCode(stringIndexes, fqNameIndexes) } @@ -1799,6 +1843,14 @@ fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.propertyAnnotation, i).hashCode(stringIndexes, fqNameIndexes) } + for(i in 0..getExtensionCount(BuiltInsProtoBuf.propertyGetterAnnotation) - 1) { + hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.propertyGetterAnnotation, i).hashCode(stringIndexes, fqNameIndexes) + } + + for(i in 0..getExtensionCount(BuiltInsProtoBuf.propertySetterAnnotation) - 1) { + hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.propertySetterAnnotation, i).hashCode(stringIndexes, fqNameIndexes) + } + if (hasExtension(BuiltInsProtoBuf.compileTimeValue)) { hashCode = 31 * hashCode + getExtension(BuiltInsProtoBuf.compileTimeValue).hashCode(stringIndexes, fqNameIndexes) } diff --git a/build-common/test/org/jetbrains/kotlin/metadata/builtins/DebugBuiltInsProtoBuf.java b/build-common/test/org/jetbrains/kotlin/metadata/builtins/DebugBuiltInsProtoBuf.java index 754d1e23696..a35b6f14e40 100644 --- a/build-common/test/org/jetbrains/kotlin/metadata/builtins/DebugBuiltInsProtoBuf.java +++ b/build-common/test/org/jetbrains/kotlin/metadata/builtins/DebugBuiltInsProtoBuf.java @@ -12,6 +12,8 @@ public final class DebugBuiltInsProtoBuf { registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.constructorAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.functionAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.propertyAnnotation); + registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.propertyGetterAnnotation); + registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.propertySetterAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.compileTimeValue); registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.enumEntryAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.DebugBuiltInsProtoBuf.parameterAnnotation); @@ -73,6 +75,28 @@ public final class DebugBuiltInsProtoBuf { .newFileScopedGeneratedExtension( org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); + public static final int PROPERTY_GETTER_ANNOTATION_FIELD_NUMBER = 152; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessage.GeneratedExtension< + org.jetbrains.kotlin.metadata.DebugProtoBuf.Property, + java.util.List> propertyGetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); + public static final int PROPERTY_SETTER_ANNOTATION_FIELD_NUMBER = 153; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessage.GeneratedExtension< + org.jetbrains.kotlin.metadata.DebugProtoBuf.Property, + java.util.List> propertySetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); public static final int COMPILE_TIME_VALUE_FIELD_NUMBER = 151; /** * extend .org.jetbrains.kotlin.metadata.Property { ... } @@ -153,22 +177,28 @@ public final class DebugBuiltInsProtoBuf { "notation:p\n\023property_annotation\022\'.org.je" + "tbrains.kotlin.metadata.Property\030\226\001 \003(\0132" + ").org.jetbrains.kotlin.metadata.Annotati" + - "on:~\n\022compile_time_value\022\'.org.jetbrains" + - ".kotlin.metadata.Property\030\227\001 \001(\01328.org.j" + - "etbrains.kotlin.metadata.Annotation.Argu" + - "ment.Value:s\n\025enum_entry_annotation\022(.or", - "g.jetbrains.kotlin.metadata.EnumEntry\030\226\001" + - " \003(\0132).org.jetbrains.kotlin.metadata.Ann" + - "otation:w\n\024parameter_annotation\022-.org.je" + - "tbrains.kotlin.metadata.ValueParameter\030\226" + - "\001 \003(\0132).org.jetbrains.kotlin.metadata.An" + - "notation:h\n\017type_annotation\022#.org.jetbra" + - "ins.kotlin.metadata.Type\030\226\001 \003(\0132).org.je" + - "tbrains.kotlin.metadata.Annotation:{\n\031ty" + - "pe_parameter_annotation\022,.org.jetbrains." + - "kotlin.metadata.TypeParameter\030\226\001 \003(\0132).o", - "rg.jetbrains.kotlin.metadata.AnnotationB" + - "\027B\025DebugBuiltInsProtoBuf" + "on:w\n\032property_getter_annotation\022\'.org.j" + + "etbrains.kotlin.metadata.Property\030\230\001 \003(\013" + + "2).org.jetbrains.kotlin.metadata.Annotat" + + "ion:w\n\032property_setter_annotation\022\'.org.", + "jetbrains.kotlin.metadata.Property\030\231\001 \003(" + + "\0132).org.jetbrains.kotlin.metadata.Annota" + + "tion:~\n\022compile_time_value\022\'.org.jetbrai" + + "ns.kotlin.metadata.Property\030\227\001 \001(\01328.org" + + ".jetbrains.kotlin.metadata.Annotation.Ar" + + "gument.Value:s\n\025enum_entry_annotation\022(." + + "org.jetbrains.kotlin.metadata.EnumEntry\030" + + "\226\001 \003(\0132).org.jetbrains.kotlin.metadata.A" + + "nnotation:w\n\024parameter_annotation\022-.org." + + "jetbrains.kotlin.metadata.ValueParameter", + "\030\226\001 \003(\0132).org.jetbrains.kotlin.metadata." + + "Annotation:h\n\017type_annotation\022#.org.jetb" + + "rains.kotlin.metadata.Type\030\226\001 \003(\0132).org." + + "jetbrains.kotlin.metadata.Annotation:{\n\031" + + "type_parameter_annotation\022,.org.jetbrain" + + "s.kotlin.metadata.TypeParameter\030\226\001 \003(\0132)" + + ".org.jetbrains.kotlin.metadata.Annotatio" + + "nB\027B\025DebugBuiltInsProtoBuf" }; org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { @@ -188,11 +218,13 @@ public final class DebugBuiltInsProtoBuf { constructorAnnotation.internalInit(descriptor.getExtensions().get(2)); functionAnnotation.internalInit(descriptor.getExtensions().get(3)); propertyAnnotation.internalInit(descriptor.getExtensions().get(4)); - compileTimeValue.internalInit(descriptor.getExtensions().get(5)); - enumEntryAnnotation.internalInit(descriptor.getExtensions().get(6)); - parameterAnnotation.internalInit(descriptor.getExtensions().get(7)); - typeAnnotation.internalInit(descriptor.getExtensions().get(8)); - typeParameterAnnotation.internalInit(descriptor.getExtensions().get(9)); + propertyGetterAnnotation.internalInit(descriptor.getExtensions().get(5)); + propertySetterAnnotation.internalInit(descriptor.getExtensions().get(6)); + compileTimeValue.internalInit(descriptor.getExtensions().get(7)); + enumEntryAnnotation.internalInit(descriptor.getExtensions().get(8)); + parameterAnnotation.internalInit(descriptor.getExtensions().get(9)); + typeAnnotation.internalInit(descriptor.getExtensions().get(10)); + typeParameterAnnotation.internalInit(descriptor.getExtensions().get(11)); org.jetbrains.kotlin.metadata.DebugProtoBuf.getDescriptor(); } diff --git a/build-common/test/org/jetbrains/kotlin/metadata/js/DebugJsProtoBuf.java b/build-common/test/org/jetbrains/kotlin/metadata/js/DebugJsProtoBuf.java index 7cf870b9ab5..f6c683ab890 100644 --- a/build-common/test/org/jetbrains/kotlin/metadata/js/DebugJsProtoBuf.java +++ b/build-common/test/org/jetbrains/kotlin/metadata/js/DebugJsProtoBuf.java @@ -14,6 +14,8 @@ public final class DebugJsProtoBuf { registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.functionAnnotation); registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.functionContainingFileId); registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.propertyAnnotation); + registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.propertyGetterAnnotation); + registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.propertySetterAnnotation); registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.compileTimeValue); registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.propertyContainingFileId); registry.add(org.jetbrains.kotlin.metadata.js.DebugJsProtoBuf.enumEntryAnnotation); @@ -4752,6 +4754,28 @@ public final class DebugJsProtoBuf { .newFileScopedGeneratedExtension( org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); + public static final int PROPERTY_GETTER_ANNOTATION_FIELD_NUMBER = 132; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessage.GeneratedExtension< + org.jetbrains.kotlin.metadata.DebugProtoBuf.Property, + java.util.List> propertyGetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); + public static final int PROPERTY_SETTER_ANNOTATION_FIELD_NUMBER = 133; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessage.GeneratedExtension< + org.jetbrains.kotlin.metadata.DebugProtoBuf.Property, + java.util.List> propertySetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); public static final int COMPILE_TIME_VALUE_FIELD_NUMBER = 131; /** * extend .org.jetbrains.kotlin.metadata.Property { ... } @@ -4900,27 +4924,33 @@ public final class DebugJsProtoBuf { "ion\030\207\001 \001(\005:p\n\023property_annotation\022\'.org." + "jetbrains.kotlin.metadata.Property\030\202\001 \003(" + "\0132).org.jetbrains.kotlin.metadata.Annota" + - "tion:~\n\022compile_time_value\022\'.org.jetbrai" + - "ns.kotlin.metadata.Property\030\203\001 \001(\01328.org" + - ".jetbrains.kotlin.metadata.Annotation.Ar", - "gument.Value:M\n\033property_containing_file" + - "_id\022\'.org.jetbrains.kotlin.metadata.Prop" + - "erty\030\207\001 \001(\005:s\n\025enum_entry_annotation\022(.o" + - "rg.jetbrains.kotlin.metadata.EnumEntry\030\202" + - "\001 \003(\0132).org.jetbrains.kotlin.metadata.An" + - "notation:w\n\024parameter_annotation\022-.org.j" + - "etbrains.kotlin.metadata.ValueParameter\030" + - "\202\001 \003(\0132).org.jetbrains.kotlin.metadata.A" + - "nnotation:h\n\017type_annotation\022#.org.jetbr" + - "ains.kotlin.metadata.Type\030\202\001 \003(\0132).org.j", - "etbrains.kotlin.metadata.Annotation:{\n\031t" + - "ype_parameter_annotation\022,.org.jetbrains" + - ".kotlin.metadata.TypeParameter\030\202\001 \003(\0132)." + - "org.jetbrains.kotlin.metadata.Annotation" + - ":x\n\026package_fragment_files\022..org.jetbrai" + - "ns.kotlin.metadata.PackageFragment\030\202\001 \001(" + - "\0132\'.org.jetbrains.kotlin.metadata.js.Fil" + - "esB\021B\017DebugJsProtoBuf" + "tion:w\n\032property_getter_annotation\022\'.org" + + ".jetbrains.kotlin.metadata.Property\030\204\001 \003" + + "(\0132).org.jetbrains.kotlin.metadata.Annot", + "ation:w\n\032property_setter_annotation\022\'.or" + + "g.jetbrains.kotlin.metadata.Property\030\205\001 " + + "\003(\0132).org.jetbrains.kotlin.metadata.Anno" + + "tation:~\n\022compile_time_value\022\'.org.jetbr" + + "ains.kotlin.metadata.Property\030\203\001 \001(\01328.o" + + "rg.jetbrains.kotlin.metadata.Annotation." + + "Argument.Value:M\n\033property_containing_fi" + + "le_id\022\'.org.jetbrains.kotlin.metadata.Pr" + + "operty\030\207\001 \001(\005:s\n\025enum_entry_annotation\022(" + + ".org.jetbrains.kotlin.metadata.EnumEntry", + "\030\202\001 \003(\0132).org.jetbrains.kotlin.metadata." + + "Annotation:w\n\024parameter_annotation\022-.org" + + ".jetbrains.kotlin.metadata.ValueParamete" + + "r\030\202\001 \003(\0132).org.jetbrains.kotlin.metadata" + + ".Annotation:h\n\017type_annotation\022#.org.jet" + + "brains.kotlin.metadata.Type\030\202\001 \003(\0132).org" + + ".jetbrains.kotlin.metadata.Annotation:{\n" + + "\031type_parameter_annotation\022,.org.jetbrai" + + "ns.kotlin.metadata.TypeParameter\030\202\001 \003(\0132" + + ").org.jetbrains.kotlin.metadata.Annotati", + "on:x\n\026package_fragment_files\022..org.jetbr" + + "ains.kotlin.metadata.PackageFragment\030\202\001 " + + "\001(\0132\'.org.jetbrains.kotlin.metadata.js.F" + + "ilesB\021B\017DebugJsProtoBuf" }; org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { @@ -4972,13 +5002,15 @@ public final class DebugJsProtoBuf { functionAnnotation.internalInit(descriptor.getExtensions().get(4)); functionContainingFileId.internalInit(descriptor.getExtensions().get(5)); propertyAnnotation.internalInit(descriptor.getExtensions().get(6)); - compileTimeValue.internalInit(descriptor.getExtensions().get(7)); - propertyContainingFileId.internalInit(descriptor.getExtensions().get(8)); - enumEntryAnnotation.internalInit(descriptor.getExtensions().get(9)); - parameterAnnotation.internalInit(descriptor.getExtensions().get(10)); - typeAnnotation.internalInit(descriptor.getExtensions().get(11)); - typeParameterAnnotation.internalInit(descriptor.getExtensions().get(12)); - packageFragmentFiles.internalInit(descriptor.getExtensions().get(13)); + propertyGetterAnnotation.internalInit(descriptor.getExtensions().get(7)); + propertySetterAnnotation.internalInit(descriptor.getExtensions().get(8)); + compileTimeValue.internalInit(descriptor.getExtensions().get(9)); + propertyContainingFileId.internalInit(descriptor.getExtensions().get(10)); + enumEntryAnnotation.internalInit(descriptor.getExtensions().get(11)); + parameterAnnotation.internalInit(descriptor.getExtensions().get(12)); + typeAnnotation.internalInit(descriptor.getExtensions().get(13)); + typeParameterAnnotation.internalInit(descriptor.getExtensions().get(14)); + packageFragmentFiles.internalInit(descriptor.getExtensions().get(15)); org.jetbrains.kotlin.metadata.DebugProtoBuf.getDescriptor(); } diff --git a/build-common/test/org/jetbrains/kotlin/metadata/konan/DebugKonanProtoBuf.java b/build-common/test/org/jetbrains/kotlin/metadata/konan/DebugKonanProtoBuf.java index db56179ff4e..8df115f08f5 100644 --- a/build-common/test/org/jetbrains/kotlin/metadata/konan/DebugKonanProtoBuf.java +++ b/build-common/test/org/jetbrains/kotlin/metadata/konan/DebugKonanProtoBuf.java @@ -14,6 +14,8 @@ public final class DebugKonanProtoBuf { registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.functionAnnotation); registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.inlineIrBody); registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.propertyAnnotation); + registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.propertyGetterAnnotation); + registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.propertySetterAnnotation); registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.hasBackingField); registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.usedAsVariable); registry.add(org.jetbrains.kotlin.metadata.konan.DebugKonanProtoBuf.compileTimeValue); @@ -3930,6 +3932,28 @@ public final class DebugKonanProtoBuf { .newFileScopedGeneratedExtension( org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); + public static final int PROPERTY_GETTER_ANNOTATION_FIELD_NUMBER = 176; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessage.GeneratedExtension< + org.jetbrains.kotlin.metadata.DebugProtoBuf.Property, + java.util.List> propertyGetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); + public static final int PROPERTY_SETTER_ANNOTATION_FIELD_NUMBER = 177; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessage.GeneratedExtension< + org.jetbrains.kotlin.metadata.DebugProtoBuf.Property, + java.util.List> propertySetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.class, + org.jetbrains.kotlin.metadata.DebugProtoBuf.Annotation.getDefaultInstance()); public static final int HAS_BACKING_FIELD_FIELD_NUMBER = 171; /** * extend .org.jetbrains.kotlin.metadata.Property { ... } @@ -4120,35 +4144,41 @@ public final class DebugKonanProtoBuf { "nlineIrBody:p\n\023property_annotation\022\'.org" + ".jetbrains.kotlin.metadata.Property\030\252\001 \003" + "(\0132).org.jetbrains.kotlin.metadata.Annot" + - "ation:C\n\021has_backing_field\022\'.org.jetbrai" + - "ns.kotlin.metadata.Property\030\253\001 \001(\010:B\n\020us" + - "ed_as_variable\022\'.org.jetbrains.kotlin.me" + - "tadata.Property\030\254\001 \001(\010:~\n\022compile_time_v", - "alue\022\'.org.jetbrains.kotlin.metadata.Pro" + - "perty\030\255\001 \001(\01328.org.jetbrains.kotlin.meta" + - "data.Annotation.Argument.Value:z\n\025inline" + - "_getter_ir_body\022\'.org.jetbrains.kotlin.m" + - "etadata.Property\030\256\001 \001(\01321.org.jetbrains." + - "kotlin.metadata.konan.InlineIrBody:z\n\025in" + - "line_setter_ir_body\022\'.org.jetbrains.kotl" + - "in.metadata.Property\030\257\001 \001(\01321.org.jetbra" + - "ins.kotlin.metadata.konan.InlineIrBody:s" + - "\n\025enum_entry_annotation\022(.org.jetbrains.", - "kotlin.metadata.EnumEntry\030\252\001 \003(\0132).org.j" + - "etbrains.kotlin.metadata.Annotation:E\n\022e" + - "num_entry_ordinal\022(.org.jetbrains.kotlin" + - ".metadata.EnumEntry\030\253\001 \001(\005:w\n\024parameter_" + - "annotation\022-.org.jetbrains.kotlin.metada" + - "ta.ValueParameter\030\252\001 \003(\0132).org.jetbrains" + - ".kotlin.metadata.Annotation:h\n\017type_anno" + - "tation\022#.org.jetbrains.kotlin.metadata.T" + - "ype\030\252\001 \003(\0132).org.jetbrains.kotlin.metada" + - "ta.Annotation:7\n\ttype_text\022#.org.jetbrai", - "ns.kotlin.metadata.Type\030\254\001 \001(\t:{\n\031type_p" + - "arameter_annotation\022,.org.jetbrains.kotl" + - "in.metadata.TypeParameter\030\252\001 \003(\0132).org.j" + - "etbrains.kotlin.metadata.AnnotationB\024B\022D" + - "ebugKonanProtoBuf" + "ation:w\n\032property_getter_annotation\022\'.or" + + "g.jetbrains.kotlin.metadata.Property\030\260\001 " + + "\003(\0132).org.jetbrains.kotlin.metadata.Anno" + + "tation:w\n\032property_setter_annotation\022\'.o", + "rg.jetbrains.kotlin.metadata.Property\030\261\001" + + " \003(\0132).org.jetbrains.kotlin.metadata.Ann" + + "otation:C\n\021has_backing_field\022\'.org.jetbr" + + "ains.kotlin.metadata.Property\030\253\001 \001(\010:B\n\020" + + "used_as_variable\022\'.org.jetbrains.kotlin." + + "metadata.Property\030\254\001 \001(\010:~\n\022compile_time" + + "_value\022\'.org.jetbrains.kotlin.metadata.P" + + "roperty\030\255\001 \001(\01328.org.jetbrains.kotlin.me" + + "tadata.Annotation.Argument.Value:z\n\025inli" + + "ne_getter_ir_body\022\'.org.jetbrains.kotlin", + ".metadata.Property\030\256\001 \001(\01321.org.jetbrain" + + "s.kotlin.metadata.konan.InlineIrBody:z\n\025" + + "inline_setter_ir_body\022\'.org.jetbrains.ko" + + "tlin.metadata.Property\030\257\001 \001(\01321.org.jetb" + + "rains.kotlin.metadata.konan.InlineIrBody" + + ":s\n\025enum_entry_annotation\022(.org.jetbrain" + + "s.kotlin.metadata.EnumEntry\030\252\001 \003(\0132).org" + + ".jetbrains.kotlin.metadata.Annotation:E\n" + + "\022enum_entry_ordinal\022(.org.jetbrains.kotl" + + "in.metadata.EnumEntry\030\253\001 \001(\005:w\n\024paramete", + "r_annotation\022-.org.jetbrains.kotlin.meta" + + "data.ValueParameter\030\252\001 \003(\0132).org.jetbrai" + + "ns.kotlin.metadata.Annotation:h\n\017type_an" + + "notation\022#.org.jetbrains.kotlin.metadata" + + ".Type\030\252\001 \003(\0132).org.jetbrains.kotlin.meta" + + "data.Annotation:7\n\ttype_text\022#.org.jetbr" + + "ains.kotlin.metadata.Type\030\254\001 \001(\t:{\n\031type" + + "_parameter_annotation\022,.org.jetbrains.ko" + + "tlin.metadata.TypeParameter\030\252\001 \003(\0132).org" + + ".jetbrains.kotlin.metadata.AnnotationB\024B", + "\022DebugKonanProtoBuf" }; org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { @@ -4194,17 +4224,19 @@ public final class DebugKonanProtoBuf { functionAnnotation.internalInit(descriptor.getExtensions().get(4)); inlineIrBody.internalInit(descriptor.getExtensions().get(5)); propertyAnnotation.internalInit(descriptor.getExtensions().get(6)); - hasBackingField.internalInit(descriptor.getExtensions().get(7)); - usedAsVariable.internalInit(descriptor.getExtensions().get(8)); - compileTimeValue.internalInit(descriptor.getExtensions().get(9)); - inlineGetterIrBody.internalInit(descriptor.getExtensions().get(10)); - inlineSetterIrBody.internalInit(descriptor.getExtensions().get(11)); - enumEntryAnnotation.internalInit(descriptor.getExtensions().get(12)); - enumEntryOrdinal.internalInit(descriptor.getExtensions().get(13)); - parameterAnnotation.internalInit(descriptor.getExtensions().get(14)); - typeAnnotation.internalInit(descriptor.getExtensions().get(15)); - typeText.internalInit(descriptor.getExtensions().get(16)); - typeParameterAnnotation.internalInit(descriptor.getExtensions().get(17)); + propertyGetterAnnotation.internalInit(descriptor.getExtensions().get(7)); + propertySetterAnnotation.internalInit(descriptor.getExtensions().get(8)); + hasBackingField.internalInit(descriptor.getExtensions().get(9)); + usedAsVariable.internalInit(descriptor.getExtensions().get(10)); + compileTimeValue.internalInit(descriptor.getExtensions().get(11)); + inlineGetterIrBody.internalInit(descriptor.getExtensions().get(12)); + inlineSetterIrBody.internalInit(descriptor.getExtensions().get(13)); + enumEntryAnnotation.internalInit(descriptor.getExtensions().get(14)); + enumEntryOrdinal.internalInit(descriptor.getExtensions().get(15)); + parameterAnnotation.internalInit(descriptor.getExtensions().get(16)); + typeAnnotation.internalInit(descriptor.getExtensions().get(17)); + typeText.internalInit(descriptor.getExtensions().get(18)); + typeParameterAnnotation.internalInit(descriptor.getExtensions().get(19)); org.jetbrains.kotlin.metadata.DebugProtoBuf.getDescriptor(); } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index 6d6b4b8d40e..b1586002825 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt @@ -36,9 +36,9 @@ object KotlinStubVersions { // BuiltIn stub version should be increased if changes are made to builtIn stub building subsystem (org.jetbrains.kotlin.idea.decompiler.builtIns) // Increasing this version will lead to reindexing of all builtIn files (see KotlinBuiltInFileType). - const val BUILTIN_STUB_VERSION = BINARY_STUB_VERSION + 2 + const val BUILTIN_STUB_VERSION = BINARY_STUB_VERSION + 3 // JS stub version should be increased if changes are made to js stub building subsystem (org.jetbrains.kotlin.idea.decompiler.js) // Increasing this version will lead to reindexing of js binary files (see KotlinJavaScriptMetaFileType). - const val JS_STUB_VERSION = BINARY_STUB_VERSION + 2 + const val JS_STUB_VERSION = BINARY_STUB_VERSION + 3 } diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionBase.kt b/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionBase.kt index 86303b51d51..511bc80e445 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionBase.kt +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionBase.kt @@ -61,6 +61,12 @@ abstract class KotlinSerializerExtensionBase(private val protocol: SerializerExt for (annotation in descriptor.nonSourceAnnotations) { proto.addExtension(protocol.propertyAnnotation, annotationSerializer.serializeAnnotation(annotation)) } + for (annotation in descriptor.getter?.nonSourceAnnotations.orEmpty()) { + proto.addExtension(protocol.propertyGetterAnnotation, annotationSerializer.serializeAnnotation(annotation)) + } + for (annotation in descriptor.setter?.nonSourceAnnotations.orEmpty()) { + proto.addExtension(protocol.propertySetterAnnotation, annotationSerializer.serializeAnnotation(annotation)) + } val constantInitializer = descriptor.compileTimeInitializer ?: return if (constantInitializer !is NullValue) { proto.setExtension(protocol.compileTimeValue, annotationSerializer.valueProto(constantInitializer).build()) diff --git a/compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.kt b/compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.kt new file mode 100644 index 00000000000..c811408f596 --- /dev/null +++ b/compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.kt @@ -0,0 +1,10 @@ +package test + +annotation class Anno(val value: String) + +@Anno("property") val v1 = "" + +var v2: String + @Anno("getter") get() = "" + @Anno("setter") set(@Anno("setparam") value) { + } diff --git a/compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.txt b/compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.txt new file mode 100644 index 00000000000..d9a4fff57a6 --- /dev/null +++ b/compiler/testData/serialization/builtinsSerializer/propertyAccessorAnnotations.txt @@ -0,0 +1,9 @@ +package test + +@test.Anno(value = "property") public val v1: kotlin.String = "" +@get:test.Anno(value = "getter") @set:test.Anno(value = "setter") @setparam:test.Anno(value = "setparam") public var v2: kotlin.String + +public final annotation class Anno : kotlin.Annotation { + public constructor Anno(/*0*/ value: kotlin.String) + public final val value: kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerTest.kt b/compiler/tests/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerTest.kt index 1fef141e35a..c8c22422ef0 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerTest.kt @@ -112,4 +112,8 @@ class BuiltInsSerializerTest : TestCaseWithTmpdir() { fun testBinaryRetainedAnnotation() { doTest("binaryRetainedAnnotation.kt") } + + fun testPropertyAccessorAnnotations() { + doTest("propertyAccessorAnnotations.kt") + } } diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt b/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt index 2a87203c7ae..125e1eb8bad 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt @@ -152,4 +152,8 @@ class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() { fun testEnum() { doTest("builtinsSerializer/annotationArguments/enum.kt") } + + fun testPropertyAccessorAnnotations() { + doTest("builtinsSerializer/propertyAccessorAnnotations.kt") + } } diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt index 9ed399973cd..344116dba6e 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinJavascriptMetadataUtils.kt @@ -33,7 +33,7 @@ class JsMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) { companion object { @JvmField - val INSTANCE = JsMetadataVersion(1, 2, 5) + val INSTANCE = JsMetadataVersion(1, 2, 6) @JvmField val INVALID_VERSION = JsMetadataVersion() diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt index 1ce16c97315..391a044e8fe 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt @@ -27,6 +27,8 @@ open class SerializerExtensionProtocol( val classAnnotation: GeneratedExtension>, val functionAnnotation: GeneratedExtension>, val propertyAnnotation: GeneratedExtension>, + val propertyGetterAnnotation: GeneratedExtension>, + val propertySetterAnnotation: GeneratedExtension>, val enumEntryAnnotation: GeneratedExtension>, val compileTimeValue: GeneratedExtension, val parameterAnnotation: GeneratedExtension>, diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt index 69b7f4b5fbe..f313308b2fb 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt @@ -47,7 +47,12 @@ class AnnotationAndConstantLoaderImpl( val annotations = when (proto) { is ProtoBuf.Constructor -> proto.getExtension(protocol.constructorAnnotation) is ProtoBuf.Function -> proto.getExtension(protocol.functionAnnotation) - is ProtoBuf.Property -> proto.getExtension(protocol.propertyAnnotation) + is ProtoBuf.Property -> when (kind) { + AnnotatedCallableKind.PROPERTY -> proto.getExtension(protocol.propertyAnnotation) + AnnotatedCallableKind.PROPERTY_GETTER -> proto.getExtension(protocol.propertyGetterAnnotation) + AnnotatedCallableKind.PROPERTY_SETTER -> proto.getExtension(protocol.propertySetterAnnotation) + else -> error("Unsupported callable kind with property proto") + } else -> error("Unknown message: $proto") }.orEmpty() return annotations.map { annotationProto -> diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/builtins/BuiltInSerializerProtocol.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/builtins/BuiltInSerializerProtocol.kt index df3bee5aead..a8f44ecde43 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/builtins/BuiltInSerializerProtocol.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/builtins/BuiltInSerializerProtocol.kt @@ -11,11 +11,19 @@ import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol object BuiltInSerializerProtocol : SerializerExtensionProtocol( - ExtensionRegistryLite.newInstance().apply { BuiltInsProtoBuf.registerAllExtensions(this) }, + ExtensionRegistryLite.newInstance().apply(BuiltInsProtoBuf::registerAllExtensions), BuiltInsProtoBuf.packageFqName, - BuiltInsProtoBuf.constructorAnnotation, BuiltInsProtoBuf.classAnnotation, BuiltInsProtoBuf.functionAnnotation, - BuiltInsProtoBuf.propertyAnnotation, BuiltInsProtoBuf.enumEntryAnnotation, BuiltInsProtoBuf.compileTimeValue, - BuiltInsProtoBuf.parameterAnnotation, BuiltInsProtoBuf.typeAnnotation, BuiltInsProtoBuf.typeParameterAnnotation + BuiltInsProtoBuf.constructorAnnotation, + BuiltInsProtoBuf.classAnnotation, + BuiltInsProtoBuf.functionAnnotation, + BuiltInsProtoBuf.propertyAnnotation, + BuiltInsProtoBuf.propertyGetterAnnotation, + BuiltInsProtoBuf.propertySetterAnnotation, + BuiltInsProtoBuf.enumEntryAnnotation, + BuiltInsProtoBuf.compileTimeValue, + BuiltInsProtoBuf.parameterAnnotation, + BuiltInsProtoBuf.typeAnnotation, + BuiltInsProtoBuf.typeParameterAnnotation ) { const val BUILTINS_FILE_EXTENSION = "kotlin_builtins" diff --git a/core/metadata/src/builtins.proto b/core/metadata/src/builtins.proto index 5d75b79cb9d..2b0730254d0 100644 --- a/core/metadata/src/builtins.proto +++ b/core/metadata/src/builtins.proto @@ -39,6 +39,8 @@ extend Function { extend Property { repeated Annotation property_annotation = 150; + repeated Annotation property_getter_annotation = 152; + repeated Annotation property_setter_annotation = 153; optional Annotation.Argument.Value compile_time_value = 151; } diff --git a/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsBinaryVersion.kt b/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsBinaryVersion.kt index a2d2ef95906..c459760d87a 100644 --- a/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsBinaryVersion.kt +++ b/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsBinaryVersion.kt @@ -19,7 +19,7 @@ class BuiltInsBinaryVersion(vararg numbers: Int) : BinaryVersion(*numbers) { companion object { @JvmField - val INSTANCE = BuiltInsBinaryVersion(1, 0, 6) + val INSTANCE = BuiltInsBinaryVersion(1, 0, 7) @JvmField val INVALID_VERSION = BuiltInsBinaryVersion() diff --git a/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsProtoBuf.java b/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsProtoBuf.java index bc29fb4e88f..68ce58ac8ce 100644 --- a/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsProtoBuf.java +++ b/core/metadata/src/org/jetbrains/kotlin/metadata/builtins/BuiltInsProtoBuf.java @@ -12,6 +12,8 @@ public final class BuiltInsProtoBuf { registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.constructorAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.functionAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.propertyAnnotation); + registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.propertyGetterAnnotation); + registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.propertySetterAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.compileTimeValue); registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.enumEntryAnnotation); registry.add(org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf.parameterAnnotation); @@ -98,6 +100,38 @@ public final class BuiltInsProtoBuf { org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, false, org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); + public static final int PROPERTY_GETTER_ANNOTATION_FIELD_NUMBER = 152; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension< + org.jetbrains.kotlin.metadata.ProtoBuf.Property, + java.util.List> propertyGetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessageLite + .newRepeatedGeneratedExtension( + org.jetbrains.kotlin.metadata.ProtoBuf.Property.getDefaultInstance(), + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.getDefaultInstance(), + null, + 152, + org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, + false, + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); + public static final int PROPERTY_SETTER_ANNOTATION_FIELD_NUMBER = 153; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension< + org.jetbrains.kotlin.metadata.ProtoBuf.Property, + java.util.List> propertySetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessageLite + .newRepeatedGeneratedExtension( + org.jetbrains.kotlin.metadata.ProtoBuf.Property.getDefaultInstance(), + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.getDefaultInstance(), + null, + 153, + org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, + false, + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); public static final int COMPILE_TIME_VALUE_FIELD_NUMBER = 151; /** * extend .org.jetbrains.kotlin.metadata.Property { ... } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/common/AnnotationLoaderForStubBuilderImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/common/AnnotationLoaderForStubBuilderImpl.kt index 00e5f8871ef..c7615d56037 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/common/AnnotationLoaderForStubBuilderImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/common/AnnotationLoaderForStubBuilderImpl.kt @@ -42,7 +42,12 @@ class AnnotationLoaderForStubBuilderImpl( val annotations = when (proto) { is ProtoBuf.Constructor -> proto.getExtension(protocol.constructorAnnotation) is ProtoBuf.Function -> proto.getExtension(protocol.functionAnnotation) - is ProtoBuf.Property -> proto.getExtension(protocol.propertyAnnotation) + is ProtoBuf.Property -> when (kind) { + AnnotatedCallableKind.PROPERTY -> proto.getExtension(protocol.propertyAnnotation) + AnnotatedCallableKind.PROPERTY_GETTER -> proto.getExtension(protocol.propertyGetterAnnotation) + AnnotatedCallableKind.PROPERTY_SETTER -> proto.getExtension(protocol.propertySetterAnnotation) + else -> error("Unsupported callable kind with property proto") + } else -> error("Unknown message: $proto") }.orEmpty() return annotations.map { container.nameResolver.getClassId(it.id) } diff --git a/js/js.serializer/src/js.proto b/js/js.serializer/src/js.proto index f751ce49741..935e1b5f6bc 100644 --- a/js/js.serializer/src/js.proto +++ b/js/js.serializer/src/js.proto @@ -71,6 +71,8 @@ extend Function { extend Property { repeated Annotation property_annotation = 130; + repeated Annotation property_getter_annotation = 132; + repeated Annotation property_setter_annotation = 133; optional Annotation.Argument.Value compile_time_value = 131; optional int32 property_containing_file_id = 135; } diff --git a/js/js.serializer/src/org/jetbrains/kotlin/metadata/js/JsProtoBuf.java b/js/js.serializer/src/org/jetbrains/kotlin/metadata/js/JsProtoBuf.java index 5dcfccf862d..1e91f9edc62 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/metadata/js/JsProtoBuf.java +++ b/js/js.serializer/src/org/jetbrains/kotlin/metadata/js/JsProtoBuf.java @@ -14,6 +14,8 @@ public final class JsProtoBuf { registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.functionAnnotation); registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.functionContainingFileId); registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.propertyAnnotation); + registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.propertyGetterAnnotation); + registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.propertySetterAnnotation); registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.compileTimeValue); registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.propertyContainingFileId); registry.add(org.jetbrains.kotlin.metadata.js.JsProtoBuf.enumEntryAnnotation); @@ -3755,6 +3757,38 @@ public final class JsProtoBuf { org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, false, org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); + public static final int PROPERTY_GETTER_ANNOTATION_FIELD_NUMBER = 132; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension< + org.jetbrains.kotlin.metadata.ProtoBuf.Property, + java.util.List> propertyGetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessageLite + .newRepeatedGeneratedExtension( + org.jetbrains.kotlin.metadata.ProtoBuf.Property.getDefaultInstance(), + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.getDefaultInstance(), + null, + 132, + org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, + false, + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); + public static final int PROPERTY_SETTER_ANNOTATION_FIELD_NUMBER = 133; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension< + org.jetbrains.kotlin.metadata.ProtoBuf.Property, + java.util.List> propertySetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessageLite + .newRepeatedGeneratedExtension( + org.jetbrains.kotlin.metadata.ProtoBuf.Property.getDefaultInstance(), + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.getDefaultInstance(), + null, + 133, + org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, + false, + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); public static final int COMPILE_TIME_VALUE_FIELD_NUMBER = 131; /** * extend .org.jetbrains.kotlin.metadata.Property { ... } diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsSerializerProtocol.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsSerializerProtocol.kt index edf9295b68f..b2e66a52688 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsSerializerProtocol.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsSerializerProtocol.kt @@ -12,16 +12,14 @@ import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol object JsSerializerProtocol : SerializerExtensionProtocol( - ExtensionRegistryLite.newInstance().apply { - JsProtoBuf.registerAllExtensions( - this - ) - }, + ExtensionRegistryLite.newInstance().apply(JsProtoBuf::registerAllExtensions), JsProtoBuf.packageFqName, JsProtoBuf.constructorAnnotation, JsProtoBuf.classAnnotation, JsProtoBuf.functionAnnotation, JsProtoBuf.propertyAnnotation, + JsProtoBuf.propertyGetterAnnotation, + JsProtoBuf.propertySetterAnnotation, JsProtoBuf.enumEntryAnnotation, JsProtoBuf.compileTimeValue, JsProtoBuf.parameterAnnotation, @@ -35,4 +33,4 @@ object JsSerializerProtocol : SerializerExtensionProtocol( "." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION } -} \ No newline at end of file +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 00fe137d9ef..1de8b860b44 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -5348,6 +5348,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/jsName/privateMethod.kt"); } + @TestMetadata("propertyAccessorFromOtherModule.kt") + public void testPropertyAccessorFromOtherModule() throws Exception { + runTest("js/js.translator/testData/box/jsName/propertyAccessorFromOtherModule.kt"); + } + @TestMetadata("secondaryConstructor.kt") public void testSecondaryConstructor() throws Exception { runTest("js/js.translator/testData/box/jsName/secondaryConstructor.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java index c00fcba1d2b..1c7bbe5e21a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java @@ -5348,6 +5348,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/jsName/privateMethod.kt"); } + @TestMetadata("propertyAccessorFromOtherModule.kt") + public void testPropertyAccessorFromOtherModule() throws Exception { + runTest("js/js.translator/testData/box/jsName/propertyAccessorFromOtherModule.kt"); + } + @TestMetadata("secondaryConstructor.kt") public void testSecondaryConstructor() throws Exception { runTest("js/js.translator/testData/box/jsName/secondaryConstructor.kt"); diff --git a/js/js.translator/testData/box/jsName/propertyAccessorFromOtherModule.kt b/js/js.translator/testData/box/jsName/propertyAccessorFromOtherModule.kt new file mode 100644 index 00000000000..8fd6b9b3928 --- /dev/null +++ b/js/js.translator/testData/box/jsName/propertyAccessorFromOtherModule.kt @@ -0,0 +1,18 @@ +// EXPECTED_REACHABLE_NODES: 1281 +// MODULE: lib +// FILE: lib.kt +package lib + +val foo: Int + @JsName("getBar") get() = 23 + +// MODULE: main(lib) +// FILE: main.kt +package main + +import lib.* + +fun box(): String { + if (foo != 23) return "fail: $foo" + return "OK" +} diff --git a/konan/library-reader/src/konan.proto b/konan/library-reader/src/konan.proto index 101bb7b4404..b08701d8d4f 100644 --- a/konan/library-reader/src/konan.proto +++ b/konan/library-reader/src/konan.proto @@ -34,6 +34,8 @@ extend Function { extend Property { repeated Annotation property_annotation = 170; + repeated Annotation property_getter_annotation = 176; + repeated Annotation property_setter_annotation = 177; optional bool has_backing_field = 171; optional bool used_as_variable = 172; optional Annotation.Argument.Value compile_time_value = 173; diff --git a/konan/library-reader/src/org/jetbrains/kotlin/metadata/konan/KonanProtoBuf.java b/konan/library-reader/src/org/jetbrains/kotlin/metadata/konan/KonanProtoBuf.java index 5d46d20849c..2f8646ca011 100644 --- a/konan/library-reader/src/org/jetbrains/kotlin/metadata/konan/KonanProtoBuf.java +++ b/konan/library-reader/src/org/jetbrains/kotlin/metadata/konan/KonanProtoBuf.java @@ -14,6 +14,8 @@ public final class KonanProtoBuf { registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.functionAnnotation); registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.inlineIrBody); registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.propertyAnnotation); + registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.propertyGetterAnnotation); + registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.propertySetterAnnotation); registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.hasBackingField); registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.usedAsVariable); registry.add(org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.compileTimeValue); @@ -3315,6 +3317,38 @@ public final class KonanProtoBuf { org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, false, org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); + public static final int PROPERTY_GETTER_ANNOTATION_FIELD_NUMBER = 176; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension< + org.jetbrains.kotlin.metadata.ProtoBuf.Property, + java.util.List> propertyGetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessageLite + .newRepeatedGeneratedExtension( + org.jetbrains.kotlin.metadata.ProtoBuf.Property.getDefaultInstance(), + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.getDefaultInstance(), + null, + 176, + org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, + false, + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); + public static final int PROPERTY_SETTER_ANNOTATION_FIELD_NUMBER = 177; + /** + * extend .org.jetbrains.kotlin.metadata.Property { ... } + */ + public static final + org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension< + org.jetbrains.kotlin.metadata.ProtoBuf.Property, + java.util.List> propertySetterAnnotation = org.jetbrains.kotlin.protobuf.GeneratedMessageLite + .newRepeatedGeneratedExtension( + org.jetbrains.kotlin.metadata.ProtoBuf.Property.getDefaultInstance(), + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.getDefaultInstance(), + null, + 177, + org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE, + false, + org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class); public static final int HAS_BACKING_FIELD_FIELD_NUMBER = 171; /** * extend .org.jetbrains.kotlin.metadata.Property { ... } diff --git a/konan/library-reader/src/org/jetbrains/kotlin/serialization/konan/KonanSerializerProtocol.kt b/konan/library-reader/src/org/jetbrains/kotlin/serialization/konan/KonanSerializerProtocol.kt index 9ed595e3b32..9aad70dd7d5 100644 --- a/konan/library-reader/src/org/jetbrains/kotlin/serialization/konan/KonanSerializerProtocol.kt +++ b/konan/library-reader/src/org/jetbrains/kotlin/serialization/konan/KonanSerializerProtocol.kt @@ -10,12 +10,14 @@ import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol object KonanSerializerProtocol : SerializerExtensionProtocol( - ExtensionRegistryLite.newInstance().apply { KonanProtoBuf.registerAllExtensions(this) }, + ExtensionRegistryLite.newInstance().apply(KonanProtoBuf::registerAllExtensions), KonanProtoBuf.packageFqName, KonanProtoBuf.constructorAnnotation, KonanProtoBuf.classAnnotation, KonanProtoBuf.functionAnnotation, KonanProtoBuf.propertyAnnotation, + KonanProtoBuf.propertyGetterAnnotation, + KonanProtoBuf.propertySetterAnnotation, KonanProtoBuf.enumEntryAnnotation, KonanProtoBuf.compileTimeValue, KonanProtoBuf.parameterAnnotation,