Support new scheme of compilation of OptionalExpectation annotations
Instead of generating these annotation classes as package-private on JVM, serialize their metadata to the .kotlin_module file, and load it when compiling dependent multiplatform modules. The problem with generating them as package-private was that kotlin-stdlib for JVM would end up declaring symbols from other platforms, which would include some annotations from package kotlin.native. But using that package is discouraged by some tools because it has a Java keyword in its name. In particular, jlink refused to work with such artifact altogether (KT-21266). #KT-38652 Fixed
This commit is contained in:
committed by
Alexander Udalov
parent
63e355d979
commit
012ffa2993
@@ -38,6 +38,12 @@ message Module {
|
||||
|
||||
// Annotations on the whole module
|
||||
repeated Annotation annotation = 6;
|
||||
|
||||
// @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
// a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
// This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
// it to the corresponding class with the resolution capabilities of common modules.
|
||||
repeated Class optional_annotation_class = 16;
|
||||
}
|
||||
|
||||
message PackageParts {
|
||||
|
||||
@@ -146,6 +146,41 @@ public final class JvmModuleProtoBuf {
|
||||
* </pre>
|
||||
*/
|
||||
int getAnnotationCount();
|
||||
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
java.util.List<org.jetbrains.kotlin.metadata.ProtoBuf.Class>
|
||||
getOptionalAnnotationClassList();
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Class getOptionalAnnotationClass(int index);
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
int getOptionalAnnotationClassCount();
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code org.jetbrains.kotlin.metadata.jvm.Module}
|
||||
@@ -256,6 +291,14 @@ public final class JvmModuleProtoBuf {
|
||||
annotation_.add(input.readMessage(org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.PARSER, extensionRegistry));
|
||||
break;
|
||||
}
|
||||
case 130: {
|
||||
if (!((mutable_bitField0_ & 0x00000040) == 0x00000040)) {
|
||||
optionalAnnotationClass_ = new java.util.ArrayList<org.jetbrains.kotlin.metadata.ProtoBuf.Class>();
|
||||
mutable_bitField0_ |= 0x00000040;
|
||||
}
|
||||
optionalAnnotationClass_.add(input.readMessage(org.jetbrains.kotlin.metadata.ProtoBuf.Class.PARSER, extensionRegistry));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
|
||||
@@ -276,6 +319,9 @@ public final class JvmModuleProtoBuf {
|
||||
if (((mutable_bitField0_ & 0x00000020) == 0x00000020)) {
|
||||
annotation_ = java.util.Collections.unmodifiableList(annotation_);
|
||||
}
|
||||
if (((mutable_bitField0_ & 0x00000040) == 0x00000040)) {
|
||||
optionalAnnotationClass_ = java.util.Collections.unmodifiableList(optionalAnnotationClass_);
|
||||
}
|
||||
try {
|
||||
unknownFieldsCodedOutput.flush();
|
||||
} catch (java.io.IOException e) {
|
||||
@@ -546,6 +592,76 @@ public final class JvmModuleProtoBuf {
|
||||
return annotation_.get(index);
|
||||
}
|
||||
|
||||
public static final int OPTIONAL_ANNOTATION_CLASS_FIELD_NUMBER = 16;
|
||||
private java.util.List<org.jetbrains.kotlin.metadata.ProtoBuf.Class> optionalAnnotationClass_;
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public java.util.List<org.jetbrains.kotlin.metadata.ProtoBuf.Class> getOptionalAnnotationClassList() {
|
||||
return optionalAnnotationClass_;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public java.util.List<? extends org.jetbrains.kotlin.metadata.ProtoBuf.ClassOrBuilder>
|
||||
getOptionalAnnotationClassOrBuilderList() {
|
||||
return optionalAnnotationClass_;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public int getOptionalAnnotationClassCount() {
|
||||
return optionalAnnotationClass_.size();
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public org.jetbrains.kotlin.metadata.ProtoBuf.Class getOptionalAnnotationClass(int index) {
|
||||
return optionalAnnotationClass_.get(index);
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public org.jetbrains.kotlin.metadata.ProtoBuf.ClassOrBuilder getOptionalAnnotationClassOrBuilder(
|
||||
int index) {
|
||||
return optionalAnnotationClass_.get(index);
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
packageParts_ = java.util.Collections.emptyList();
|
||||
metadataParts_ = java.util.Collections.emptyList();
|
||||
@@ -553,6 +669,7 @@ public final class JvmModuleProtoBuf {
|
||||
stringTable_ = org.jetbrains.kotlin.metadata.ProtoBuf.StringTable.getDefaultInstance();
|
||||
qualifiedNameTable_ = org.jetbrains.kotlin.metadata.ProtoBuf.QualifiedNameTable.getDefaultInstance();
|
||||
annotation_ = java.util.Collections.emptyList();
|
||||
optionalAnnotationClass_ = java.util.Collections.emptyList();
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
@@ -584,6 +701,12 @@ public final class JvmModuleProtoBuf {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < getOptionalAnnotationClassCount(); i++) {
|
||||
if (!getOptionalAnnotationClass(i).isInitialized()) {
|
||||
memoizedIsInitialized = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
@@ -609,6 +732,9 @@ public final class JvmModuleProtoBuf {
|
||||
for (int i = 0; i < annotation_.size(); i++) {
|
||||
output.writeMessage(6, annotation_.get(i));
|
||||
}
|
||||
for (int i = 0; i < optionalAnnotationClass_.size(); i++) {
|
||||
output.writeMessage(16, optionalAnnotationClass_.get(i));
|
||||
}
|
||||
output.writeRawBytes(unknownFields);
|
||||
}
|
||||
|
||||
@@ -647,6 +773,10 @@ public final class JvmModuleProtoBuf {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeMessageSize(6, annotation_.get(i));
|
||||
}
|
||||
for (int i = 0; i < optionalAnnotationClass_.size(); i++) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeMessageSize(16, optionalAnnotationClass_.get(i));
|
||||
}
|
||||
size += unknownFields.size();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
@@ -753,6 +883,8 @@ public final class JvmModuleProtoBuf {
|
||||
bitField0_ = (bitField0_ & ~0x00000010);
|
||||
annotation_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
optionalAnnotationClass_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000040);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -804,6 +936,11 @@ public final class JvmModuleProtoBuf {
|
||||
bitField0_ = (bitField0_ & ~0x00000020);
|
||||
}
|
||||
result.annotation_ = annotation_;
|
||||
if (((bitField0_ & 0x00000040) == 0x00000040)) {
|
||||
optionalAnnotationClass_ = java.util.Collections.unmodifiableList(optionalAnnotationClass_);
|
||||
bitField0_ = (bitField0_ & ~0x00000040);
|
||||
}
|
||||
result.optionalAnnotationClass_ = optionalAnnotationClass_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
return result;
|
||||
}
|
||||
@@ -855,6 +992,16 @@ public final class JvmModuleProtoBuf {
|
||||
annotation_.addAll(other.annotation_);
|
||||
}
|
||||
|
||||
}
|
||||
if (!other.optionalAnnotationClass_.isEmpty()) {
|
||||
if (optionalAnnotationClass_.isEmpty()) {
|
||||
optionalAnnotationClass_ = other.optionalAnnotationClass_;
|
||||
bitField0_ = (bitField0_ & ~0x00000040);
|
||||
} else {
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.addAll(other.optionalAnnotationClass_);
|
||||
}
|
||||
|
||||
}
|
||||
setUnknownFields(
|
||||
getUnknownFields().concat(other.unknownFields));
|
||||
@@ -886,6 +1033,12 @@ public final class JvmModuleProtoBuf {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < getOptionalAnnotationClassCount(); i++) {
|
||||
if (!getOptionalAnnotationClass(i).isInitialized()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1685,6 +1838,215 @@ public final class JvmModuleProtoBuf {
|
||||
return this;
|
||||
}
|
||||
|
||||
private java.util.List<org.jetbrains.kotlin.metadata.ProtoBuf.Class> optionalAnnotationClass_ =
|
||||
java.util.Collections.emptyList();
|
||||
private void ensureOptionalAnnotationClassIsMutable() {
|
||||
if (!((bitField0_ & 0x00000040) == 0x00000040)) {
|
||||
optionalAnnotationClass_ = new java.util.ArrayList<org.jetbrains.kotlin.metadata.ProtoBuf.Class>(optionalAnnotationClass_);
|
||||
bitField0_ |= 0x00000040;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public java.util.List<org.jetbrains.kotlin.metadata.ProtoBuf.Class> getOptionalAnnotationClassList() {
|
||||
return java.util.Collections.unmodifiableList(optionalAnnotationClass_);
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public int getOptionalAnnotationClassCount() {
|
||||
return optionalAnnotationClass_.size();
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public org.jetbrains.kotlin.metadata.ProtoBuf.Class getOptionalAnnotationClass(int index) {
|
||||
return optionalAnnotationClass_.get(index);
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setOptionalAnnotationClass(
|
||||
int index, org.jetbrains.kotlin.metadata.ProtoBuf.Class value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.set(index, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setOptionalAnnotationClass(
|
||||
int index, org.jetbrains.kotlin.metadata.ProtoBuf.Class.Builder builderForValue) {
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.set(index, builderForValue.build());
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder addOptionalAnnotationClass(org.jetbrains.kotlin.metadata.ProtoBuf.Class value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.add(value);
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder addOptionalAnnotationClass(
|
||||
int index, org.jetbrains.kotlin.metadata.ProtoBuf.Class value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.add(index, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder addOptionalAnnotationClass(
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Class.Builder builderForValue) {
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.add(builderForValue.build());
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder addOptionalAnnotationClass(
|
||||
int index, org.jetbrains.kotlin.metadata.ProtoBuf.Class.Builder builderForValue) {
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.add(index, builderForValue.build());
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder addAllOptionalAnnotationClass(
|
||||
java.lang.Iterable<? extends org.jetbrains.kotlin.metadata.ProtoBuf.Class> values) {
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
|
||||
values, optionalAnnotationClass_);
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearOptionalAnnotationClass() {
|
||||
optionalAnnotationClass_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000040);
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;</code>
|
||||
*
|
||||
* <pre>
|
||||
* @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
|
||||
* a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
|
||||
* This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
|
||||
* it to the corresponding class with the resolution capabilities of common modules.
|
||||
* </pre>
|
||||
*/
|
||||
public Builder removeOptionalAnnotationClass(int index) {
|
||||
ensureOptionalAnnotationClassIsMutable();
|
||||
optionalAnnotationClass_.remove(index);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.metadata.jvm.Module)
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -5,7 +5,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.metadata.jvm.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
|
||||
/**
|
||||
* @param annotations list of module annotations, in the format: "org/foo/bar/Baz.Inner" (see [ClassId.fromString])
|
||||
* @param optionalAnnotations list of @OptionalExpectation-annotated annotation classes in this module.
|
||||
* @param nameResolver string table to resolve names referenced in classes in [optionalAnnotations].
|
||||
*/
|
||||
class BinaryModuleData(val annotations: List<String>)
|
||||
class BinaryModuleData(
|
||||
val annotations: List<String>,
|
||||
val optionalAnnotations: List<ProtoBuf.Class>,
|
||||
val nameResolver: NameResolver,
|
||||
)
|
||||
|
||||
+22
-4
@@ -5,13 +5,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.metadata.jvm.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.metadata.deserialization.isKotlin1Dot4OrLater
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import java.io.*
|
||||
|
||||
class ModuleMapping private constructor(
|
||||
val version: JvmMetadataVersion,
|
||||
val packageFqName2Parts: Map<String, PackageParts>,
|
||||
val moduleData: BinaryModuleData,
|
||||
private val debugName: String
|
||||
@@ -26,10 +30,10 @@ class ModuleMapping private constructor(
|
||||
const val MAPPING_FILE_EXT: String = "kotlin_module"
|
||||
|
||||
@JvmField
|
||||
val EMPTY: ModuleMapping = ModuleMapping(emptyMap(), BinaryModuleData(emptyList()), "EMPTY")
|
||||
val EMPTY: ModuleMapping = ModuleMapping(JvmMetadataVersion.INSTANCE, emptyMap(), emptyBinaryData(), "EMPTY")
|
||||
|
||||
@JvmField
|
||||
val CORRUPTED: ModuleMapping = ModuleMapping(emptyMap(), BinaryModuleData(emptyList()), "CORRUPTED")
|
||||
val CORRUPTED: ModuleMapping = ModuleMapping(JvmMetadataVersion.INSTANCE, emptyMap(), emptyBinaryData(), "CORRUPTED")
|
||||
|
||||
const val STRICT_METADATA_VERSION_SEMANTICS_FLAG = 1 shl 0
|
||||
|
||||
@@ -69,7 +73,9 @@ class ModuleMapping private constructor(
|
||||
return EMPTY
|
||||
}
|
||||
|
||||
val moduleProto = JvmModuleProtoBuf.Module.parseFrom(stream) ?: return EMPTY
|
||||
// "Builtin" extension registry is needed in order to deserialize annotations on optional annotation classes and their members.
|
||||
val extensions = ExtensionRegistryLite.newInstance().apply(BuiltInsProtoBuf::registerAllExtensions)
|
||||
val moduleProto = JvmModuleProtoBuf.Module.parseFrom(stream, extensions) ?: return EMPTY
|
||||
val result = linkedMapOf<String, PackageParts>()
|
||||
|
||||
for (proto in moduleProto.packagePartsList) {
|
||||
@@ -114,7 +120,12 @@ class ModuleMapping private constructor(
|
||||
val nameResolver = NameResolverImpl(moduleProto.stringTable, moduleProto.qualifiedNameTable)
|
||||
val annotations = moduleProto.annotationList.map { proto -> nameResolver.getQualifiedClassName(proto.id) }
|
||||
|
||||
return ModuleMapping(result, BinaryModuleData(annotations), debugName)
|
||||
return ModuleMapping(
|
||||
version,
|
||||
result,
|
||||
BinaryModuleData(annotations, moduleProto.optionalAnnotationClassList, nameResolver),
|
||||
debugName
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadMultiFileFacadeInternalName(
|
||||
@@ -127,6 +138,13 @@ class ModuleMapping private constructor(
|
||||
val facadeShortName = multifileFacadeId?.let(multifileFacadeShortNames::getOrNull)
|
||||
return facadeShortName?.let { internalNameOf(packageFqName, it) }
|
||||
}
|
||||
|
||||
private fun emptyBinaryData(): BinaryModuleData =
|
||||
BinaryModuleData(
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
NameResolverImpl(ProtoBuf.StringTable.getDefaultInstance(), ProtoBuf.QualifiedNameTable.getDefaultInstance())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user