JS: serialize .kjsm package-wise, adapt decompiler & stub builder
Instead of multiple .kjsm files for different classes and .kotlin_string_table, .kotlin_file_table, .kotlin_classes files for each package, serialize the contents of each package to a single foo/bar/baz/baz.kjsm file. The short name of the file is the last segment in the FQ name of the package, or "root-package" if the package is root. There are two main reasons for this change: 1) Such structure takes less space, is more IO-friendly and will not cause multiple exceptions as the old one, where we sometimes tried to read non-existing files 2) This is exactly the same format that is used to serialize built-in declarations (.kotlin_builtins) at the moment, which will allow us to reuse some code Also write a separate Header protobuf message to the beginning of the .kjsm file. This will be used as arguments of the kotlin.Metadata annotation are used in the JVM-specific parts of the compiler: to be able to provide some general information about the binary file without parsing the whole protobuf data. This commit breaks decompiled text & stub builder consistency tests. This is OK because they're removed in a future commit. Fixes EA-79605, EA-81947, EA-84277 and maybe EA-86787 #KT-10894 Fixed #KT-14124 Fixed #KT-15755 Fixed
This commit is contained in:
@@ -21,6 +21,702 @@ public final class DebugJsProtoBuf {
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.typeAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.typeParameterAnnotation);
|
||||
}
|
||||
public interface HeaderOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:org.jetbrains.kotlin.serialization.js.Header)
|
||||
org.jetbrains.kotlin.protobuf.MessageOrBuilder {
|
||||
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
boolean hasFlags();
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
int getFlags();
|
||||
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
boolean hasJsCodeBinaryVersion();
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
int getJsCodeBinaryVersion();
|
||||
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
boolean hasPackageFqName();
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
java.lang.String getPackageFqName();
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
org.jetbrains.kotlin.protobuf.ByteString
|
||||
getPackageFqNameBytes();
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code org.jetbrains.kotlin.serialization.js.Header}
|
||||
*/
|
||||
public static final class Header extends
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage implements
|
||||
// @@protoc_insertion_point(message_implements:org.jetbrains.kotlin.serialization.js.Header)
|
||||
HeaderOrBuilder {
|
||||
// Use Header.newBuilder() to construct.
|
||||
private Header(org.jetbrains.kotlin.protobuf.GeneratedMessage.Builder<?> builder) {
|
||||
super(builder);
|
||||
this.unknownFields = builder.getUnknownFields();
|
||||
}
|
||||
private Header(boolean noInit) { this.unknownFields = org.jetbrains.kotlin.protobuf.UnknownFieldSet.getDefaultInstance(); }
|
||||
|
||||
private static final Header defaultInstance;
|
||||
public static Header getDefaultInstance() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public Header getDefaultInstanceForType() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
private final org.jetbrains.kotlin.protobuf.UnknownFieldSet unknownFields;
|
||||
@java.lang.Override
|
||||
public final org.jetbrains.kotlin.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private Header(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
initFields();
|
||||
int mutable_bitField0_ = 0;
|
||||
org.jetbrains.kotlin.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
org.jetbrains.kotlin.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
default: {
|
||||
if (!parseUnknownField(input, unknownFields,
|
||||
extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
bitField0_ |= 0x00000001;
|
||||
flags_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
bitField0_ |= 0x00000002;
|
||||
jsCodeBinaryVersion_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
case 26: {
|
||||
org.jetbrains.kotlin.protobuf.ByteString bs = input.readBytes();
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = bs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException(
|
||||
e.getMessage()).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.internal_static_org_jetbrains_kotlin_serialization_js_Header_descriptor;
|
||||
}
|
||||
|
||||
protected org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.internal_static_org_jetbrains_kotlin_serialization_js_Header_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header.class, org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header.Builder.class);
|
||||
}
|
||||
|
||||
public static org.jetbrains.kotlin.protobuf.Parser<Header> PARSER =
|
||||
new org.jetbrains.kotlin.protobuf.AbstractParser<Header>() {
|
||||
public Header parsePartialFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return new Header(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
@java.lang.Override
|
||||
public org.jetbrains.kotlin.protobuf.Parser<Header> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
public static final int FLAGS_FIELD_NUMBER = 1;
|
||||
private int flags_;
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasFlags() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public int getFlags() {
|
||||
return flags_;
|
||||
}
|
||||
|
||||
public static final int JS_CODE_BINARY_VERSION_FIELD_NUMBER = 2;
|
||||
private int jsCodeBinaryVersion_;
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasJsCodeBinaryVersion() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public int getJsCodeBinaryVersion() {
|
||||
return jsCodeBinaryVersion_;
|
||||
}
|
||||
|
||||
public static final int PACKAGE_FQ_NAME_FIELD_NUMBER = 3;
|
||||
private java.lang.Object packageFqName_;
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public boolean hasPackageFqName() {
|
||||
return ((bitField0_ & 0x00000004) == 0x00000004);
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public java.lang.String getPackageFqName() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
return (java.lang.String) ref;
|
||||
} else {
|
||||
org.jetbrains.kotlin.protobuf.ByteString bs =
|
||||
(org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
java.lang.String s = bs.toStringUtf8();
|
||||
if (bs.isValidUtf8()) {
|
||||
packageFqName_ = s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public org.jetbrains.kotlin.protobuf.ByteString
|
||||
getPackageFqNameBytes() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
org.jetbrains.kotlin.protobuf.ByteString b =
|
||||
org.jetbrains.kotlin.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
packageFqName_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
flags_ = 0;
|
||||
jsCodeBinaryVersion_ = 0;
|
||||
packageFqName_ = "";
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized == 1) return true;
|
||||
if (isInitialized == 0) return false;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeTo(org.jetbrains.kotlin.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
getSerializedSize();
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
output.writeInt32(1, flags_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
output.writeInt32(2, jsCodeBinaryVersion_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000004) == 0x00000004)) {
|
||||
output.writeBytes(3, getPackageFqNameBytes());
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeInt32Size(1, flags_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeInt32Size(2, jsCodeBinaryVersion_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000004) == 0x00000004)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeBytesSize(3, getPackageFqNameBytes());
|
||||
}
|
||||
size += getUnknownFields().getSerializedSize();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
@java.lang.Override
|
||||
protected java.lang.Object writeReplace()
|
||||
throws java.io.ObjectStreamException {
|
||||
return super.writeReplace();
|
||||
}
|
||||
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.ByteString data)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.ByteString data,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(byte[] data)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(
|
||||
byte[] data,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(
|
||||
java.io.InputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static Builder newBuilder() { return Builder.create(); }
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header prototype) {
|
||||
return newBuilder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() { return newBuilder(this); }
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code org.jetbrains.kotlin.serialization.js.Header}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:org.jetbrains.kotlin.serialization.js.Header)
|
||||
org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.HeaderOrBuilder {
|
||||
public static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.internal_static_org_jetbrains_kotlin_serialization_js_Header_descriptor;
|
||||
}
|
||||
|
||||
protected org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.internal_static_org_jetbrains_kotlin_serialization_js_Header_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header.class, org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (org.jetbrains.kotlin.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
private static Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
flags_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
jsCodeBinaryVersion_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
packageFqName_ = "";
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clone() {
|
||||
return create().mergeFrom(buildPartial());
|
||||
}
|
||||
|
||||
public org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.internal_static_org_jetbrains_kotlin_serialization_js_Header_descriptor;
|
||||
}
|
||||
|
||||
public org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header getDefaultInstanceForType() {
|
||||
return org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header.getDefaultInstance();
|
||||
}
|
||||
|
||||
public org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header build() {
|
||||
org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header buildPartial() {
|
||||
org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header result = new org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header(this);
|
||||
int from_bitField0_ = bitField0_;
|
||||
int to_bitField0_ = 0;
|
||||
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
to_bitField0_ |= 0x00000001;
|
||||
}
|
||||
result.flags_ = flags_;
|
||||
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
to_bitField0_ |= 0x00000002;
|
||||
}
|
||||
result.jsCodeBinaryVersion_ = jsCodeBinaryVersion_;
|
||||
if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
|
||||
to_bitField0_ |= 0x00000004;
|
||||
}
|
||||
result.packageFqName_ = packageFqName_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(org.jetbrains.kotlin.protobuf.Message other) {
|
||||
if (other instanceof org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header) {
|
||||
return mergeFrom((org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header other) {
|
||||
if (other == org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header.getDefaultInstance()) return this;
|
||||
if (other.hasFlags()) {
|
||||
setFlags(other.getFlags());
|
||||
}
|
||||
if (other.hasJsCodeBinaryVersion()) {
|
||||
setJsCodeBinaryVersion(other.getJsCodeBinaryVersion());
|
||||
}
|
||||
if (other.hasPackageFqName()) {
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = other.packageFqName_;
|
||||
onChanged();
|
||||
}
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (org.jetbrains.kotlin.serialization.js.DebugJsProtoBuf.Header) e.getUnfinishedMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
private int flags_ ;
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasFlags() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public int getFlags() {
|
||||
return flags_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setFlags(int value) {
|
||||
bitField0_ |= 0x00000001;
|
||||
flags_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearFlags() {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
flags_ = 0;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
private int jsCodeBinaryVersion_ ;
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasJsCodeBinaryVersion() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public int getJsCodeBinaryVersion() {
|
||||
return jsCodeBinaryVersion_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setJsCodeBinaryVersion(int value) {
|
||||
bitField0_ |= 0x00000002;
|
||||
jsCodeBinaryVersion_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearJsCodeBinaryVersion() {
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
jsCodeBinaryVersion_ = 0;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
private java.lang.Object packageFqName_ = "";
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public boolean hasPackageFqName() {
|
||||
return ((bitField0_ & 0x00000004) == 0x00000004);
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public java.lang.String getPackageFqName() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (!(ref instanceof java.lang.String)) {
|
||||
org.jetbrains.kotlin.protobuf.ByteString bs =
|
||||
(org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
java.lang.String s = bs.toStringUtf8();
|
||||
if (bs.isValidUtf8()) {
|
||||
packageFqName_ = s;
|
||||
}
|
||||
return s;
|
||||
} else {
|
||||
return (java.lang.String) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public org.jetbrains.kotlin.protobuf.ByteString
|
||||
getPackageFqNameBytes() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (ref instanceof String) {
|
||||
org.jetbrains.kotlin.protobuf.ByteString b =
|
||||
org.jetbrains.kotlin.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
packageFqName_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public Builder setPackageFqName(
|
||||
java.lang.String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public Builder clearPackageFqName() {
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
packageFqName_ = getDefaultInstance().getPackageFqName();
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public Builder setPackageFqNameBytes(
|
||||
org.jetbrains.kotlin.protobuf.ByteString value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.js.Header)
|
||||
}
|
||||
|
||||
static {
|
||||
defaultInstance = new Header(true);
|
||||
defaultInstance.initFields();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.js.Header)
|
||||
}
|
||||
|
||||
public interface FileOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:org.jetbrains.kotlin.serialization.js.File)
|
||||
org.jetbrains.kotlin.protobuf.MessageOrBuilder {
|
||||
@@ -4716,6 +5412,11 @@ public final class DebugJsProtoBuf {
|
||||
.newFileScopedGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.class,
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.Annotation.getDefaultInstance());
|
||||
private static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Header_descriptor;
|
||||
private static
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Header_fieldAccessorTable;
|
||||
private static final org.jetbrains.kotlin.protobuf.Descriptors.Descriptor
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_File_descriptor;
|
||||
private static
|
||||
@@ -4753,63 +5454,65 @@ public final class DebugJsProtoBuf {
|
||||
"\n#js/js.serializer/src/js.debug.proto\022%o" +
|
||||
"rg.jetbrains.kotlin.serialization.js\0320co" +
|
||||
"re/deserialization/src/descriptors.debug" +
|
||||
".proto\"V\n\004File\022\n\n\002id\030\001 \002(\005\022B\n\nannotation" +
|
||||
"\030\002 \003(\0132..org.jetbrains.kotlin.serializat" +
|
||||
"ion.Annotation\"B\n\005Files\0229\n\004file\030\001 \003(\0132+." +
|
||||
"org.jetbrains.kotlin.serialization.js.Fi" +
|
||||
"le\"!\n\007Classes\022\026\n\nclass_name\030\001 \003(\005B\002\020\001\"\265\004" +
|
||||
"\n\007Library\022H\n\004kind\030\001 \001(\01623.org.jetbrains." +
|
||||
"kotlin.serialization.js.Library.Kind:\005PL",
|
||||
"AIN\022A\n\004part\030\002 \003(\01323.org.jetbrains.kotlin" +
|
||||
".serialization.js.Library.Part\022\027\n\017import" +
|
||||
"ed_module\030\003 \003(\t\032\317\002\n\004Part\022@\n\007strings\030\001 \001(" +
|
||||
"\0132/.org.jetbrains.kotlin.serialization.S" +
|
||||
"tringTable\022O\n\017qualified_names\030\002 \001(\01326.or" +
|
||||
"g.jetbrains.kotlin.serialization.Qualifi" +
|
||||
"edNameTable\022<\n\007package\030\003 \001(\0132+.org.jetbr" +
|
||||
"ains.kotlin.serialization.Package\0228\n\005cla" +
|
||||
"ss\030\004 \003(\0132).org.jetbrains.kotlin.serializ" +
|
||||
"ation.Class\022<\n\005files\030\202\001 \001(\0132,.org.jetbra",
|
||||
"ins.kotlin.serialization.js.Files\"2\n\004Kin" +
|
||||
"d\022\t\n\005PLAIN\020\001\022\007\n\003AMD\020\002\022\r\n\tCOMMON_JS\020\003\022\007\n\003" +
|
||||
"UMD\020\004:E\n\017package_fq_name\022+.org.jetbrains" +
|
||||
".kotlin.serialization.Package\030\203\001 \001(\005:t\n\020" +
|
||||
"class_annotation\022).org.jetbrains.kotlin." +
|
||||
"serialization.Class\030\202\001 \003(\0132..org.jetbrai" +
|
||||
"ns.kotlin.serialization.Annotation:L\n\030cl" +
|
||||
"ass_containing_file_id\022).org.jetbrains.k" +
|
||||
"otlin.serialization.Class\030\207\001 \001(\005:\200\001\n\026con" +
|
||||
"structor_annotation\022/.org.jetbrains.kotl",
|
||||
"in.serialization.Constructor\030\202\001 \003(\0132..or" +
|
||||
"g.jetbrains.kotlin.serialization.Annotat" +
|
||||
"ion:z\n\023function_annotation\022,.org.jetbrai" +
|
||||
"ns.kotlin.serialization.Function\030\202\001 \003(\0132" +
|
||||
"..org.jetbrains.kotlin.serialization.Ann" +
|
||||
"otation:R\n\033function_containing_file_id\022," +
|
||||
".org.jetbrains.kotlin.serialization.Func" +
|
||||
"tion\030\207\001 \001(\005:z\n\023property_annotation\022,.org" +
|
||||
".jetbrains.kotlin.serialization.Property" +
|
||||
"\030\202\001 \003(\0132..org.jetbrains.kotlin.serializa",
|
||||
"tion.Annotation:\210\001\n\022compile_time_value\022," +
|
||||
".org.jetbrains.kotlin.serialization.Prop" +
|
||||
"erty\030\203\001 \001(\0132=.org.jetbrains.kotlin.seria" +
|
||||
"lization.Annotation.Argument.Value:R\n\033pr" +
|
||||
"operty_containing_file_id\022,.org.jetbrain" +
|
||||
"s.kotlin.serialization.Property\030\207\001 \001(\005:}" +
|
||||
"\n\025enum_entry_annotation\022-.org.jetbrains." +
|
||||
"kotlin.serialization.EnumEntry\030\202\001 \003(\0132.." +
|
||||
".proto\"P\n\006Header\022\r\n\005flags\030\001 \001(\005\022\036\n\026js_co" +
|
||||
"de_binary_version\030\002 \001(\005\022\027\n\017package_fq_na" +
|
||||
"me\030\003 \001(\t\"V\n\004File\022\n\n\002id\030\001 \002(\005\022B\n\nannotati" +
|
||||
"on\030\002 \003(\0132..org.jetbrains.kotlin.serializ" +
|
||||
"ation.Annotation\"B\n\005Files\0229\n\004file\030\001 \003(\0132" +
|
||||
"+.org.jetbrains.kotlin.serialization.js." +
|
||||
"File\"!\n\007Classes\022\026\n\nclass_name\030\001 \003(\005B\002\020\001\"",
|
||||
"\265\004\n\007Library\022H\n\004kind\030\001 \001(\01623.org.jetbrain" +
|
||||
"s.kotlin.serialization.js.Library.Kind:\005" +
|
||||
"PLAIN\022A\n\004part\030\002 \003(\01323.org.jetbrains.kotl" +
|
||||
"in.serialization.js.Library.Part\022\027\n\017impo" +
|
||||
"rted_module\030\003 \003(\t\032\317\002\n\004Part\022@\n\007strings\030\001 " +
|
||||
"\001(\0132/.org.jetbrains.kotlin.serialization" +
|
||||
".StringTable\022O\n\017qualified_names\030\002 \001(\01326." +
|
||||
"org.jetbrains.kotlin.serialization.Quali" +
|
||||
"fiedNameTable\022<\n\007package\030\003 \001(\0132+.org.jet" +
|
||||
"brains.kotlin.serialization.Package\0228\n\005c",
|
||||
"lass\030\004 \003(\0132).org.jetbrains.kotlin.serial" +
|
||||
"ization.Class\022<\n\005files\030\202\001 \001(\0132,.org.jetb" +
|
||||
"rains.kotlin.serialization.js.Files\"2\n\004K" +
|
||||
"ind\022\t\n\005PLAIN\020\001\022\007\n\003AMD\020\002\022\r\n\tCOMMON_JS\020\003\022\007" +
|
||||
"\n\003UMD\020\004:E\n\017package_fq_name\022+.org.jetbrai" +
|
||||
"ns.kotlin.serialization.Package\030\203\001 \001(\005:t" +
|
||||
"\n\020class_annotation\022).org.jetbrains.kotli" +
|
||||
"n.serialization.Class\030\202\001 \003(\0132..org.jetbr" +
|
||||
"ains.kotlin.serialization.Annotation:L\n\030" +
|
||||
"class_containing_file_id\022).org.jetbrains",
|
||||
".kotlin.serialization.Class\030\207\001 \001(\005:\200\001\n\026c" +
|
||||
"onstructor_annotation\022/.org.jetbrains.ko" +
|
||||
"tlin.serialization.Constructor\030\202\001 \003(\0132.." +
|
||||
"org.jetbrains.kotlin.serialization.Annot" +
|
||||
"ation:\201\001\n\024parameter_annotation\0222.org.jet",
|
||||
"brains.kotlin.serialization.ValueParamet" +
|
||||
"er\030\202\001 \003(\0132..org.jetbrains.kotlin.seriali" +
|
||||
"zation.Annotation:r\n\017type_annotation\022(.o" +
|
||||
"rg.jetbrains.kotlin.serialization.Type\030\202" +
|
||||
"\001 \003(\0132..org.jetbrains.kotlin.serializati" +
|
||||
"on.Annotation:\205\001\n\031type_parameter_annotat" +
|
||||
"ion\0221.org.jetbrains.kotlin.serialization" +
|
||||
".TypeParameter\030\202\001 \003(\0132..org.jetbrains.ko" +
|
||||
"tlin.serialization.AnnotationB\021B\017DebugJs" +
|
||||
"ProtoBuf"
|
||||
"ation:z\n\023function_annotation\022,.org.jetbr" +
|
||||
"ains.kotlin.serialization.Function\030\202\001 \003(" +
|
||||
"\0132..org.jetbrains.kotlin.serialization.A" +
|
||||
"nnotation:R\n\033function_containing_file_id" +
|
||||
"\022,.org.jetbrains.kotlin.serialization.Fu" +
|
||||
"nction\030\207\001 \001(\005:z\n\023property_annotation\022,.o",
|
||||
"rg.jetbrains.kotlin.serialization.Proper" +
|
||||
"ty\030\202\001 \003(\0132..org.jetbrains.kotlin.seriali" +
|
||||
"zation.Annotation:\210\001\n\022compile_time_value" +
|
||||
"\022,.org.jetbrains.kotlin.serialization.Pr" +
|
||||
"operty\030\203\001 \001(\0132=.org.jetbrains.kotlin.ser" +
|
||||
"ialization.Annotation.Argument.Value:R\n\033" +
|
||||
"property_containing_file_id\022,.org.jetbra" +
|
||||
"ins.kotlin.serialization.Property\030\207\001 \001(\005" +
|
||||
":}\n\025enum_entry_annotation\022-.org.jetbrain" +
|
||||
"s.kotlin.serialization.EnumEntry\030\202\001 \003(\0132",
|
||||
"..org.jetbrains.kotlin.serialization.Ann" +
|
||||
"otation:\201\001\n\024parameter_annotation\0222.org.j" +
|
||||
"etbrains.kotlin.serialization.ValueParam" +
|
||||
"eter\030\202\001 \003(\0132..org.jetbrains.kotlin.seria" +
|
||||
"lization.Annotation:r\n\017type_annotation\022(" +
|
||||
".org.jetbrains.kotlin.serialization.Type" +
|
||||
"\030\202\001 \003(\0132..org.jetbrains.kotlin.serializa" +
|
||||
"tion.Annotation:\205\001\n\031type_parameter_annot" +
|
||||
"ation\0221.org.jetbrains.kotlin.serializati" +
|
||||
"on.TypeParameter\030\202\001 \003(\0132..org.jetbrains.",
|
||||
"kotlin.serialization.AnnotationB\021B\017Debug" +
|
||||
"JsProtoBuf"
|
||||
};
|
||||
org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
|
||||
@@ -4824,26 +5527,32 @@ public final class DebugJsProtoBuf {
|
||||
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor[] {
|
||||
org.jetbrains.kotlin.serialization.DebugProtoBuf.getDescriptor(),
|
||||
}, assigner);
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_File_descriptor =
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Header_descriptor =
|
||||
getDescriptor().getMessageTypes().get(0);
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Header_fieldAccessorTable = new
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Header_descriptor,
|
||||
new java.lang.String[] { "Flags", "JsCodeBinaryVersion", "PackageFqName", });
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_File_descriptor =
|
||||
getDescriptor().getMessageTypes().get(1);
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_File_fieldAccessorTable = new
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_File_descriptor,
|
||||
new java.lang.String[] { "Id", "Annotation", });
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Files_descriptor =
|
||||
getDescriptor().getMessageTypes().get(1);
|
||||
getDescriptor().getMessageTypes().get(2);
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Files_fieldAccessorTable = new
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Files_descriptor,
|
||||
new java.lang.String[] { "File", });
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Classes_descriptor =
|
||||
getDescriptor().getMessageTypes().get(2);
|
||||
getDescriptor().getMessageTypes().get(3);
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Classes_fieldAccessorTable = new
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Classes_descriptor,
|
||||
new java.lang.String[] { "ClassName", });
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Library_descriptor =
|
||||
getDescriptor().getMessageTypes().get(3);
|
||||
getDescriptor().getMessageTypes().get(4);
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Library_fieldAccessorTable = new
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_org_jetbrains_kotlin_serialization_js_Library_descriptor,
|
||||
|
||||
@@ -40,5 +40,5 @@ object KotlinStubVersions {
|
||||
|
||||
// JS stub version should be increased if changes are made to js stub building subsystem (org.jetbrains.kotlin.idea.decompiler.js)
|
||||
// Increasing this version will lead to reindexing of js binary files (see KotlinJavaScriptMetaFileType).
|
||||
const val JS_STUB_VERSION = BINARY_STUB_VERSION + 0
|
||||
const val JS_STUB_VERSION = BINARY_STUB_VERSION + 1
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.jetbrains.kotlin.utils
|
||||
|
||||
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||
import java.io.DataInputStream
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import javax.xml.bind.DatatypeConverter.parseBase64Binary
|
||||
import javax.xml.bind.DatatypeConverter.printBase64Binary
|
||||
|
||||
@@ -31,10 +33,21 @@ class JsBinaryVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE = JsBinaryVersion(0, 7, 0)
|
||||
val INSTANCE = JsBinaryVersion(0, 8, 0)
|
||||
|
||||
@JvmField
|
||||
val INVALID_VERSION = JsBinaryVersion()
|
||||
|
||||
fun readFrom(stream: InputStream): JsBinaryVersion {
|
||||
val dataInput = DataInputStream(stream)
|
||||
val size = dataInput.readInt()
|
||||
|
||||
// We assume here that the version will always have 3 components. This is needed to prevent reading an unpredictable amount
|
||||
// of integers from old .kjsm files (pre-1.1) because they did not have the version in the beginning
|
||||
if (size != INSTANCE.toArray().size) return INVALID_VERSION
|
||||
|
||||
return JsBinaryVersion(*(1..size).map { dataInput.readInt() }.toIntArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-10
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
class NameResolverImpl(
|
||||
@@ -29,7 +28,7 @@ class NameResolverImpl(
|
||||
private val qualifiedNames: ProtoBuf.QualifiedNameTable
|
||||
) : NameResolver {
|
||||
|
||||
override fun getString(index: Int) = strings.getString(index)
|
||||
override fun getString(index: Int): String = strings.getString(index)
|
||||
|
||||
override fun getName(index: Int) = Name.guessByFirstCharacter(strings.getString(index))
|
||||
|
||||
@@ -65,12 +64,4 @@ class NameResolverImpl(
|
||||
}
|
||||
return Triple(packageNameSegments, relativeClassNameSegments, local)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(stream: InputStream): NameResolverImpl {
|
||||
val simpleNames = ProtoBuf.StringTable.parseDelimitedFrom(stream)
|
||||
val qualifiedNames = ProtoBuf.QualifiedNameTable.parseDelimitedFrom(stream)
|
||||
return NameResolverImpl(simpleNames, qualifiedNames)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ fun buildDecompiledTextForBuiltIns(builtInFile: VirtualFile): DecompiledText {
|
||||
}
|
||||
is BuiltInDefinitionFile.Compatible -> {
|
||||
val packageFqName = file.packageFqName
|
||||
val resolver = KotlinBuiltInDeserializerForDecompiler(file.packageDirectory, packageFqName, file.proto, file.nameResolver)
|
||||
val resolver = KotlinBuiltInDeserializerForDecompiler(packageFqName, file.proto, file.nameResolver)
|
||||
val declarations = arrayListOf<DeclarationDescriptor>()
|
||||
declarations.addAll(resolver.resolveDeclarationsInFacade(packageFqName))
|
||||
for (classProto in file.classesToDecompile) {
|
||||
|
||||
+1
-3
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.idea.decompiler.builtIns
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.builtins.BuiltInsClassDataFinder
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
@@ -34,11 +33,10 @@ import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
|
||||
class KotlinBuiltInDeserializerForDecompiler(
|
||||
packageDirectory: VirtualFile,
|
||||
packageFqName: FqName,
|
||||
private val proto: BuiltInsProtoBuf.BuiltIns,
|
||||
private val nameResolver: NameResolver
|
||||
) : DeserializerForDecompilerBase(packageDirectory, packageFqName) {
|
||||
) : DeserializerForDecompilerBase(packageFqName) {
|
||||
override val targetPlatform: TargetPlatform get() = TargetPlatform.Default
|
||||
override val builtIns: KotlinBuiltIns get() = DefaultBuiltIns.Instance
|
||||
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ fun DeserializerForClassfileDecompiler(classFile: VirtualFile): DeserializerForC
|
||||
class DeserializerForClassfileDecompiler(
|
||||
packageDirectory: VirtualFile,
|
||||
directoryPackageFqName: FqName
|
||||
) : DeserializerForDecompilerBase(packageDirectory, directoryPackageFqName) {
|
||||
) : DeserializerForDecompilerBase(directoryPackageFqName) {
|
||||
override val targetPlatform: TargetPlatform get() = JvmPlatform
|
||||
override val builtIns: KotlinBuiltIns get() = DefaultBuiltIns.Instance
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.js
|
||||
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.js.isDefaultPackageMetafile
|
||||
import org.jetbrains.kotlin.serialization.js.isPackageClassFqName
|
||||
|
||||
object JsMetaFileUtils {
|
||||
fun isKotlinJsMetaFile(file: VirtualFile): Boolean = file.fileType == KotlinJavaScriptMetaFileType
|
||||
|
||||
fun isKotlinJavaScriptInternalCompiledFile(file: VirtualFile): Boolean =
|
||||
isKotlinJsMetaFile(file) && file.nameWithoutExtension.contains('.')
|
||||
|
||||
fun getPackageFqName(file: VirtualFile): FqName = getPackageFqName(getRelativeToRootPath(file))
|
||||
|
||||
fun getClassFqName(file: VirtualFile): FqName = getClassFqName(getRelativeToRootPath(file))
|
||||
|
||||
fun getClassId(file: VirtualFile): ClassId = getClassId(getRelativeToRootPath(file))
|
||||
|
||||
fun isPackageHeader(file: VirtualFile): Boolean = isPackageHeader(getRelativeToRootPath(file))
|
||||
|
||||
fun getModuleDirectory(file: VirtualFile): VirtualFile =
|
||||
getRoot(file).findChild(getModuleName(getRelativeToRootPath(file)))!!
|
||||
|
||||
private fun getRelativeToRootPath(file: VirtualFile): String = VfsUtilCore.getRelativePath(file, getRoot(file))!!
|
||||
|
||||
private fun getClassFqName(relPath: String): FqName {
|
||||
val pathToFile = relPath.substringAfter(VfsUtilCore.VFS_SEPARATOR_CHAR)
|
||||
return FqName(pathToFile.substringBeforeLast('.').replace(VfsUtilCore.VFS_SEPARATOR_CHAR, '.'))
|
||||
}
|
||||
|
||||
private fun getClassId(relPath: String): ClassId {
|
||||
val classFqName = getClassFqName(relPath)
|
||||
val packageFqName = getPackageFqName(relPath)
|
||||
|
||||
val name = classFqName.shortName().asString().substringBeforeLast('.')
|
||||
return ClassId(packageFqName, FqName(name), false)
|
||||
}
|
||||
|
||||
private fun getPackageFqName(relPath: String): FqName {
|
||||
val pathToFile = relPath.substringAfter(VfsUtilCore.VFS_SEPARATOR_CHAR)
|
||||
if (isDefaultPackageMetafile(pathToFile) || !pathToFile.contains(VfsUtilCore.VFS_SEPARATOR_CHAR)) return FqName.ROOT
|
||||
|
||||
val name = pathToFile.substringBeforeLast(VfsUtilCore.VFS_SEPARATOR_CHAR)
|
||||
return FqName(name.replace(VfsUtilCore.VFS_SEPARATOR_CHAR, '.'))
|
||||
}
|
||||
|
||||
private fun getModuleName(relPath: String): String = relPath.substringBefore(VfsUtilCore.VFS_SEPARATOR_CHAR)
|
||||
|
||||
private fun isPackageHeader(relPath: String): Boolean {
|
||||
val classFqName = getClassFqName(relPath)
|
||||
return classFqName.isPackageClassFqName()
|
||||
}
|
||||
|
||||
private fun getRoot(file: VirtualFile): VirtualFile = if (file.parent == null) file else getRoot(file.parent)
|
||||
}
|
||||
|
||||
+16
-33
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.idea.decompiler.js
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
@@ -28,61 +27,45 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.serialization.js.*
|
||||
import java.io.ByteArrayInputStream
|
||||
import org.jetbrains.kotlin.serialization.js.DynamicTypeDeserializer
|
||||
import org.jetbrains.kotlin.serialization.js.JsProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptClassDataFinder
|
||||
|
||||
// TODO: deduplicate with KotlinBuiltInDeserializerForDecompiler
|
||||
class KotlinJavaScriptDeserializerForDecompiler(
|
||||
classFile: VirtualFile
|
||||
) : DeserializerForDecompilerBase(classFile.parent!!, JsMetaFileUtils.getPackageFqName(classFile)) {
|
||||
|
||||
private val nameResolver = run {
|
||||
val moduleDirectory = JsMetaFileUtils.getModuleDirectory(packageDirectory)
|
||||
val stringsFileName = KotlinJavascriptSerializedResourcePaths.getStringTableFilePath(directoryPackageFqName)
|
||||
val stringsFile = moduleDirectory.findFileByRelativePath(stringsFileName)
|
||||
assert(stringsFile != null) { "strings file not found: $stringsFileName" }
|
||||
NameResolverImpl.read(ByteArrayInputStream(stringsFile!!.contentsToByteArray(false)))
|
||||
}
|
||||
|
||||
packageFqName: FqName,
|
||||
private val proto: JsProtoBuf.Library.Part,
|
||||
private val nameResolver: NameResolver
|
||||
) : DeserializerForDecompilerBase(packageFqName) {
|
||||
override val targetPlatform: TargetPlatform get() = JsPlatform
|
||||
override val builtIns: KotlinBuiltIns get() = DefaultBuiltIns.Instance
|
||||
|
||||
// TODO: read metadata from .kjsm files here
|
||||
private val classDataFinder = KotlinJavascriptClassDataFinder(JsProtoBuf.Library.Part.getDefaultInstance(), nameResolver)
|
||||
|
||||
override val deserializationComponents: DeserializationComponents
|
||||
|
||||
init {
|
||||
val notFoundClasses = NotFoundClasses(storageManager, moduleDescriptor)
|
||||
val annotationAndConstantLoader = AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, JsSerializerProtocol)
|
||||
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, DeserializationConfiguration.Default, classDataFinder, annotationAndConstantLoader,
|
||||
packageFragmentProvider, ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
storageManager, moduleDescriptor, DeserializationConfiguration.Default, KotlinJavascriptClassDataFinder(proto, nameResolver),
|
||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, JsSerializerProtocol), packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassifierResolver(builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, DynamicTypeDeserializer, emptyList(), notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
override fun resolveDeclarationsInFacade(facadeFqName: FqName): List<DeclarationDescriptor> {
|
||||
val packageFqName = facadeFqName.parent()
|
||||
assert(packageFqName == directoryPackageFqName) {
|
||||
"Was called for $packageFqName; only members of $directoryPackageFqName package are expected."
|
||||
}
|
||||
val packageFilePath = KotlinJavascriptSerializedResourcePaths.getPackageFilePath(directoryPackageFqName).substringAfterLast("/")
|
||||
val file = packageDirectory.findChild(packageFilePath)
|
||||
if (file == null) {
|
||||
LOG.error("Could not read data for package $packageFqName; $packageFilePath absent in $packageDirectory")
|
||||
return emptyList()
|
||||
assert(facadeFqName == directoryPackageFqName) {
|
||||
"Was called for $facadeFqName; only members of $directoryPackageFqName package are expected."
|
||||
}
|
||||
|
||||
val content = file.contentsToByteArray(false)
|
||||
val packageProto = ProtoBuf.Package.parseFrom(content, JsSerializerProtocol.extensionRegistry)
|
||||
val membersScope = DeserializedPackageMemberScope(
|
||||
createDummyPackageFragment(packageFqName), packageProto, nameResolver, containerSource = null,
|
||||
createDummyPackageFragment(facadeFqName), proto.`package`, nameResolver, containerSource = null,
|
||||
components = deserializationComponents
|
||||
) { emptyList() }
|
||||
|
||||
return membersScope.getContributedDescriptors().toList()
|
||||
}
|
||||
|
||||
|
||||
+66
-31
@@ -20,61 +20,96 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.FileViewProvider
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.compiled.ClassFileDecompilers
|
||||
import com.intellij.psi.compiled.ClsStubBuilder
|
||||
import org.jetbrains.kotlin.fileClasses.OldPackageFacadeClassUtils
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
|
||||
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
|
||||
import org.jetbrains.kotlin.idea.decompiler.common.createIncompatibleAbiVersionDecompiledText
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolverForDecompiler
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.buildDecompiledText
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.defaultDecompilerRendererOptions
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
||||
import java.util.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.serialization.js.JsProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
|
||||
import org.jetbrains.kotlin.utils.JsBinaryVersion
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
class KotlinJavaScriptMetaFileDecompiler : ClassFileDecompilers.Full() {
|
||||
private val stubBuilder = KotlinJavaScriptStubBuilder()
|
||||
|
||||
override fun accepts(file: VirtualFile): Boolean {
|
||||
return file.name.endsWith("." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION)
|
||||
return file.fileType == KotlinJavaScriptMetaFileType
|
||||
}
|
||||
|
||||
override fun getStubBuilder(): ClsStubBuilder {
|
||||
return stubBuilder
|
||||
}
|
||||
override fun getStubBuilder() = stubBuilder
|
||||
|
||||
override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean): FileViewProvider {
|
||||
return KotlinDecompiledFileViewProvider(manager, file, physical) { provider ->
|
||||
if (JsMetaFileUtils.isKotlinJavaScriptInternalCompiledFile(file)) {
|
||||
null
|
||||
}
|
||||
else {
|
||||
KtDecompiledFile(provider) { file -> buildDecompiledTextFromJsMetadata(file) }
|
||||
}
|
||||
KtDecompiledFile(provider, ::buildDecompiledTextFromJsMetadata)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val decompilerRendererForJS = DescriptorRenderer.withOptions { defaultDecompilerRendererOptions() }
|
||||
|
||||
fun buildDecompiledTextFromJsMetadata(
|
||||
classFile: VirtualFile,
|
||||
resolver: ResolverForDecompiler = KotlinJavaScriptDeserializerForDecompiler(classFile)
|
||||
): DecompiledText {
|
||||
val packageFqName = JsMetaFileUtils.getPackageFqName(classFile)
|
||||
val isPackageHeader = JsMetaFileUtils.isPackageHeader(classFile)
|
||||
|
||||
if (isPackageHeader) {
|
||||
return buildDecompiledText(packageFqName,
|
||||
resolveDeclarationsInPackage(packageFqName, resolver),
|
||||
decompilerRendererForJS)
|
||||
// TODO: deduplicate code with KotlinBuiltInDecompiler
|
||||
fun buildDecompiledTextFromJsMetadata(kjsmFile: VirtualFile): DecompiledText {
|
||||
if (kjsmFile.fileType != KotlinJavaScriptMetaFileType) {
|
||||
error("Unexpected file type ${kjsmFile.fileType}")
|
||||
}
|
||||
else {
|
||||
val classId = JsMetaFileUtils.getClassId(classFile)
|
||||
return buildDecompiledText(packageFqName, listOfNotNull(resolver.resolveTopLevelClass(classId)), decompilerRendererForJS)
|
||||
|
||||
val file = KjsmFile.read(kjsmFile)
|
||||
?: error("Unexpectedly empty file: $kjsmFile")
|
||||
|
||||
when (file) {
|
||||
is KjsmFile.Incompatible -> {
|
||||
return createIncompatibleAbiVersionDecompiledText(JsBinaryVersion.INSTANCE, file.version)
|
||||
}
|
||||
is KjsmFile.Compatible -> {
|
||||
val packageFqName = file.packageFqName
|
||||
val resolver = KotlinJavaScriptDeserializerForDecompiler(packageFqName, file.proto, file.nameResolver)
|
||||
val declarations = arrayListOf<DeclarationDescriptor>()
|
||||
declarations.addAll(resolver.resolveDeclarationsInFacade(packageFqName))
|
||||
for (klass in file.classesToDecompile) {
|
||||
val classId = file.nameResolver.getClassId(klass.fqName)
|
||||
declarations.add(resolver.resolveTopLevelClass(classId)!!)
|
||||
}
|
||||
return buildDecompiledText(packageFqName, declarations, decompilerRendererForJS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveDeclarationsInPackage(packageFqName: FqName, resolver: ResolverForDecompiler) =
|
||||
ArrayList(resolver.resolveDeclarationsInFacade(OldPackageFacadeClassUtils.getPackageClassFqName(packageFqName)))
|
||||
// TODO: deduplicate code with BuiltInDefinitionFile
|
||||
sealed class KjsmFile {
|
||||
class Incompatible(val version: JsBinaryVersion) : KjsmFile()
|
||||
|
||||
class Compatible(val header: JsProtoBuf.Header, val proto: JsProtoBuf.Library.Part) : KjsmFile() {
|
||||
val packageFqName = FqName(header.packageFqName)
|
||||
val nameResolver = NameResolverImpl(proto.strings, proto.qualifiedNames)
|
||||
|
||||
val classesToDecompile =
|
||||
proto.class_List.filterNot { proto -> nameResolver.getClassId(proto.fqName).isNestedClass }
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun read(file: VirtualFile): KjsmFile? {
|
||||
if (!file.isValid) {
|
||||
return null
|
||||
}
|
||||
|
||||
val stream = ByteArrayInputStream(file.contentsToByteArray())
|
||||
|
||||
val version = JsBinaryVersion.readFrom(stream)
|
||||
if (!version.isCompatible()) {
|
||||
return Incompatible(version)
|
||||
}
|
||||
|
||||
val header = JsProtoBuf.Header.parseDelimitedFrom(stream)
|
||||
val proto = JsProtoBuf.Library.Part.parseFrom(stream, JsSerializerProtocol.extensionRegistry)
|
||||
val result = Compatible(header, proto)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
-48
@@ -16,70 +16,55 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.js
|
||||
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.compiled.ClsStubBuilder
|
||||
import com.intellij.psi.impl.compiled.ClassFileStubBuilder
|
||||
import com.intellij.psi.stubs.PsiFileStub
|
||||
import com.intellij.util.indexing.FileContent
|
||||
import org.jetbrains.kotlin.idea.decompiler.common.AnnotationLoaderForStubBuilderImpl
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClsStubBuilderComponents
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.createPackageFacadeStub
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.createTopLevelClassStub
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.*
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinStubVersions
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.serialization.js.JsProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializedResourcePaths
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
// TODO: deduplicate code with KotlinBuiltInStubBuilder
|
||||
class KotlinJavaScriptStubBuilder : ClsStubBuilder() {
|
||||
override fun getStubVersion() = ClassFileStubBuilder.STUB_VERSION + KotlinStubVersions.JS_STUB_VERSION
|
||||
|
||||
override fun buildFileStub(content: FileContent): PsiFileStub<*>? {
|
||||
val file = content.file
|
||||
val virtualFile = content.file
|
||||
assert(virtualFile.fileType == KotlinJavaScriptMetaFileType) { "Unexpected file type ${virtualFile.fileType}" }
|
||||
val file = KjsmFile.read(virtualFile) ?: return null
|
||||
|
||||
if (file.fileSystem.protocol != StandardFileSystems.JAR_PROTOCOL ||
|
||||
JsMetaFileUtils.isKotlinJavaScriptInternalCompiledFile(file)) return null
|
||||
when (file) {
|
||||
is KjsmFile.Incompatible -> {
|
||||
return createIncompatibleAbiVersionFileStub()
|
||||
}
|
||||
is KjsmFile.Compatible -> {
|
||||
val packageProto = file.proto.`package`
|
||||
val packageFqName = file.packageFqName
|
||||
val nameResolver = file.nameResolver
|
||||
val components = ClsStubBuilderComponents(
|
||||
KotlinJavascriptClassDataFinder(file.proto, nameResolver),
|
||||
AnnotationLoaderForStubBuilderImpl(JsSerializerProtocol),
|
||||
virtualFile
|
||||
)
|
||||
val context = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable))
|
||||
|
||||
return doBuildFileStub(file)
|
||||
}
|
||||
|
||||
fun doBuildFileStub(file: VirtualFile): PsiFileStub<KtFile>? {
|
||||
val packageFqName = JsMetaFileUtils.getPackageFqName(file)
|
||||
|
||||
val content = file.contentsToByteArray(false)
|
||||
val isPackageHeader = JsMetaFileUtils.isPackageHeader(file)
|
||||
|
||||
val moduleDirectory = JsMetaFileUtils.getModuleDirectory(file)
|
||||
val stringsFileName = KotlinJavascriptSerializedResourcePaths.getStringTableFilePath(packageFqName)
|
||||
val stringsFile = moduleDirectory.findFileByRelativePath(stringsFileName) ?: error("strings file not found: $stringsFileName")
|
||||
|
||||
val nameResolver = NameResolverImpl.read(ByteArrayInputStream(stringsFile.contentsToByteArray(false)))
|
||||
val components = createStubBuilderComponents(file, nameResolver)
|
||||
|
||||
if (isPackageHeader) {
|
||||
val packageProto = ProtoBuf.Package.parseFrom(content, JsSerializerProtocol.extensionRegistry)
|
||||
val context = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable))
|
||||
return createPackageFacadeStub(packageProto, packageFqName, context)
|
||||
val fileStub = createFileStub(packageFqName, isScript = false)
|
||||
createDeclarationsStubs(
|
||||
fileStub, context,
|
||||
ProtoContainer.Package(packageFqName, context.nameResolver, context.typeTable, source = null),
|
||||
packageProto
|
||||
)
|
||||
for (classProto in file.classesToDecompile) {
|
||||
createClassStub(
|
||||
fileStub, classProto, nameResolver, nameResolver.getClassId(classProto.fqName), source = null, context = context
|
||||
)
|
||||
}
|
||||
return fileStub
|
||||
}
|
||||
}
|
||||
else {
|
||||
val classProto = ProtoBuf.Class.parseFrom(content, JsSerializerProtocol.extensionRegistry)
|
||||
val context = components.createContext(nameResolver, packageFqName, TypeTable(classProto.typeTable))
|
||||
val classId = JsMetaFileUtils.getClassId(file)
|
||||
return createTopLevelClassStub(classId, classProto, source = null, context = context, isScript = false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createStubBuilderComponents(file: VirtualFile, nameResolver: NameResolver): ClsStubBuilderComponents {
|
||||
// TODO: read metadata from .kjsm files here
|
||||
val classDataFinder = KotlinJavascriptClassDataFinder(JsProtoBuf.Library.Part.getDefaultInstance(), nameResolver)
|
||||
val annotationLoader = AnnotationLoaderForStubBuilderImpl(JsSerializerProtocol)
|
||||
return ClsStubBuilderComponents(classDataFinder, annotationLoader, file)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
@@ -32,10 +31,7 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
|
||||
abstract class DeserializerForDecompilerBase(
|
||||
val packageDirectory: VirtualFile,
|
||||
val directoryPackageFqName: FqName
|
||||
) : ResolverForDecompiler {
|
||||
abstract class DeserializerForDecompilerBase(val directoryPackageFqName: FqName) : ResolverForDecompiler {
|
||||
protected abstract val deserializationComponents: DeserializationComponents
|
||||
|
||||
protected abstract val targetPlatform: TargetPlatform
|
||||
|
||||
@@ -20,8 +20,11 @@ import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
interface JsVirtualFileFinder : VirtualFileFinder {
|
||||
fun hasPackage(fqName: FqName): Boolean
|
||||
|
||||
object SERVICE {
|
||||
@JvmStatic fun getInstance(project: Project): JsVirtualFileFinder =
|
||||
ServiceManager.getService(project, JsVirtualFileFinderFactory::class.java).create(GlobalSearchScope.allScope(project))
|
||||
|
||||
@@ -43,12 +43,15 @@ private fun findVirtualFileWithHeader(classId: ClassId, key: ID<FqName, Void>, s
|
||||
return files.iterator().next()
|
||||
}
|
||||
|
||||
// TODO: drop this implementation, replace with a much simpler service
|
||||
class JsIDEVirtualFileFinder(private val scope: GlobalSearchScope) : JsVirtualFileFinder {
|
||||
|
||||
init { checkScopeForFinder(scope, LOG) }
|
||||
|
||||
override fun findVirtualFileWithHeader(classId: ClassId): VirtualFile? =
|
||||
findVirtualFileWithHeader(classId, KotlinJavaScriptMetaFileIndex.KEY, scope, LOG)
|
||||
throw UnsupportedOperationException("This method should not be called. (classId = $classId)")
|
||||
|
||||
override fun hasPackage(fqName: FqName): Boolean = KotlinJavaScriptMetaFileIndex.hasPackage(fqName, scope)
|
||||
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance(JsIDEVirtualFileFinder::class.java)
|
||||
@@ -60,10 +63,7 @@ class JvmIDEVirtualFileFinder(private val scope: GlobalSearchScope) : VirtualFil
|
||||
return findVirtualFileWithHeader(classId, KotlinMetadataFileIndex.KEY, scope, LOG)?.inputStream
|
||||
}
|
||||
|
||||
override fun hasMetadataPackage(fqName: FqName): Boolean {
|
||||
return !FileBasedIndex.getInstance().processValues(KotlinMetadataFilePackageIndex.KEY,
|
||||
fqName, null, { _, _ -> false }, scope)
|
||||
}
|
||||
override fun hasMetadataPackage(fqName: FqName): Boolean = KotlinMetadataFilePackageIndex.hasPackage(fqName, scope)
|
||||
|
||||
// TODO: load built-ins metadata from scope
|
||||
override fun findBuiltInsData(packageFqName: FqName): InputStream? = null
|
||||
@@ -77,3 +77,6 @@ class JvmIDEVirtualFileFinder(private val scope: GlobalSearchScope) : VirtualFil
|
||||
private val LOG = Logger.getInstance(JvmIDEVirtualFileFinder::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> KotlinFileIndexBase<T>.hasPackage(fqName: FqName, scope: GlobalSearchScope): Boolean =
|
||||
!FileBasedIndex.getInstance().processValues(name, fqName, null, { _, _ -> false }, scope)
|
||||
|
||||
@@ -24,12 +24,14 @@ import com.intellij.util.io.KeyDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.IDEKotlinBinaryClassCache
|
||||
import org.jetbrains.kotlin.idea.decompiler.builtIns.BuiltInDefinitionFile
|
||||
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInFileType
|
||||
import org.jetbrains.kotlin.idea.decompiler.js.JsMetaFileUtils
|
||||
import org.jetbrains.kotlin.idea.decompiler.js.KotlinJavaScriptMetaFileType
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment
|
||||
import org.jetbrains.kotlin.serialization.js.JsProtoBuf
|
||||
import org.jetbrains.kotlin.utils.JsBinaryVersion
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.DataInput
|
||||
import java.io.DataOutput
|
||||
import java.util.*
|
||||
@@ -98,13 +100,15 @@ object KotlinJavaScriptMetaFileIndex : KotlinFileIndexBase<KotlinJavaScriptMetaF
|
||||
|
||||
override fun getVersion() = VERSION
|
||||
|
||||
private val VERSION = 3
|
||||
private val VERSION = 4
|
||||
|
||||
private val INDEXER = indexer { fileContent ->
|
||||
if (fileContent.fileType == KotlinJavaScriptMetaFileType) JsMetaFileUtils.getClassFqName(fileContent.file) else null
|
||||
val stream = ByteArrayInputStream(fileContent.content)
|
||||
if (JsBinaryVersion.readFrom(stream).isCompatible()) {
|
||||
FqName(JsProtoBuf.Header.parseDelimitedFrom(stream).packageFqName)
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
override fun dependsOnFileContent(): Boolean = false
|
||||
}
|
||||
|
||||
open class KotlinMetadataFileIndexBase<T>(classOfIndex: Class<T>, indexFunction: (ClassId) -> FqName) : KotlinFileIndexBase<T>(classOfIndex) {
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
||||
import org.jetbrains.kotlin.idea.versions.getKotlinJsRuntimeMarkerClass
|
||||
import org.jetbrains.kotlin.idea.versions.getKotlinJvmRuntimeMarkerClass
|
||||
import org.jetbrains.kotlin.idea.versions.hasKotlinJsKjsmFile
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.JvmIDEVirtualFileFinder
|
||||
import org.jetbrains.kotlin.utils.ifEmpty
|
||||
|
||||
@@ -132,7 +132,7 @@ fun getNonConfiguredModules(project: Project, excludeModules: Collection<Module>
|
||||
fun hasAnyKotlinRuntimeInScope(module: Module): Boolean {
|
||||
val scope = module.getModuleWithDependenciesAndLibrariesScope(hasKotlinFilesOnlyInTests(module))
|
||||
return getKotlinJvmRuntimeMarkerClass(module.project, scope) != null ||
|
||||
getKotlinJsRuntimeMarkerClass(module.project, scope) != null ||
|
||||
hasKotlinJsKjsmFile(module.project, scope) ||
|
||||
hasKotlinCommonRuntimeInScope(scope)
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ fun hasKotlinJvmRuntimeInScope(module: Module): Boolean {
|
||||
|
||||
fun hasKotlinJsRuntimeInScope(module: Module): Boolean {
|
||||
val scope = module.getModuleWithDependenciesAndLibrariesScope(hasKotlinFilesOnlyInTests(module))
|
||||
return getKotlinJsRuntimeMarkerClass(module.project, scope) != null
|
||||
return hasKotlinJsKjsmFile(module.project, scope)
|
||||
}
|
||||
|
||||
fun hasKotlinCommonRuntimeInScope(scope: GlobalSearchScope): Boolean {
|
||||
|
||||
@@ -53,11 +53,12 @@ import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.runWithAlternativeResolveEnabled
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinderFactory
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.utils.JsBinaryVersion
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.constant
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@@ -282,10 +283,10 @@ fun getKotlinJvmRuntimeMarkerClass(project: Project, scope: GlobalSearchScope):
|
||||
}
|
||||
}
|
||||
|
||||
fun getKotlinJsRuntimeMarkerClass(project: Project, scope: GlobalSearchScope): VirtualFile? {
|
||||
fun hasKotlinJsKjsmFile(project: Project, scope: GlobalSearchScope): Boolean {
|
||||
return runReadAction {
|
||||
project.runWithAlternativeResolveEnabled {
|
||||
JsVirtualFileFinderFactory.SERVICE.getInstance(project).create(scope).findVirtualFileWithHeader(ClassId.topLevel(KotlinBuiltIns.FQ_NAMES.unit.toSafe()))
|
||||
JsVirtualFileFinderFactory.SERVICE.getInstance(project).create(scope).hasPackage(constant { FqName("kotlin.js") })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -45,7 +45,8 @@ class KotlinJavaScriptDecompiledTextConsistencyTest : TextConsistencyBaseTest()
|
||||
override fun getVirtualFileFinder(): VirtualFileFinder = JsVirtualFileFinder.SERVICE.getInstance(project)
|
||||
|
||||
override fun getDecompiledText(packageFile: VirtualFile, resolver: ResolverForDecompiler?): String =
|
||||
(resolver?.let { buildDecompiledTextFromJsMetadata(packageFile, it) } ?: buildDecompiledTextFromJsMetadata(packageFile)).text
|
||||
// TODO: use resolver here
|
||||
buildDecompiledTextFromJsMetadata(packageFile).text
|
||||
|
||||
override fun getModuleDescriptor(): ModuleDescriptor {
|
||||
val stdlibJar = PathUtil.getKotlinPathsForDistDirectory().jsStdLibJarPath.absolutePath
|
||||
|
||||
@@ -21,6 +21,18 @@ import "core/deserialization/src/descriptors.proto";
|
||||
option java_outer_classname = "JsProtoBuf";
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
message Header {
|
||||
/*
|
||||
preRelease
|
||||
*/
|
||||
optional int32 flags = 1;
|
||||
|
||||
// (patch << 16) + (minor << 8) + major
|
||||
optional int32 js_code_binary_version = 2;
|
||||
|
||||
optional string package_fq_name = 3;
|
||||
}
|
||||
|
||||
message File {
|
||||
required int32 id = 1;
|
||||
repeated Annotation annotation = 2;
|
||||
|
||||
@@ -21,6 +21,657 @@ public final class JsProtoBuf {
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.typeAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.js.JsProtoBuf.typeParameterAnnotation);
|
||||
}
|
||||
public interface HeaderOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:org.jetbrains.kotlin.serialization.js.Header)
|
||||
org.jetbrains.kotlin.protobuf.MessageLiteOrBuilder {
|
||||
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
boolean hasFlags();
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
int getFlags();
|
||||
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
boolean hasJsCodeBinaryVersion();
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
int getJsCodeBinaryVersion();
|
||||
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
boolean hasPackageFqName();
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
java.lang.String getPackageFqName();
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
org.jetbrains.kotlin.protobuf.ByteString
|
||||
getPackageFqNameBytes();
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code org.jetbrains.kotlin.serialization.js.Header}
|
||||
*/
|
||||
public static final class Header extends
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessageLite implements
|
||||
// @@protoc_insertion_point(message_implements:org.jetbrains.kotlin.serialization.js.Header)
|
||||
HeaderOrBuilder {
|
||||
// Use Header.newBuilder() to construct.
|
||||
private Header(org.jetbrains.kotlin.protobuf.GeneratedMessageLite.Builder builder) {
|
||||
super(builder);
|
||||
this.unknownFields = builder.getUnknownFields();
|
||||
}
|
||||
private Header(boolean noInit) { this.unknownFields = org.jetbrains.kotlin.protobuf.ByteString.EMPTY;}
|
||||
|
||||
private static final Header defaultInstance;
|
||||
public static Header getDefaultInstance() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public Header getDefaultInstanceForType() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
private final org.jetbrains.kotlin.protobuf.ByteString unknownFields;
|
||||
private Header(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
initFields();
|
||||
int mutable_bitField0_ = 0;
|
||||
org.jetbrains.kotlin.protobuf.ByteString.Output unknownFieldsOutput =
|
||||
org.jetbrains.kotlin.protobuf.ByteString.newOutput();
|
||||
org.jetbrains.kotlin.protobuf.CodedOutputStream unknownFieldsCodedOutput =
|
||||
org.jetbrains.kotlin.protobuf.CodedOutputStream.newInstance(
|
||||
unknownFieldsOutput);
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
default: {
|
||||
if (!parseUnknownField(input, unknownFieldsCodedOutput,
|
||||
extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
bitField0_ |= 0x00000001;
|
||||
flags_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
bitField0_ |= 0x00000002;
|
||||
jsCodeBinaryVersion_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
case 26: {
|
||||
org.jetbrains.kotlin.protobuf.ByteString bs = input.readBytes();
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = bs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException(
|
||||
e.getMessage()).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
try {
|
||||
unknownFieldsCodedOutput.flush();
|
||||
} catch (java.io.IOException e) {
|
||||
// Should not happen
|
||||
} finally {
|
||||
unknownFields = unknownFieldsOutput.toByteString();
|
||||
}
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static org.jetbrains.kotlin.protobuf.Parser<Header> PARSER =
|
||||
new org.jetbrains.kotlin.protobuf.AbstractParser<Header>() {
|
||||
public Header parsePartialFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return new Header(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
@java.lang.Override
|
||||
public org.jetbrains.kotlin.protobuf.Parser<Header> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
public static final int FLAGS_FIELD_NUMBER = 1;
|
||||
private int flags_;
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasFlags() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public int getFlags() {
|
||||
return flags_;
|
||||
}
|
||||
|
||||
public static final int JS_CODE_BINARY_VERSION_FIELD_NUMBER = 2;
|
||||
private int jsCodeBinaryVersion_;
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasJsCodeBinaryVersion() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public int getJsCodeBinaryVersion() {
|
||||
return jsCodeBinaryVersion_;
|
||||
}
|
||||
|
||||
public static final int PACKAGE_FQ_NAME_FIELD_NUMBER = 3;
|
||||
private java.lang.Object packageFqName_;
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public boolean hasPackageFqName() {
|
||||
return ((bitField0_ & 0x00000004) == 0x00000004);
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public java.lang.String getPackageFqName() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
return (java.lang.String) ref;
|
||||
} else {
|
||||
org.jetbrains.kotlin.protobuf.ByteString bs =
|
||||
(org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
java.lang.String s = bs.toStringUtf8();
|
||||
if (bs.isValidUtf8()) {
|
||||
packageFqName_ = s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public org.jetbrains.kotlin.protobuf.ByteString
|
||||
getPackageFqNameBytes() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
org.jetbrains.kotlin.protobuf.ByteString b =
|
||||
org.jetbrains.kotlin.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
packageFqName_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
flags_ = 0;
|
||||
jsCodeBinaryVersion_ = 0;
|
||||
packageFqName_ = "";
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized == 1) return true;
|
||||
if (isInitialized == 0) return false;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeTo(org.jetbrains.kotlin.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
getSerializedSize();
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
output.writeInt32(1, flags_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
output.writeInt32(2, jsCodeBinaryVersion_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000004) == 0x00000004)) {
|
||||
output.writeBytes(3, getPackageFqNameBytes());
|
||||
}
|
||||
output.writeRawBytes(unknownFields);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeInt32Size(1, flags_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeInt32Size(2, jsCodeBinaryVersion_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000004) == 0x00000004)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeBytesSize(3, getPackageFqNameBytes());
|
||||
}
|
||||
size += unknownFields.size();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
@java.lang.Override
|
||||
protected java.lang.Object writeReplace()
|
||||
throws java.io.ObjectStreamException {
|
||||
return super.writeReplace();
|
||||
}
|
||||
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.ByteString data)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.ByteString data,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(byte[] data)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(
|
||||
byte[] data,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(
|
||||
java.io.InputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parseFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static Builder newBuilder() { return Builder.create(); }
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder(org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header prototype) {
|
||||
return newBuilder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() { return newBuilder(this); }
|
||||
|
||||
/**
|
||||
* Protobuf type {@code org.jetbrains.kotlin.serialization.js.Header}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessageLite.Builder<
|
||||
org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header, Builder>
|
||||
implements
|
||||
// @@protoc_insertion_point(builder_implements:org.jetbrains.kotlin.serialization.js.Header)
|
||||
org.jetbrains.kotlin.serialization.js.JsProtoBuf.HeaderOrBuilder {
|
||||
// Construct using org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private void maybeForceBuilderInitialization() {
|
||||
}
|
||||
private static Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
flags_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
jsCodeBinaryVersion_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
packageFqName_ = "";
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clone() {
|
||||
return create().mergeFrom(buildPartial());
|
||||
}
|
||||
|
||||
public org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header getDefaultInstanceForType() {
|
||||
return org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header.getDefaultInstance();
|
||||
}
|
||||
|
||||
public org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header build() {
|
||||
org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header buildPartial() {
|
||||
org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header result = new org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header(this);
|
||||
int from_bitField0_ = bitField0_;
|
||||
int to_bitField0_ = 0;
|
||||
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
to_bitField0_ |= 0x00000001;
|
||||
}
|
||||
result.flags_ = flags_;
|
||||
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
to_bitField0_ |= 0x00000002;
|
||||
}
|
||||
result.jsCodeBinaryVersion_ = jsCodeBinaryVersion_;
|
||||
if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
|
||||
to_bitField0_ |= 0x00000004;
|
||||
}
|
||||
result.packageFqName_ = packageFqName_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
return result;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header other) {
|
||||
if (other == org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header.getDefaultInstance()) return this;
|
||||
if (other.hasFlags()) {
|
||||
setFlags(other.getFlags());
|
||||
}
|
||||
if (other.hasJsCodeBinaryVersion()) {
|
||||
setJsCodeBinaryVersion(other.getJsCodeBinaryVersion());
|
||||
}
|
||||
if (other.hasPackageFqName()) {
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = other.packageFqName_;
|
||||
|
||||
}
|
||||
setUnknownFields(
|
||||
getUnknownFields().concat(other.unknownFields));
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(
|
||||
org.jetbrains.kotlin.protobuf.CodedInputStream input,
|
||||
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (org.jetbrains.kotlin.serialization.js.JsProtoBuf.Header) e.getUnfinishedMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
private int flags_ ;
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasFlags() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public int getFlags() {
|
||||
return flags_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setFlags(int value) {
|
||||
bitField0_ |= 0x00000001;
|
||||
flags_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*preRelease
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearFlags() {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
flags_ = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private int jsCodeBinaryVersion_ ;
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasJsCodeBinaryVersion() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public int getJsCodeBinaryVersion() {
|
||||
return jsCodeBinaryVersion_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setJsCodeBinaryVersion(int value) {
|
||||
bitField0_ |= 0x00000002;
|
||||
jsCodeBinaryVersion_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 js_code_binary_version = 2;</code>
|
||||
*
|
||||
* <pre>
|
||||
* (patch << 16) + (minor << 8) + major
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearJsCodeBinaryVersion() {
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
jsCodeBinaryVersion_ = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private java.lang.Object packageFqName_ = "";
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public boolean hasPackageFqName() {
|
||||
return ((bitField0_ & 0x00000004) == 0x00000004);
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public java.lang.String getPackageFqName() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (!(ref instanceof java.lang.String)) {
|
||||
org.jetbrains.kotlin.protobuf.ByteString bs =
|
||||
(org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
java.lang.String s = bs.toStringUtf8();
|
||||
if (bs.isValidUtf8()) {
|
||||
packageFqName_ = s;
|
||||
}
|
||||
return s;
|
||||
} else {
|
||||
return (java.lang.String) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public org.jetbrains.kotlin.protobuf.ByteString
|
||||
getPackageFqNameBytes() {
|
||||
java.lang.Object ref = packageFqName_;
|
||||
if (ref instanceof String) {
|
||||
org.jetbrains.kotlin.protobuf.ByteString b =
|
||||
org.jetbrains.kotlin.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
packageFqName_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (org.jetbrains.kotlin.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public Builder setPackageFqName(
|
||||
java.lang.String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public Builder clearPackageFqName() {
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
packageFqName_ = getDefaultInstance().getPackageFqName();
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string package_fq_name = 3;</code>
|
||||
*/
|
||||
public Builder setPackageFqNameBytes(
|
||||
org.jetbrains.kotlin.protobuf.ByteString value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000004;
|
||||
packageFqName_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.js.Header)
|
||||
}
|
||||
|
||||
static {
|
||||
defaultInstance = new Header(true);
|
||||
defaultInstance.initFields();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.serialization.js.Header)
|
||||
}
|
||||
|
||||
public interface FileOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:org.jetbrains.kotlin.serialization.js.File)
|
||||
org.jetbrains.kotlin.protobuf.MessageLiteOrBuilder {
|
||||
|
||||
+54
-60
@@ -31,9 +31,11 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.StringTableImpl
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.JsBinaryVersion
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.DataOutputStream
|
||||
import java.util.*
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
@@ -70,31 +72,7 @@ object KotlinJavascriptSerializationUtil {
|
||||
importedModules.forEach { builder.addImportedModule(it) }
|
||||
|
||||
for (fqName in getPackagesFqNames(module)) {
|
||||
val part = JsProtoBuf.Library.Part.newBuilder()
|
||||
serializePackage(bindingContext, module, fqName, object : SerializerCallbacks {
|
||||
override fun writeClass(classId: ClassId, classProto: ProtoBuf.Class) {
|
||||
part.addClass_(classProto)
|
||||
}
|
||||
|
||||
override fun writePackage(fqName: FqName, packageProto: ProtoBuf.Package) {
|
||||
part.`package` = packageProto
|
||||
}
|
||||
|
||||
override fun writeFiles(fqName: FqName, filesProto: JsProtoBuf.Files) {
|
||||
part.files = filesProto
|
||||
}
|
||||
|
||||
override fun writeStringTable(fqName: FqName, stringTable: StringTableImpl) {
|
||||
val (strings, qualifiedNames) = stringTable.buildProto()
|
||||
part.strings = strings
|
||||
part.qualifiedNames = qualifiedNames
|
||||
}
|
||||
|
||||
override fun writeClassNames(fqName: FqName, classNames: List<Name>, stringTable: StringTableImpl) {
|
||||
// Do nothing
|
||||
}
|
||||
})
|
||||
|
||||
val part = serializePackageFragment(bindingContext, fqName, module)
|
||||
if (part.hasPackage() || part.class_Count > 0) {
|
||||
builder.addPart(part)
|
||||
}
|
||||
@@ -103,6 +81,38 @@ object KotlinJavascriptSerializationUtil {
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
private fun serializePackageFragment(
|
||||
bindingContext: BindingContext,
|
||||
fqName: FqName,
|
||||
module: ModuleDescriptor
|
||||
): JsProtoBuf.Library.Part {
|
||||
val part = JsProtoBuf.Library.Part.newBuilder()
|
||||
serializePackage(bindingContext, module, fqName, object : SerializerCallbacks {
|
||||
override fun writeClass(classId: ClassId, classProto: ProtoBuf.Class) {
|
||||
part.addClass_(classProto)
|
||||
}
|
||||
|
||||
override fun writePackage(fqName: FqName, packageProto: ProtoBuf.Package) {
|
||||
part.`package` = packageProto
|
||||
}
|
||||
|
||||
override fun writeFiles(fqName: FqName, filesProto: JsProtoBuf.Files) {
|
||||
part.files = filesProto
|
||||
}
|
||||
|
||||
override fun writeStringTable(fqName: FqName, stringTable: StringTableImpl) {
|
||||
val (strings, qualifiedNames) = stringTable.buildProto()
|
||||
part.strings = strings
|
||||
part.qualifiedNames = qualifiedNames
|
||||
}
|
||||
|
||||
override fun writeClassNames(fqName: FqName, classNames: List<Name>, stringTable: StringTableImpl) {
|
||||
// Do nothing
|
||||
}
|
||||
})
|
||||
return part.build()
|
||||
}
|
||||
|
||||
fun metadataAsString(bindingContext: BindingContext, jsDescriptor: JsModuleDescriptor<ModuleDescriptor>): String =
|
||||
KotlinJavascriptMetadataUtils.formatMetadataAsString(jsDescriptor.name, jsDescriptor.serializeToBinaryMetadata(bindingContext))
|
||||
|
||||
@@ -179,46 +189,30 @@ object KotlinJavascriptSerializationUtil {
|
||||
fun toContentMap(bindingContext: BindingContext, module: ModuleDescriptor): Map<String, ByteArray> {
|
||||
val contentMap = hashMapOf<String, ByteArray>()
|
||||
|
||||
fun writeFile(fileName: String, bytes: ByteArray) {
|
||||
contentMap[fileName] = bytes
|
||||
}
|
||||
|
||||
for (fqName in getPackagesFqNames(module)) {
|
||||
serializePackage(bindingContext, module, fqName, object : SerializerCallbacks {
|
||||
override fun writeClass(classId: ClassId, classProto: ProtoBuf.Class) {
|
||||
val bytes = ByteArrayOutputStream().apply(classProto::writeTo).toByteArray()
|
||||
writeFile(KotlinJavascriptSerializedResourcePaths.getClassMetadataPath(classId), bytes)
|
||||
}
|
||||
val part = serializePackageFragment(bindingContext, fqName, module)
|
||||
if (part.class_Count == 0 && part.`package`.let { packageProto ->
|
||||
packageProto.functionCount == 0 && packageProto.propertyCount == 0 && packageProto.typeAliasCount == 0
|
||||
}) continue
|
||||
|
||||
override fun writePackage(fqName: FqName, packageProto: ProtoBuf.Package) {
|
||||
if (packageProto.functionCount > 0 || packageProto.propertyCount > 0 || packageProto.typeAliasCount > 0) {
|
||||
val bytes = ByteArrayOutputStream().apply(packageProto::writeTo).toByteArray()
|
||||
writeFile(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName), bytes)
|
||||
}
|
||||
}
|
||||
val packageFqName = fqName.asString()
|
||||
|
||||
override fun writeFiles(fqName: FqName, filesProto: JsProtoBuf.Files) {
|
||||
val bytes = ByteArrayOutputStream().apply(filesProto::writeTo).toByteArray()
|
||||
writeFile(KotlinJavascriptSerializedResourcePaths.getFileListFilePath(fqName), bytes)
|
||||
}
|
||||
val header = JsProtoBuf.Header.newBuilder()
|
||||
// TODO: write pre-release flag if needed
|
||||
// TODO: write JS code binary version
|
||||
header.packageFqName = packageFqName
|
||||
|
||||
override fun writeStringTable(fqName: FqName, stringTable: StringTableImpl) {
|
||||
val bytes = ByteArrayOutputStream().apply(stringTable::serializeTo).toByteArray()
|
||||
if (bytes.isNotEmpty()) {
|
||||
writeFile(KotlinJavascriptSerializedResourcePaths.getStringTableFilePath(fqName), bytes)
|
||||
}
|
||||
}
|
||||
val stream = ByteArrayOutputStream()
|
||||
with(DataOutputStream(stream)) {
|
||||
val version = JsBinaryVersion.INSTANCE.toArray()
|
||||
writeInt(version.size)
|
||||
version.forEach(this::writeInt)
|
||||
}
|
||||
|
||||
override fun writeClassNames(fqName: FqName, classNames: List<Name>, stringTable: StringTableImpl) {
|
||||
val builder = JsProtoBuf.Classes.newBuilder()
|
||||
builder.addAllClassName(classNames.map(stringTable::getSimpleNameIndex))
|
||||
val classesProto = builder.build()
|
||||
if (classesProto.classNameCount > 0) {
|
||||
val bytes = ByteArrayOutputStream().apply(classesProto::writeTo).toByteArray()
|
||||
writeFile(KotlinJavascriptSerializedResourcePaths.getClassesInPackageFilePath(fqName), bytes)
|
||||
}
|
||||
}
|
||||
})
|
||||
header.build().writeDelimitedTo(stream)
|
||||
part.writeTo(stream)
|
||||
|
||||
contentMap[JsSerializerProtocol.getKjsmFilePath(fqName)] = stream.toByteArray()
|
||||
}
|
||||
|
||||
return contentMap
|
||||
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object KotlinJavascriptSerializedResourcePaths {
|
||||
private val CLASSES_FILE_EXTENSION = "kotlin_classes"
|
||||
private val STRING_TABLE_FILE_EXTENSION = "kotlin_string_table"
|
||||
private val FILE_LIST_FILE_EXTENSION = "kotlin_file_table"
|
||||
|
||||
fun getClassesInPackageFilePath(fqName: FqName): String =
|
||||
fqName.toPath().withSepIfNotEmpty() + shortName(fqName) + "." + CLASSES_FILE_EXTENSION
|
||||
|
||||
|
||||
fun getClassMetadataPath(classId: ClassId): String {
|
||||
return classId.packageFqName.toPath().withSepIfNotEmpty() + classId.relativeClassName.asString() +
|
||||
"." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
|
||||
}
|
||||
|
||||
fun getPackageFilePath(fqName: FqName): String =
|
||||
getPackageClassFqName(fqName).toPath() + "." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
|
||||
|
||||
fun getStringTableFilePath(fqName: FqName): String =
|
||||
fqName.toPath().withSepIfNotEmpty() + shortName(fqName) + "." + STRING_TABLE_FILE_EXTENSION
|
||||
|
||||
fun getFileListFilePath(fqName: FqName) = fqName.toPath().withSepIfNotEmpty() + shortName(fqName) + "." + FILE_LIST_FILE_EXTENSION
|
||||
|
||||
private fun FqName.toPath() = this.asString().replace('.', '/')
|
||||
|
||||
private fun String.withSepIfNotEmpty() = if (this.isEmpty()) this else this + "/"
|
||||
|
||||
private fun shortName(fqName: FqName): String =
|
||||
if (fqName.isRoot) "default-package" else fqName.shortName().asString()
|
||||
|
||||
}
|
||||
|
||||
private val PACKAGE_CLASS_NAME_SUFFIX: String = "Package"
|
||||
private val DEFAULT_PACKAGE_CLASS_NAME: String = "_Default" + PACKAGE_CLASS_NAME_SUFFIX
|
||||
private val DEFAULT_PACKAGE_METAFILE_NAME: String = DEFAULT_PACKAGE_CLASS_NAME + "." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
|
||||
|
||||
fun FqName.isPackageClassFqName(): Boolean = !this.isRoot && getPackageClassFqName(this.parent()) == this
|
||||
|
||||
fun isDefaultPackageMetafile(fileName: String): Boolean = fileName == DEFAULT_PACKAGE_METAFILE_NAME
|
||||
|
||||
private fun getPackageClassFqName(packageFQN: FqName): FqName {
|
||||
return packageFQN.child(Name.identifier(getPackageClassName(packageFQN)))
|
||||
}
|
||||
|
||||
private fun getPackageClassName(packageFQN: FqName): String {
|
||||
return if (packageFQN.isRoot) DEFAULT_PACKAGE_CLASS_NAME else capitalizeNonEmptyString(packageFQN.shortName().asString()) + PACKAGE_CLASS_NAME_SUFFIX
|
||||
}
|
||||
|
||||
private fun capitalizeNonEmptyString(s: String): String {
|
||||
return if (s[0].isUpperCase()) s else s[0].toUpperCase() + s.substring(1)
|
||||
}
|
||||
+10
-1
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -82,4 +83,12 @@ object JsSerializerProtocol : SerializerExtensionProtocol(
|
||||
JsProtoBuf.constructorAnnotation, JsProtoBuf.classAnnotation, JsProtoBuf.functionAnnotation, JsProtoBuf.propertyAnnotation,
|
||||
JsProtoBuf.enumEntryAnnotation, JsProtoBuf.compileTimeValue, JsProtoBuf.parameterAnnotation, JsProtoBuf.typeAnnotation,
|
||||
JsProtoBuf.typeParameterAnnotation
|
||||
)
|
||||
) {
|
||||
fun getKjsmFilePath(packageFqName: FqName): String {
|
||||
val shortName = if (packageFqName.isRoot) Name.identifier("root-package") else packageFqName.shortName()
|
||||
|
||||
return packageFqName.child(shortName).asString().replace('.', '/') +
|
||||
"." +
|
||||
KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user