From 69bfc5b4bbfe9dbfa54edf4be498a94daca60fcf Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 9 Jan 2017 14:12:22 +0300 Subject: [PATCH] Write multifile part->facade mapping to .kotlin_module --- .../jvm/DebugJvmPackageTable.java | 553 +++++++++++++++++- .../kotlin/codegen/ClassFileFactory.java | 4 +- .../kotlin/codegen/MultifileClassCodegen.kt | 5 +- .../kotlin/codegen/PackageCodegenImpl.java | 3 +- .../kotlin/codegen/PackagePartRegistry.kt | 2 +- .../src/jvm_package_table.proto | 11 +- .../kotlin/load/kotlin/ModuleMapping.kt | 82 ++- .../serialization/jvm/JvmPackageTable.java | 545 ++++++++++++++++- .../idea/vfilefinder/moduleMappingIndexes.kt | 13 +- 9 files changed, 1138 insertions(+), 80 deletions(-) diff --git a/build-common/test/org/jetbrains/kotlin/serialization/jvm/DebugJvmPackageTable.java b/build-common/test/org/jetbrains/kotlin/serialization/jvm/DebugJvmPackageTable.java index 0da1e91bbca..15992f048c0 100644 --- a/build-common/test/org/jetbrains/kotlin/serialization/jvm/DebugJvmPackageTable.java +++ b/build-common/test/org/jetbrains/kotlin/serialization/jvm/DebugJvmPackageTable.java @@ -1314,7 +1314,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ org.jetbrains.kotlin.protobuf.ProtocolStringList @@ -1323,7 +1324,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ int getClassNameCount(); @@ -1331,7 +1333,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ java.lang.String getClassName(int index); @@ -1339,11 +1342,78 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ org.jetbrains.kotlin.protobuf.ByteString getClassNameBytes(int index); + + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + java.util.List getMultifileFacadeIdList(); + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + int getMultifileFacadeIdCount(); + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + int getMultifileFacadeId(int index); + + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + org.jetbrains.kotlin.protobuf.ProtocolStringList + getMultifileFacadeNameList(); + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + int getMultifileFacadeNameCount(); + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + java.lang.String getMultifileFacadeName(int index); + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + org.jetbrains.kotlin.protobuf.ByteString + getMultifileFacadeNameBytes(int index); } /** * Protobuf type {@code org.jetbrains.kotlin.serialization.jvm.PackageParts} @@ -1412,6 +1482,36 @@ public final class DebugJvmPackageTable { className_.add(bs); break; } + case 24: { + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000004; + } + multifileFacadeId_.add(input.readInt32()); + break; + } + case 26: { + int length = input.readRawVarint32(); + int limit = input.pushLimit(length); + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004) && input.getBytesUntilLimit() > 0) { + multifileFacadeId_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000004; + } + while (input.getBytesUntilLimit() > 0) { + multifileFacadeId_.add(input.readInt32()); + } + input.popLimit(limit); + break; + } + case 34: { + org.jetbrains.kotlin.protobuf.ByteString bs = input.readBytes(); + if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = new org.jetbrains.kotlin.protobuf.LazyStringArrayList(); + mutable_bitField0_ |= 0x00000008; + } + multifileFacadeName_.add(bs); + break; + } } } } catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) { @@ -1423,6 +1523,12 @@ public final class DebugJvmPackageTable { if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { className_ = className_.getUnmodifiableView(); } + if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = java.util.Collections.unmodifiableList(multifileFacadeId_); + } + if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = multifileFacadeName_.getUnmodifiableView(); + } this.unknownFields = unknownFields.build(); makeExtensionsImmutable(); } @@ -1503,7 +1609,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public org.jetbrains.kotlin.protobuf.ProtocolStringList @@ -1514,7 +1621,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public int getClassNameCount() { @@ -1524,7 +1632,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public java.lang.String getClassName(int index) { @@ -1534,7 +1643,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public org.jetbrains.kotlin.protobuf.ByteString @@ -1542,9 +1652,97 @@ public final class DebugJvmPackageTable { return className_.getByteString(index); } + public static final int MULTIFILE_FACADE_ID_FIELD_NUMBER = 3; + private java.util.List multifileFacadeId_; + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + public java.util.List + getMultifileFacadeIdList() { + return multifileFacadeId_; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + public int getMultifileFacadeIdCount() { + return multifileFacadeId_.size(); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + public int getMultifileFacadeId(int index) { + return multifileFacadeId_.get(index); + } + private int multifileFacadeIdMemoizedSerializedSize = -1; + + public static final int MULTIFILE_FACADE_NAME_FIELD_NUMBER = 4; + private org.jetbrains.kotlin.protobuf.LazyStringList multifileFacadeName_; + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public org.jetbrains.kotlin.protobuf.ProtocolStringList + getMultifileFacadeNameList() { + return multifileFacadeName_; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public int getMultifileFacadeNameCount() { + return multifileFacadeName_.size(); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public java.lang.String getMultifileFacadeName(int index) { + return multifileFacadeName_.get(index); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public org.jetbrains.kotlin.protobuf.ByteString + getMultifileFacadeNameBytes(int index) { + return multifileFacadeName_.getByteString(index); + } + private void initFields() { packageFqName_ = ""; className_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + multifileFacadeId_ = java.util.Collections.emptyList(); + multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -1569,6 +1767,16 @@ public final class DebugJvmPackageTable { for (int i = 0; i < className_.size(); i++) { output.writeBytes(2, className_.getByteString(i)); } + if (getMultifileFacadeIdList().size() > 0) { + output.writeRawVarint32(26); + output.writeRawVarint32(multifileFacadeIdMemoizedSerializedSize); + } + for (int i = 0; i < multifileFacadeId_.size(); i++) { + output.writeInt32NoTag(multifileFacadeId_.get(i)); + } + for (int i = 0; i < multifileFacadeName_.size(); i++) { + output.writeBytes(4, multifileFacadeName_.getByteString(i)); + } getUnknownFields().writeTo(output); } @@ -1591,6 +1799,29 @@ public final class DebugJvmPackageTable { size += dataSize; size += 1 * getClassNameList().size(); } + { + int dataSize = 0; + for (int i = 0; i < multifileFacadeId_.size(); i++) { + dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream + .computeInt32SizeNoTag(multifileFacadeId_.get(i)); + } + size += dataSize; + if (!getMultifileFacadeIdList().isEmpty()) { + size += 1; + size += org.jetbrains.kotlin.protobuf.CodedOutputStream + .computeInt32SizeNoTag(dataSize); + } + multifileFacadeIdMemoizedSerializedSize = dataSize; + } + { + int dataSize = 0; + for (int i = 0; i < multifileFacadeName_.size(); i++) { + dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream + .computeBytesSizeNoTag(multifileFacadeName_.getByteString(i)); + } + size += dataSize; + size += 1 * getMultifileFacadeNameList().size(); + } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; @@ -1712,6 +1943,10 @@ public final class DebugJvmPackageTable { bitField0_ = (bitField0_ & ~0x00000001); className_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; bitField0_ = (bitField0_ & ~0x00000002); + multifileFacadeId_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); return this; } @@ -1749,6 +1984,16 @@ public final class DebugJvmPackageTable { bitField0_ = (bitField0_ & ~0x00000002); } result.className_ = className_; + if (((bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = java.util.Collections.unmodifiableList(multifileFacadeId_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.multifileFacadeId_ = multifileFacadeId_; + if (((bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = multifileFacadeName_.getUnmodifiableView(); + bitField0_ = (bitField0_ & ~0x00000008); + } + result.multifileFacadeName_ = multifileFacadeName_; result.bitField0_ = to_bitField0_; onBuilt(); return result; @@ -1780,6 +2025,26 @@ public final class DebugJvmPackageTable { } onChanged(); } + if (!other.multifileFacadeId_.isEmpty()) { + if (multifileFacadeId_.isEmpty()) { + multifileFacadeId_ = other.multifileFacadeId_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureMultifileFacadeIdIsMutable(); + multifileFacadeId_.addAll(other.multifileFacadeId_); + } + onChanged(); + } + if (!other.multifileFacadeName_.isEmpty()) { + if (multifileFacadeName_.isEmpty()) { + multifileFacadeName_ = other.multifileFacadeName_; + bitField0_ = (bitField0_ & ~0x00000008); + } else { + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.addAll(other.multifileFacadeName_); + } + onChanged(); + } this.mergeUnknownFields(other.getUnknownFields()); return this; } @@ -1898,7 +2163,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public org.jetbrains.kotlin.protobuf.ProtocolStringList @@ -1909,7 +2175,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public int getClassNameCount() { @@ -1919,7 +2186,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public java.lang.String getClassName(int index) { @@ -1929,7 +2197,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public org.jetbrains.kotlin.protobuf.ByteString @@ -1940,7 +2209,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder setClassName( @@ -1957,7 +2227,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder addClassName( @@ -1974,7 +2245,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder addAllClassName( @@ -1989,7 +2261,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder clearClassName() { @@ -2002,7 +2275,8 @@ public final class DebugJvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder addClassNameBytes( @@ -2016,6 +2290,243 @@ public final class DebugJvmPackageTable { return this; } + private java.util.List multifileFacadeId_ = java.util.Collections.emptyList(); + private void ensureMultifileFacadeIdIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = new java.util.ArrayList(multifileFacadeId_); + bitField0_ |= 0x00000004; + } + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public java.util.List + getMultifileFacadeIdList() { + return java.util.Collections.unmodifiableList(multifileFacadeId_); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public int getMultifileFacadeIdCount() { + return multifileFacadeId_.size(); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public int getMultifileFacadeId(int index) { + return multifileFacadeId_.get(index); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder setMultifileFacadeId( + int index, int value) { + ensureMultifileFacadeIdIsMutable(); + multifileFacadeId_.set(index, value); + onChanged(); + return this; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder addMultifileFacadeId(int value) { + ensureMultifileFacadeIdIsMutable(); + multifileFacadeId_.add(value); + onChanged(); + return this; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder addAllMultifileFacadeId( + java.lang.Iterable values) { + ensureMultifileFacadeIdIsMutable(); + org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll( + values, multifileFacadeId_); + onChanged(); + return this; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder clearMultifileFacadeId() { + multifileFacadeId_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + + private org.jetbrains.kotlin.protobuf.LazyStringList multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + private void ensureMultifileFacadeNameIsMutable() { + if (!((bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = new org.jetbrains.kotlin.protobuf.LazyStringArrayList(multifileFacadeName_); + bitField0_ |= 0x00000008; + } + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public org.jetbrains.kotlin.protobuf.ProtocolStringList + getMultifileFacadeNameList() { + return multifileFacadeName_.getUnmodifiableView(); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public int getMultifileFacadeNameCount() { + return multifileFacadeName_.size(); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public java.lang.String getMultifileFacadeName(int index) { + return multifileFacadeName_.get(index); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public org.jetbrains.kotlin.protobuf.ByteString + getMultifileFacadeNameBytes(int index) { + return multifileFacadeName_.getByteString(index); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder setMultifileFacadeName( + int index, java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.set(index, value); + onChanged(); + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder addMultifileFacadeName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.add(value); + onChanged(); + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder addAllMultifileFacadeName( + java.lang.Iterable values) { + ensureMultifileFacadeNameIsMutable(); + org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll( + values, multifileFacadeName_); + onChanged(); + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder clearMultifileFacadeName() { + multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); + onChanged(); + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder addMultifileFacadeNameBytes( + org.jetbrains.kotlin.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.add(value); + onChanged(); + return this; + } + // @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.jvm.PackageParts) } @@ -2052,9 +2563,11 @@ public final class DebugJvmPackageTable { "\022K\n\rpackage_parts\030\001 \003(\01324.org.jetbrains." + "kotlin.serialization.jvm.PackageParts\022L\n" + "\016metadata_parts\030\002 \003(\01324.org.jetbrains.ko" + - "tlin.serialization.jvm.PackageParts\";\n\014P" + + "tlin.serialization.jvm.PackageParts\"{\n\014P" + "ackageParts\022\027\n\017package_fq_name\030\001 \002(\t\022\022\n\n" + - "class_name\030\002 \003(\tB\026B\024DebugJvmPackageTable" + "class_name\030\002 \003(\t\022\037\n\023multifile_facade_id\030" + + "\003 \003(\005B\002\020\001\022\035\n\025multifile_facade_name\030\004 \003(\t", + "B\026B\024DebugJvmPackageTable" }; org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { @@ -2079,7 +2592,7 @@ public final class DebugJvmPackageTable { internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_fieldAccessorTable = new org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_org_jetbrains_kotlin_serialization_jvm_PackageParts_descriptor, - new java.lang.String[] { "PackageFqName", "ClassName", }); + new java.lang.String[] { "PackageFqName", "ClassName", "MultifileFacadeId", "MultifileFacadeName", }); } // @@protoc_insertion_point(outer_class_scope) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java index 669f8bf658b..5baf69f40c8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java @@ -185,13 +185,13 @@ public class ClassFileFactory implements OutputFileCollection { final String packageFqNameAsString = packageFqName.asString(); return new PackagePartRegistry() { @Override - public void addPart(@NotNull String partShortName) { + public void addPart(@NotNull String partShortName, @Nullable String facadeShortName) { PackageParts packageParts = partsGroupedByPackage.get(packageFqNameAsString); if (packageParts == null) { packageParts = new PackageParts(packageFqNameAsString); partsGroupedByPackage.put(packageFqNameAsString, packageParts); } - packageParts.addPart(partShortName); + packageParts.addPart(partShortName, facadeShortName); } }; } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt index 20ccd27cacf..42b9adfdd34 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt @@ -215,14 +215,13 @@ class MultifileClassCodegenImpl( if (!state.generateDeclaredClassFilter.shouldGeneratePackagePart(file) || !file.hasDeclarationsForPartClass()) return - val partInternalName = partType.internalName - packagePartRegistry.addPart(partInternalName.substring(partInternalName.lastIndexOf('/') + 1)) + packagePartRegistry.addPart(partType.internalName.substringAfterLast('/'), facadeClassType.internalName.substringAfterLast('/')) val builder = state.factory.newVisitor(MultifileClassPart(file, packageFragment), partType, file) MultifileClassPartCodegen( builder, file, packageFragment, - getSuperClassForPart(partInternalName), + getSuperClassForPart(partType.internalName), shouldGeneratePartHierarchy, partContext, state ).generate() diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java index af4cb608f40..7b1cd9836fe 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.SmartList; +import kotlin.text.StringsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.codegen.context.PackageContext; @@ -125,7 +126,7 @@ public class PackageCodegenImpl implements PackageCodegen { if (!generatePackagePart || !state.getGenerateDeclaredClassFilter().shouldGeneratePackagePart(file)) return; String name = fileClassType.getInternalName(); - packagePartRegistry.addPart(name.substring(name.lastIndexOf('/') + 1)); + packagePartRegistry.addPart(StringsKt.substringAfterLast(name, '/', name), null); ClassBuilder builder = state.getFactory().newVisitor(JvmDeclarationOriginKt.PackagePart(file, packageFragment), fileClassType, file); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt index 0b157191270..453fa63bafe 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt @@ -17,5 +17,5 @@ package org.jetbrains.kotlin.codegen interface PackagePartRegistry { - fun addPart(partShortName: String) + fun addPart(partShortName: String, facadeShortName: String?) } diff --git a/core/descriptor.loader.java/src/jvm_package_table.proto b/core/descriptor.loader.java/src/jvm_package_table.proto index 6c4f5dacefc..59f6c358d30 100644 --- a/core/descriptor.loader.java/src/jvm_package_table.proto +++ b/core/descriptor.loader.java/src/jvm_package_table.proto @@ -30,6 +30,15 @@ message PackageTable { message PackageParts { required string package_fq_name = 1; - // Short names of files, without extension, present in this package + // Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here + // (multi-file facades are not present in this list, they are defined below) repeated string class_name = 2; + + // For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1, + // or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0. + // (e.g. if there are no multi-file classes in the module, this list is not going to exist at all) + repeated int32 multifile_facade_id = 3 [packed=true]; + + // Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping. + repeated string multifile_facade_name = 4; } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/ModuleMapping.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/ModuleMapping.kt index aa9e4797d9e..4b556cf6b68 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/ModuleMapping.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/ModuleMapping.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.load.kotlin import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable import java.io.ByteArrayInputStream import java.io.DataInputStream +import kotlin.comparisons.nullsLast class ModuleMapping private constructor(val packageFqName2Parts: Map, private val debugName: String) { fun findPackageParts(packageFqName: String): PackageParts? { @@ -43,14 +44,23 @@ class ModuleMapping private constructor(val packageFqName2Parts: Map().apply { - addParts(this, parseFrom.packagePartsList, PackageParts::addPart) - addParts(this, parseFrom.metadataPartsList, PackageParts::addMetadataPart) + val table = JvmPackageTable.PackageTable.parseFrom(stream) ?: return EMPTY + val result = hashMapOf() + + for (proto in table.packagePartsList) { + val packageParts = result.getOrPut(proto.packageFqName) { PackageParts(proto.packageFqName) } + for ((index, partShortName) in proto.classNameList.withIndex()) { + val multifileFacadeId = proto.multifileFacadeIdList.getOrNull(index)?.minus(1) + packageParts.addPart(partShortName, multifileFacadeId?.let(proto.multifileFacadeNameList::getOrNull)) } - return ModuleMapping(packageFqNameParts, debugName ?: "") } + + for (proto in table.metadataPartsList) { + val packageParts = result.getOrPut(proto.packageFqName) { PackageParts(proto.packageFqName) } + proto.classNameList.forEach(packageParts::addMetadataPart) + } + + return ModuleMapping(result, debugName ?: "") } else { // TODO: consider reporting "incompatible ABI version" error for package parts @@ -58,47 +68,52 @@ class ModuleMapping private constructor(val packageFqName2Parts: Map, - partsList: List, - addPartOrMetadataPart: (PackageParts, String) -> Unit - ) { - for (proto in partsList) { - PackageParts(proto.packageFqName).apply { - result.put(proto.packageFqName, this) - proto.classNameList.forEach { addPartOrMetadataPart(this, it) } - } - } - } } } class PackageParts(val packageFqName: String) { - // See JvmPackageTable.PackageTable.package_parts - val parts: Set = linkedSetOf() - // See JvmPackageTable.PackageTable.metadata_parts - val metadataParts: Set = linkedSetOf() + // Short name of package part -> short name of the corresponding multifile facade (or null, if it's not a multifile part) + private val packageParts = linkedMapOf() - fun addPart(shortName: String) { - (parts as MutableSet /* see KT-14663 */).add(shortName) + // See JvmPackageTable.PackageTable.package_parts + val parts: Set get() = packageParts.keys + // See JvmPackageTable.PackageTable.metadata_parts + val metadataParts: Set = linkedSetOf() + + fun addPart(partShortName: String, facadeShortName: String?) { + packageParts[partShortName] = facadeShortName } fun removePart(shortName: String) { - (parts as MutableSet).remove(shortName) + packageParts.remove(shortName) } fun addMetadataPart(shortName: String) { - (metadataParts as MutableSet).add(shortName) + (metadataParts as MutableSet /* see KT-14663 */).add(shortName) } fun addTo(builder: JvmPackageTable.PackageTable.Builder) { if (parts.isNotEmpty()) { builder.addPackageParts(JvmPackageTable.PackageParts.newBuilder().apply { packageFqName = this@PackageParts.packageFqName - addAllClassName(parts.sorted()) + + val facadeNameToId = mutableMapOf() + for ((facadeName, partNames) in parts.groupBy { getMultifileFacadeName(it) }.toSortedMap(nullsLast())) { + for (partName in partNames.sorted()) { + addClassName(partName) + if (facadeName != null) { + addMultifileFacadeId(1 + facadeNameToId.getOrPut(facadeName) { facadeNameToId.size }) + } + } + } + + for ((facadeId, facadeName) in facadeNameToId.values.zip(facadeNameToId.keys).sortedBy(Pair::first)) { + assert(facadeId == multifileFacadeNameCount) { "Multifile facades are loaded incorrectly: $facadeNameToId" } + addMultifileFacadeName(facadeName) + } }) } + if (metadataParts.isNotEmpty()) { builder.addMetadataParts(JvmPackageTable.PackageParts.newBuilder().apply { packageFqName = this@PackageParts.packageFqName @@ -107,16 +122,21 @@ class PackageParts(val packageFqName: String) { } } + fun getMultifileFacadeName(partShortName: String): String? = packageParts[partShortName] + operator fun plusAssign(other: PackageParts) { - other.parts.forEach(this::addPart) + for ((partShortName, facadeShortName) in other.packageParts) { + addPart(partShortName, facadeShortName) + } other.metadataParts.forEach(this::addMetadataPart) } override fun equals(other: Any?) = - other is PackageParts && other.packageFqName == packageFqName && other.parts == parts && other.metadataParts == metadataParts + other is PackageParts && + other.packageFqName == packageFqName && other.packageParts == packageParts && other.metadataParts == metadataParts override fun hashCode() = - (packageFqName.hashCode() * 31 + parts.hashCode()) * 31 + metadataParts.hashCode() + (packageFqName.hashCode() * 31 + packageParts.hashCode()) * 31 + metadataParts.hashCode() override fun toString() = (parts + metadataParts).toString() diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmPackageTable.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmPackageTable.java index df4ed62cee1..06dabf20de4 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmPackageTable.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/serialization/jvm/JvmPackageTable.java @@ -905,7 +905,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ org.jetbrains.kotlin.protobuf.ProtocolStringList @@ -914,7 +915,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ int getClassNameCount(); @@ -922,7 +924,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ java.lang.String getClassName(int index); @@ -930,11 +933,78 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ org.jetbrains.kotlin.protobuf.ByteString getClassNameBytes(int index); + + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + java.util.List getMultifileFacadeIdList(); + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + int getMultifileFacadeIdCount(); + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + int getMultifileFacadeId(int index); + + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + org.jetbrains.kotlin.protobuf.ProtocolStringList + getMultifileFacadeNameList(); + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + int getMultifileFacadeNameCount(); + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + java.lang.String getMultifileFacadeName(int index); + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + org.jetbrains.kotlin.protobuf.ByteString + getMultifileFacadeNameBytes(int index); } /** * Protobuf type {@code org.jetbrains.kotlin.serialization.jvm.PackageParts} @@ -1001,6 +1071,36 @@ public final class JvmPackageTable { className_.add(bs); break; } + case 24: { + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000004; + } + multifileFacadeId_.add(input.readInt32()); + break; + } + case 26: { + int length = input.readRawVarint32(); + int limit = input.pushLimit(length); + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004) && input.getBytesUntilLimit() > 0) { + multifileFacadeId_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000004; + } + while (input.getBytesUntilLimit() > 0) { + multifileFacadeId_.add(input.readInt32()); + } + input.popLimit(limit); + break; + } + case 34: { + org.jetbrains.kotlin.protobuf.ByteString bs = input.readBytes(); + if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = new org.jetbrains.kotlin.protobuf.LazyStringArrayList(); + mutable_bitField0_ |= 0x00000008; + } + multifileFacadeName_.add(bs); + break; + } } } } catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) { @@ -1012,6 +1112,12 @@ public final class JvmPackageTable { if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { className_ = className_.getUnmodifiableView(); } + if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = java.util.Collections.unmodifiableList(multifileFacadeId_); + } + if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = multifileFacadeName_.getUnmodifiableView(); + } try { unknownFieldsCodedOutput.flush(); } catch (java.io.IOException e) { @@ -1086,7 +1192,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public org.jetbrains.kotlin.protobuf.ProtocolStringList @@ -1097,7 +1204,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public int getClassNameCount() { @@ -1107,7 +1215,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public java.lang.String getClassName(int index) { @@ -1117,7 +1226,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-     * Short names of files, without extension, present in this package
+     * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+     * (multi-file facades are not present in this list, they are defined below)
      * 
*/ public org.jetbrains.kotlin.protobuf.ByteString @@ -1125,9 +1235,97 @@ public final class JvmPackageTable { return className_.getByteString(index); } + public static final int MULTIFILE_FACADE_ID_FIELD_NUMBER = 3; + private java.util.List multifileFacadeId_; + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + public java.util.List + getMultifileFacadeIdList() { + return multifileFacadeId_; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + public int getMultifileFacadeIdCount() { + return multifileFacadeId_.size(); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+     * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+     * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+     * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+     * 
+ */ + public int getMultifileFacadeId(int index) { + return multifileFacadeId_.get(index); + } + private int multifileFacadeIdMemoizedSerializedSize = -1; + + public static final int MULTIFILE_FACADE_NAME_FIELD_NUMBER = 4; + private org.jetbrains.kotlin.protobuf.LazyStringList multifileFacadeName_; + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public org.jetbrains.kotlin.protobuf.ProtocolStringList + getMultifileFacadeNameList() { + return multifileFacadeName_; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public int getMultifileFacadeNameCount() { + return multifileFacadeName_.size(); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public java.lang.String getMultifileFacadeName(int index) { + return multifileFacadeName_.get(index); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+     * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+     * 
+ */ + public org.jetbrains.kotlin.protobuf.ByteString + getMultifileFacadeNameBytes(int index) { + return multifileFacadeName_.getByteString(index); + } + private void initFields() { packageFqName_ = ""; className_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + multifileFacadeId_ = java.util.Collections.emptyList(); + multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -1152,6 +1350,16 @@ public final class JvmPackageTable { for (int i = 0; i < className_.size(); i++) { output.writeBytes(2, className_.getByteString(i)); } + if (getMultifileFacadeIdList().size() > 0) { + output.writeRawVarint32(26); + output.writeRawVarint32(multifileFacadeIdMemoizedSerializedSize); + } + for (int i = 0; i < multifileFacadeId_.size(); i++) { + output.writeInt32NoTag(multifileFacadeId_.get(i)); + } + for (int i = 0; i < multifileFacadeName_.size(); i++) { + output.writeBytes(4, multifileFacadeName_.getByteString(i)); + } output.writeRawBytes(unknownFields); } @@ -1174,6 +1382,29 @@ public final class JvmPackageTable { size += dataSize; size += 1 * getClassNameList().size(); } + { + int dataSize = 0; + for (int i = 0; i < multifileFacadeId_.size(); i++) { + dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream + .computeInt32SizeNoTag(multifileFacadeId_.get(i)); + } + size += dataSize; + if (!getMultifileFacadeIdList().isEmpty()) { + size += 1; + size += org.jetbrains.kotlin.protobuf.CodedOutputStream + .computeInt32SizeNoTag(dataSize); + } + multifileFacadeIdMemoizedSerializedSize = dataSize; + } + { + int dataSize = 0; + for (int i = 0; i < multifileFacadeName_.size(); i++) { + dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream + .computeBytesSizeNoTag(multifileFacadeName_.getByteString(i)); + } + size += dataSize; + size += 1 * getMultifileFacadeNameList().size(); + } size += unknownFields.size(); memoizedSerializedSize = size; return size; @@ -1272,6 +1503,10 @@ public final class JvmPackageTable { bitField0_ = (bitField0_ & ~0x00000001); className_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; bitField0_ = (bitField0_ & ~0x00000002); + multifileFacadeId_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); return this; } @@ -1304,6 +1539,16 @@ public final class JvmPackageTable { bitField0_ = (bitField0_ & ~0x00000002); } result.className_ = className_; + if (((bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = java.util.Collections.unmodifiableList(multifileFacadeId_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.multifileFacadeId_ = multifileFacadeId_; + if (((bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = multifileFacadeName_.getUnmodifiableView(); + bitField0_ = (bitField0_ & ~0x00000008); + } + result.multifileFacadeName_ = multifileFacadeName_; result.bitField0_ = to_bitField0_; return result; } @@ -1324,6 +1569,26 @@ public final class JvmPackageTable { className_.addAll(other.className_); } + } + if (!other.multifileFacadeId_.isEmpty()) { + if (multifileFacadeId_.isEmpty()) { + multifileFacadeId_ = other.multifileFacadeId_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureMultifileFacadeIdIsMutable(); + multifileFacadeId_.addAll(other.multifileFacadeId_); + } + + } + if (!other.multifileFacadeName_.isEmpty()) { + if (multifileFacadeName_.isEmpty()) { + multifileFacadeName_ = other.multifileFacadeName_; + bitField0_ = (bitField0_ & ~0x00000008); + } else { + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.addAll(other.multifileFacadeName_); + } + } setUnknownFields( getUnknownFields().concat(other.unknownFields)); @@ -1444,7 +1709,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public org.jetbrains.kotlin.protobuf.ProtocolStringList @@ -1455,7 +1721,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public int getClassNameCount() { @@ -1465,7 +1732,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public java.lang.String getClassName(int index) { @@ -1475,7 +1743,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public org.jetbrains.kotlin.protobuf.ByteString @@ -1486,7 +1755,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder setClassName( @@ -1503,7 +1773,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder addClassName( @@ -1520,7 +1791,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder addAllClassName( @@ -1535,7 +1807,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder clearClassName() { @@ -1548,7 +1821,8 @@ public final class JvmPackageTable { * repeated string class_name = 2; * *
-       * Short names of files, without extension, present in this package
+       * Short names of files, without extension, present in this package. Only single file facades and multi-file _parts_ are listed here
+       * (multi-file facades are not present in this list, they are defined below)
        * 
*/ public Builder addClassNameBytes( @@ -1562,6 +1836,243 @@ public final class JvmPackageTable { return this; } + private java.util.List multifileFacadeId_ = java.util.Collections.emptyList(); + private void ensureMultifileFacadeIdIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + multifileFacadeId_ = new java.util.ArrayList(multifileFacadeId_); + bitField0_ |= 0x00000004; + } + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public java.util.List + getMultifileFacadeIdList() { + return java.util.Collections.unmodifiableList(multifileFacadeId_); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public int getMultifileFacadeIdCount() { + return multifileFacadeId_.size(); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public int getMultifileFacadeId(int index) { + return multifileFacadeId_.get(index); + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder setMultifileFacadeId( + int index, int value) { + ensureMultifileFacadeIdIsMutable(); + multifileFacadeId_.set(index, value); + + return this; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder addMultifileFacadeId(int value) { + ensureMultifileFacadeIdIsMutable(); + multifileFacadeId_.add(value); + + return this; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder addAllMultifileFacadeId( + java.lang.Iterable values) { + ensureMultifileFacadeIdIsMutable(); + org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll( + values, multifileFacadeId_); + + return this; + } + /** + * repeated int32 multifile_facade_id = 3 [packed = true]; + * + *
+       * For each class name listed above, index of the name of the corresponding multi-file facade class in multifile_facade_name + 1,
+       * or 0 if the class is not a multi-file part. If there's no value in this list at some index, the value is assumed to be 0.
+       * (e.g. if there are no multi-file classes in the module, this list is not going to exist at all)
+       * 
+ */ + public Builder clearMultifileFacadeId() { + multifileFacadeId_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + + return this; + } + + private org.jetbrains.kotlin.protobuf.LazyStringList multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + private void ensureMultifileFacadeNameIsMutable() { + if (!((bitField0_ & 0x00000008) == 0x00000008)) { + multifileFacadeName_ = new org.jetbrains.kotlin.protobuf.LazyStringArrayList(multifileFacadeName_); + bitField0_ |= 0x00000008; + } + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public org.jetbrains.kotlin.protobuf.ProtocolStringList + getMultifileFacadeNameList() { + return multifileFacadeName_.getUnmodifiableView(); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public int getMultifileFacadeNameCount() { + return multifileFacadeName_.size(); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public java.lang.String getMultifileFacadeName(int index) { + return multifileFacadeName_.get(index); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public org.jetbrains.kotlin.protobuf.ByteString + getMultifileFacadeNameBytes(int index) { + return multifileFacadeName_.getByteString(index); + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder setMultifileFacadeName( + int index, java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.set(index, value); + + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder addMultifileFacadeName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.add(value); + + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder addAllMultifileFacadeName( + java.lang.Iterable values) { + ensureMultifileFacadeNameIsMutable(); + org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll( + values, multifileFacadeName_); + + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder clearMultifileFacadeName() { + multifileFacadeName_ = org.jetbrains.kotlin.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); + + return this; + } + /** + * repeated string multifile_facade_name = 4; + * + *
+       * Short names of multi-file facades, used in multifile_facade_id to store the part -> facade mapping.
+       * 
+ */ + public Builder addMultifileFacadeNameBytes( + org.jetbrains.kotlin.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + ensureMultifileFacadeNameIsMutable(); + multifileFacadeName_.add(value); + + return this; + } + // @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.jvm.PackageParts) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/moduleMappingIndexes.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/moduleMappingIndexes.kt index fdc93c93ded..1cd4e225b23 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/moduleMappingIndexes.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/moduleMappingIndexes.kt @@ -42,13 +42,18 @@ object KotlinModuleMappingIndex : FileBasedIndexExtension( private val VALUE_EXTERNALIZER = object : DataExternalizer { override fun read(input: DataInput): PackageParts? = PackageParts(IOUtil.readUTF(input)).apply { - IOUtil.readStringList(input).forEach(this::addPart) + val shortPartNames = IOUtil.readStringList(input) + val shortFacadeNames = IOUtil.readStringList(input) + for ((partName, facadeName) in shortPartNames zip shortFacadeNames) { + addPart(partName, if (facadeName.isNotEmpty()) facadeName else null) + } IOUtil.readStringList(input).forEach(this::addMetadataPart) } - override fun save(out: DataOutput, value: PackageParts?) { - IOUtil.writeUTF(out, value!!.packageFqName) + override fun save(out: DataOutput, value: PackageParts) { + IOUtil.writeUTF(out, value.packageFqName) IOUtil.writeStringList(out, value.parts) + IOUtil.writeStringList(out, value.parts.map { value.getMultifileFacadeName(it).orEmpty() }) IOUtil.writeStringList(out, value.metadataParts) } } @@ -65,7 +70,7 @@ object KotlinModuleMappingIndex : FileBasedIndexExtension( return FileBasedIndex.InputFilter { file -> file.extension == ModuleMapping.MAPPING_FILE_EXT } } - override fun getVersion(): Int = 3 + override fun getVersion(): Int = 4 override fun getIndexer(): DataIndexer { return DataIndexer { inputData ->