From 933bcb3511c60a1f636aaaea751f86bd113496a5 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 30 Jan 2017 11:49:20 +0300 Subject: [PATCH] JS: do not require "id" in the File protobuf message --- .../serialization/js/DebugJsProtoBuf.java | 58 +++++++++++++------ js/js.serializer/src/js.proto | 4 +- .../kotlin/serialization/js/JsProtoBuf.java | 56 +++++++++++++----- .../js/KotlinJavascriptPackageFragment.kt | 4 +- .../js/KotlinJavascriptSerializationUtil.kt | 6 +- 5 files changed, 91 insertions(+), 37 deletions(-) diff --git a/build-common/test/org/jetbrains/kotlin/serialization/js/DebugJsProtoBuf.java b/build-common/test/org/jetbrains/kotlin/serialization/js/DebugJsProtoBuf.java index 9c1431be23e..0bde91c9ebd 100644 --- a/build-common/test/org/jetbrains/kotlin/serialization/js/DebugJsProtoBuf.java +++ b/build-common/test/org/jetbrains/kotlin/serialization/js/DebugJsProtoBuf.java @@ -722,11 +722,19 @@ public final class DebugJsProtoBuf { org.jetbrains.kotlin.protobuf.MessageOrBuilder { /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ boolean hasId(); /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ int getId(); @@ -865,13 +873,21 @@ public final class DebugJsProtoBuf { public static final int ID_FIELD_NUMBER = 1; private int id_; /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ public boolean hasId() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ public int getId() { return id_; @@ -922,10 +938,6 @@ public final class DebugJsProtoBuf { if (isInitialized == 1) return true; if (isInitialized == 0) return false; - if (!hasId()) { - memoizedIsInitialized = 0; - return false; - } for (int i = 0; i < getAnnotationCount(); i++) { if (!getAnnotation(i).isInitialized()) { memoizedIsInitialized = 0; @@ -1179,10 +1191,6 @@ public final class DebugJsProtoBuf { } public final boolean isInitialized() { - if (!hasId()) { - - return false; - } for (int i = 0; i < getAnnotationCount(); i++) { if (!getAnnotation(i).isInitialized()) { @@ -1213,19 +1221,31 @@ public final class DebugJsProtoBuf { private int id_ ; /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public boolean hasId() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public int getId() { return id_; } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public Builder setId(int value) { bitField0_ |= 0x00000001; @@ -1234,7 +1254,11 @@ public final class DebugJsProtoBuf { return this; } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public Builder clearId() { bitField0_ = (bitField0_ & ~0x00000001); @@ -5456,7 +5480,7 @@ public final class DebugJsProtoBuf { "re/deserialization/src/descriptors.debug" + ".proto\"P\n\006Header\022\r\n\005flags\030\001 \001(\005\022\036\n\026js_co" + "de_binary_version\030\002 \001(\005\022\027\n\017package_fq_na" + - "me\030\003 \001(\t\"V\n\004File\022\n\n\002id\030\001 \002(\005\022B\n\nannotati" + + "me\030\003 \001(\t\"V\n\004File\022\n\n\002id\030\001 \001(\005\022B\n\nannotati" + "on\030\002 \003(\0132..org.jetbrains.kotlin.serializ" + "ation.Annotation\"B\n\005Files\0229\n\004file\030\001 \003(\0132" + "+.org.jetbrains.kotlin.serialization.js." + diff --git a/js/js.serializer/src/js.proto b/js/js.serializer/src/js.proto index f62384d1ef0..66b7ccaaf22 100644 --- a/js/js.serializer/src/js.proto +++ b/js/js.serializer/src/js.proto @@ -34,7 +34,9 @@ message Header { } message File { - required int32 id = 1; + // If absent, id is the index of the file in the Files.file list + optional int32 id = 1; + repeated Annotation annotation = 2; } diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsProtoBuf.java b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsProtoBuf.java index 9c3e8c7be48..79760a3ec4c 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsProtoBuf.java +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/JsProtoBuf.java @@ -677,11 +677,19 @@ public final class JsProtoBuf { org.jetbrains.kotlin.protobuf.MessageLiteOrBuilder { /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ boolean hasId(); /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ int getId(); @@ -802,13 +810,21 @@ public final class JsProtoBuf { public static final int ID_FIELD_NUMBER = 1; private int id_; /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ public boolean hasId() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+     * If absent, id is the index of the file in the Files.file list
+     * 
*/ public int getId() { return id_; @@ -859,10 +875,6 @@ public final class JsProtoBuf { if (isInitialized == 1) return true; if (isInitialized == 0) return false; - if (!hasId()) { - memoizedIsInitialized = 0; - return false; - } for (int i = 0; i < getAnnotationCount(); i++) { if (!getAnnotation(i).isInitialized()) { memoizedIsInitialized = 0; @@ -1054,10 +1066,6 @@ public final class JsProtoBuf { } public final boolean isInitialized() { - if (!hasId()) { - - return false; - } for (int i = 0; i < getAnnotationCount(); i++) { if (!getAnnotation(i).isInitialized()) { @@ -1088,19 +1096,31 @@ public final class JsProtoBuf { private int id_ ; /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public boolean hasId() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public int getId() { return id_; } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public Builder setId(int value) { bitField0_ |= 0x00000001; @@ -1109,7 +1129,11 @@ public final class JsProtoBuf { return this; } /** - * required int32 id = 1; + * optional int32 id = 1; + * + *
+       * If absent, id is the index of the file in the Files.file list
+       * 
*/ public Builder clearId() { bitField0_ = (bitField0_ & ~0x00000001); diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt index 967da277efd..80bb9e674b8 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt @@ -42,7 +42,9 @@ class KotlinJavascriptPackageFragment( private val nameResolver: NameResolver ) : DeserializedPackageFragment(fqName, storageManager, module) { private val fileMap: Map by storageManager.createLazyValue { - proto.files.fileList.associate { file -> file.id to FileHolder(file.annotationList) } + proto.files.fileList.withIndex().associate { (index, file) -> + (if (file.hasId()) file.id else index) to FileHolder(file.annotationList) + } } private val annotationDeserializer: AnnotationDeserializer by storageManager.createLazyValue { diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializationUtil.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializationUtil.kt index 8dceb27d712..e9351c6b55e 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializationUtil.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializationUtil.kt @@ -137,9 +137,11 @@ object KotlinJavascriptSerializationUtil { serializer: AnnotationSerializer ): JsProtoBuf.Files { val filesProto = JsProtoBuf.Files.newBuilder() - for ((file, id) in fileRegistry.fileIds) { + for ((file, id) in fileRegistry.fileIds.entries.sortedBy { it.value }) { val fileProto = JsProtoBuf.File.newBuilder() - fileProto.id = id + if (id != filesProto.fileCount) { + fileProto.id = id + } for (annotationPsi in file.annotationEntries) { val annotation = bindingContext[BindingContext.ANNOTATION, annotationPsi]!! fileProto.addAnnotation(serializer.serializeAnnotation(annotation))