Don't serialize default primary constructors

Drop "Callable primary_constructor" field, because it requires serializer to
serialize the fact that a class has a primary constructor. Default primary
constructors for objects etc. may not be serialized, because they can be
re-created trivially when they're loaded. There are three options: a class
doesn't have a primary constructor, a class has a default primary constructor,
a class has a custom primary constructor. This explains the change in
descriptors.proto
This commit is contained in:
Alexander Udalov
2013-11-01 17:12:33 +04:00
parent 606b3aa4a9
commit 008e5f0b13
71 changed files with 724 additions and 245 deletions
@@ -1,2 +1,3 @@
R 0B
j
0B

Binary file not shown.
Binary file not shown.
@@ -1,8 +1,9 @@
& 2

 R Ć0B
 Z
 Z
0B
 Z
&0B

 j
Ć0B

Binary file not shown.
@@ -1,8 +1,9 @@
&2

 R Ć0B
Z
 Z
0B
 Z
&0?B

 j
Ć0B

Binary file not shown.
@@ -1,8 +1,9 @@
&!2

R Ć0B
!Z
Z
0B
Z
&0LB

j
Ć0B
!
Binary file not shown.
@@ -1,8 +1,9 @@
&*2

R Ć0B
*Z
Z
0B
Z
&0]B

j
Ć0B
*
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,8 @@
&F2

R Ć0B
FZ
Z
0B
Z &0ŞB

j
Ć0B
F
@@ -1,4 +1,5 @@
_2
-
_HR Â0B
_`Ä
_Hj
Â0B
_
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,8 @@
&d2

R Ć0B
dZ
Z
0B
Z &0ĐB

j
Ć0B
d
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,8 @@
&Ż2

R Ć0B
ŻZ
Z
0B
Z &0§B

j
Ć0B
Ż
@@ -1,2 +1,3 @@
ЅR В0B
Ѕj
В0B
Ѕ
@@ -1,6 +1,5 @@
&
2
(R Ć0B
2
(Z
&06B
 Z
@@ -14,4 +13,6 @@
Z
&0;B
Z
Z
&0<B
j
Ć0B
Binary file not shown.
@@ -1,7 +1,8 @@
&Á2

R Ć0B
ÁZ
Z
0B
Z &0ĐB

j
Ć0B
Á
Binary file not shown.
@@ -1,8 +1,9 @@
Ä2
R+Ć0:
Ő
%:Ö
ÄB
Z0×B
ÄZ
B
0ŘB
%Z 0ŮB
j-
+Ć0:
Ő
%:Ö
@@ -1,3 +1,4 @@
2
HR В0B
Hj
В0B

@@ -1,3 +1,4 @@
2
R 0B
j
0B

@@ -1,3 +1,4 @@
Η2
R Ζ0B
j
Ζ0B
Η
@@ -1,5 +1,6 @@
É2
RÆ0: à
Z Æ 0àB
_j
Æ0: à
_B
ÉZ Æ 0àB
_
É
@@ -1,3 +1,4 @@
2
R 0B
j
0B

Binary file not shown.
@@ -1,3 +1,4 @@
2
R 0B
j
0B

@@ -120,12 +120,19 @@ message Class {
optional bool class_object_present = 9 [default = false];
optional Callable primary_constructor = 10;
// todo: other constructors?
repeated Callable member = 11;
repeated int32 enum_entry = 12;
message PrimaryConstructor {
// If this field is present, it contains serialized data for the primary constructor.
// Otherwise it's default and can be created manually upon deserialization
optional Callable data = 1;
}
// This field is present if and only if the class has a primary constructor
optional PrimaryConstructor primary_constructor = 13;
// todo: other constructors?
}
message Package {
@@ -19,6 +19,7 @@ package org.jetbrains.jet.descriptors.serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.TypeProjection;
@@ -101,8 +102,16 @@ public class DescriptorSerializer {
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
if (primaryConstructor != null) {
builder.setPrimaryConstructor(local.callableProto(primaryConstructor));
if (DescriptorFactory.isDefaultPrimaryConstructor(primaryConstructor)) {
builder.setPrimaryConstructor(ProtoBuf.Class.PrimaryConstructor.getDefaultInstance());
}
else {
ProtoBuf.Class.PrimaryConstructor.Builder constructorBuilder = ProtoBuf.Class.PrimaryConstructor.newBuilder();
constructorBuilder.setData(local.callableProto(primaryConstructor));
builder.setPrimaryConstructor(constructorBuilder);
}
}
// TODO: other constructors
for (DeclarationDescriptor descriptor : sort(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors())) {
@@ -4437,24 +4437,6 @@ public final class ProtoBuf {
*/
boolean getClassObjectPresent();
// optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
boolean hasPrimaryConstructor();
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getPrimaryConstructor();
// repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 11;
/**
* <code>repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 11;</code>
@@ -4483,6 +4465,24 @@ public final class ProtoBuf {
* <code>repeated int32 enum_entry = 12;</code>
*/
int getEnumEntry(int index);
// optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
boolean hasPrimaryConstructor();
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor getPrimaryConstructor();
}
/**
* Protobuf type {@code org.jetbrains.jet.descriptors.serialization.Class}
@@ -4605,31 +4605,18 @@ public final class ProtoBuf {
classObjectPresent_ = input.readBool();
break;
}
case 82: {
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder subBuilder = null;
if (((bitField0_ & 0x00000010) == 0x00000010)) {
subBuilder = primaryConstructor_.toBuilder();
}
primaryConstructor_ = input.readMessage(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.PARSER, extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(primaryConstructor_);
primaryConstructor_ = subBuilder.buildPartial();
}
bitField0_ |= 0x00000010;
break;
}
case 90: {
if (!((mutable_bitField0_ & 0x00000200) == 0x00000200)) {
if (!((mutable_bitField0_ & 0x00000100) == 0x00000100)) {
member_ = new java.util.ArrayList<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable>();
mutable_bitField0_ |= 0x00000200;
mutable_bitField0_ |= 0x00000100;
}
member_.add(input.readMessage(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.PARSER, extensionRegistry));
break;
}
case 96: {
if (!((mutable_bitField0_ & 0x00000400) == 0x00000400)) {
if (!((mutable_bitField0_ & 0x00000200) == 0x00000200)) {
enumEntry_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000400;
mutable_bitField0_ |= 0x00000200;
}
enumEntry_.add(input.readInt32());
break;
@@ -4637,9 +4624,9 @@ public final class ProtoBuf {
case 98: {
int length = input.readRawVarint32();
int limit = input.pushLimit(length);
if (!((mutable_bitField0_ & 0x00000400) == 0x00000400) && input.getBytesUntilLimit() > 0) {
if (!((mutable_bitField0_ & 0x00000200) == 0x00000200) && input.getBytesUntilLimit() > 0) {
enumEntry_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000400;
mutable_bitField0_ |= 0x00000200;
}
while (input.getBytesUntilLimit() > 0) {
enumEntry_.add(input.readInt32());
@@ -4647,6 +4634,19 @@ public final class ProtoBuf {
input.popLimit(limit);
break;
}
case 106: {
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.Builder subBuilder = null;
if (((bitField0_ & 0x00000010) == 0x00000010)) {
subBuilder = primaryConstructor_.toBuilder();
}
primaryConstructor_ = input.readMessage(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.PARSER, extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(primaryConstructor_);
primaryConstructor_ = subBuilder.buildPartial();
}
bitField0_ |= 0x00000010;
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -4667,10 +4667,10 @@ public final class ProtoBuf {
if (((mutable_bitField0_ & 0x00000040) == 0x00000040)) {
nestedObjectName_ = java.util.Collections.unmodifiableList(nestedObjectName_);
}
if (((mutable_bitField0_ & 0x00000200) == 0x00000200)) {
if (((mutable_bitField0_ & 0x00000100) == 0x00000100)) {
member_ = java.util.Collections.unmodifiableList(member_);
}
if (((mutable_bitField0_ & 0x00000400) == 0x00000400)) {
if (((mutable_bitField0_ & 0x00000200) == 0x00000200)) {
enumEntry_ = java.util.Collections.unmodifiableList(enumEntry_);
}
makeExtensionsImmutable();
@@ -4800,6 +4800,437 @@ public final class ProtoBuf {
// @@protoc_insertion_point(enum_scope:org.jetbrains.jet.descriptors.serialization.Class.Kind)
}
public interface PrimaryConstructorOrBuilder
extends com.google.protobuf.MessageLiteOrBuilder {
// optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
boolean hasData();
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getData();
}
/**
* Protobuf type {@code org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor}
*/
public static final class PrimaryConstructor extends
com.google.protobuf.GeneratedMessageLite
implements PrimaryConstructorOrBuilder {
// Use PrimaryConstructor.newBuilder() to construct.
private PrimaryConstructor(com.google.protobuf.GeneratedMessageLite.Builder builder) {
super(builder);
}
private PrimaryConstructor(boolean noInit) {}
private static final PrimaryConstructor defaultInstance;
public static PrimaryConstructor getDefaultInstance() {
return defaultInstance;
}
public PrimaryConstructor getDefaultInstanceForType() {
return defaultInstance;
}
private PrimaryConstructor(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
initFields();
int mutable_bitField0_ = 0;
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
default: {
if (!parseUnknownField(input,
extensionRegistry, tag)) {
done = true;
}
break;
}
case 10: {
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder subBuilder = null;
if (((bitField0_ & 0x00000001) == 0x00000001)) {
subBuilder = data_.toBuilder();
}
data_ = input.readMessage(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.PARSER, extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(data_);
data_ = subBuilder.buildPartial();
}
bitField0_ |= 0x00000001;
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e.getMessage()).setUnfinishedMessage(this);
} finally {
makeExtensionsImmutable();
}
}
public static com.google.protobuf.Parser<PrimaryConstructor> PARSER =
new com.google.protobuf.AbstractParser<PrimaryConstructor>() {
public PrimaryConstructor parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new PrimaryConstructor(input, extensionRegistry);
}
};
@java.lang.Override
public com.google.protobuf.Parser<PrimaryConstructor> getParserForType() {
return PARSER;
}
private int bitField0_;
// optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;
public static final int DATA_FIELD_NUMBER = 1;
private org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable data_;
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public boolean hasData() {
return ((bitField0_ & 0x00000001) == 0x00000001);
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getData() {
return data_;
}
private void initFields() {
data_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized != -1) return isInitialized == 1;
if (hasData()) {
if (!getData().isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
memoizedIsInitialized = 1;
return true;
}
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
getSerializedSize();
if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeMessage(1, data_);
}
}
private int memoizedSerializedSize = -1;
public int getSerializedSize() {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
if (((bitField0_ & 0x00000001) == 0x00000001)) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(1, data_);
}
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.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseFrom(input, extensionRegistry);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input, extensionRegistry);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.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.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor prototype) {
return newBuilder().mergeFrom(prototype);
}
public Builder toBuilder() { return newBuilder(this); }
/**
* Protobuf type {@code org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageLite.Builder<
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor, Builder>
implements org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructorOrBuilder {
// Construct using org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
}
private static Builder create() {
return new Builder();
}
public Builder clear() {
super.clear();
data_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000001);
return this;
}
public Builder clone() {
return create().mergeFrom(buildPartial());
}
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor getDefaultInstanceForType() {
return org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.getDefaultInstance();
}
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor build() {
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor buildPartial() {
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor result = new org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
to_bitField0_ |= 0x00000001;
}
result.data_ = data_;
result.bitField0_ = to_bitField0_;
return result;
}
public Builder mergeFrom(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor other) {
if (other == org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.getDefaultInstance()) return this;
if (other.hasData()) {
mergeData(other.getData());
}
return this;
}
public final boolean isInitialized() {
if (hasData()) {
if (!getData().isInitialized()) {
return false;
}
}
return true;
}
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor) e.getUnfinishedMessage();
throw e;
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int bitField0_;
// optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;
private org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable data_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public boolean hasData() {
return ((bitField0_ & 0x00000001) == 0x00000001);
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getData() {
return data_;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public Builder setData(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable value) {
if (value == null) {
throw new NullPointerException();
}
data_ = value;
bitField0_ |= 0x00000001;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public Builder setData(
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder builderForValue) {
data_ = builderForValue.build();
bitField0_ |= 0x00000001;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public Builder mergeData(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable value) {
if (((bitField0_ & 0x00000001) == 0x00000001) &&
data_ != org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance()) {
data_ =
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.newBuilder(data_).mergeFrom(value).buildPartial();
} else {
data_ = value;
}
bitField0_ |= 0x00000001;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable data = 1;</code>
*
* <pre>
* If this field is present, it contains serialized data for the primary constructor.
* Otherwise it's default and can be created manually upon deserialization
* </pre>
*/
public Builder clearData() {
data_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000001);
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor)
}
static {
defaultInstance = new PrimaryConstructor(true);
defaultInstance.initFields();
}
// @@protoc_insertion_point(class_scope:org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor)
}
private int bitField0_;
// optional int32 flags = 1 [default = 0];
public static final int FLAGS_FIELD_NUMBER = 1;
@@ -5055,30 +5486,6 @@ public final class ProtoBuf {
return classObjectPresent_;
}
// optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;
public static final int PRIMARY_CONSTRUCTOR_FIELD_NUMBER = 10;
private org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable primaryConstructor_;
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public boolean hasPrimaryConstructor() {
return ((bitField0_ & 0x00000010) == 0x00000010);
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getPrimaryConstructor() {
return primaryConstructor_;
}
// repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 11;
public static final int MEMBER_FIELD_NUMBER = 11;
private java.util.List<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable> member_;
@@ -5138,6 +5545,30 @@ public final class ProtoBuf {
return enumEntry_.get(index);
}
// optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;
public static final int PRIMARY_CONSTRUCTOR_FIELD_NUMBER = 13;
private org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor primaryConstructor_;
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public boolean hasPrimaryConstructor() {
return ((bitField0_ & 0x00000010) == 0x00000010);
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor getPrimaryConstructor() {
return primaryConstructor_;
}
private void initFields() {
flags_ = 0;
extraVisibility_ = "";
@@ -5147,9 +5578,9 @@ public final class ProtoBuf {
nestedClassName_ = java.util.Collections.emptyList();
nestedObjectName_ = java.util.Collections.emptyList();
classObjectPresent_ = false;
primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
member_ = java.util.Collections.emptyList();
enumEntry_ = java.util.Collections.emptyList();
primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.getDefaultInstance();
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -5172,14 +5603,14 @@ public final class ProtoBuf {
return false;
}
}
if (hasPrimaryConstructor()) {
if (!getPrimaryConstructor().isInitialized()) {
for (int i = 0; i < getMemberCount(); i++) {
if (!getMember(i).isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
for (int i = 0; i < getMemberCount(); i++) {
if (!getMember(i).isInitialized()) {
if (hasPrimaryConstructor()) {
if (!getPrimaryConstructor().isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
@@ -5215,15 +5646,15 @@ public final class ProtoBuf {
if (((bitField0_ & 0x00000008) == 0x00000008)) {
output.writeBool(9, classObjectPresent_);
}
if (((bitField0_ & 0x00000010) == 0x00000010)) {
output.writeMessage(10, primaryConstructor_);
}
for (int i = 0; i < member_.size(); i++) {
output.writeMessage(11, member_.get(i));
}
for (int i = 0; i < enumEntry_.size(); i++) {
output.writeInt32(12, enumEntry_.get(i));
}
if (((bitField0_ & 0x00000010) == 0x00000010)) {
output.writeMessage(13, primaryConstructor_);
}
}
private int memoizedSerializedSize = -1;
@@ -5274,10 +5705,6 @@ public final class ProtoBuf {
size += com.google.protobuf.CodedOutputStream
.computeBoolSize(9, classObjectPresent_);
}
if (((bitField0_ & 0x00000010) == 0x00000010)) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(10, primaryConstructor_);
}
for (int i = 0; i < member_.size(); i++) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(11, member_.get(i));
@@ -5291,6 +5718,10 @@ public final class ProtoBuf {
size += dataSize;
size += 1 * getEnumEntryList().size();
}
if (((bitField0_ & 0x00000010) == 0x00000010)) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(13, primaryConstructor_);
}
memoizedSerializedSize = size;
return size;
}
@@ -5398,11 +5829,11 @@ public final class ProtoBuf {
bitField0_ = (bitField0_ & ~0x00000040);
classObjectPresent_ = false;
bitField0_ = (bitField0_ & ~0x00000080);
primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000100);
member_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000200);
bitField0_ = (bitField0_ & ~0x00000100);
enumEntry_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000200);
primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000400);
return this;
}
@@ -5463,20 +5894,20 @@ public final class ProtoBuf {
to_bitField0_ |= 0x00000008;
}
result.classObjectPresent_ = classObjectPresent_;
if (((from_bitField0_ & 0x00000100) == 0x00000100)) {
if (((bitField0_ & 0x00000100) == 0x00000100)) {
member_ = java.util.Collections.unmodifiableList(member_);
bitField0_ = (bitField0_ & ~0x00000100);
}
result.member_ = member_;
if (((bitField0_ & 0x00000200) == 0x00000200)) {
enumEntry_ = java.util.Collections.unmodifiableList(enumEntry_);
bitField0_ = (bitField0_ & ~0x00000200);
}
result.enumEntry_ = enumEntry_;
if (((from_bitField0_ & 0x00000400) == 0x00000400)) {
to_bitField0_ |= 0x00000010;
}
result.primaryConstructor_ = primaryConstructor_;
if (((bitField0_ & 0x00000200) == 0x00000200)) {
member_ = java.util.Collections.unmodifiableList(member_);
bitField0_ = (bitField0_ & ~0x00000200);
}
result.member_ = member_;
if (((bitField0_ & 0x00000400) == 0x00000400)) {
enumEntry_ = java.util.Collections.unmodifiableList(enumEntry_);
bitField0_ = (bitField0_ & ~0x00000400);
}
result.enumEntry_ = enumEntry_;
result.bitField0_ = to_bitField0_;
return result;
}
@@ -5537,13 +5968,10 @@ public final class ProtoBuf {
if (other.hasClassObjectPresent()) {
setClassObjectPresent(other.getClassObjectPresent());
}
if (other.hasPrimaryConstructor()) {
mergePrimaryConstructor(other.getPrimaryConstructor());
}
if (!other.member_.isEmpty()) {
if (member_.isEmpty()) {
member_ = other.member_;
bitField0_ = (bitField0_ & ~0x00000200);
bitField0_ = (bitField0_ & ~0x00000100);
} else {
ensureMemberIsMutable();
member_.addAll(other.member_);
@@ -5553,13 +5981,16 @@ public final class ProtoBuf {
if (!other.enumEntry_.isEmpty()) {
if (enumEntry_.isEmpty()) {
enumEntry_ = other.enumEntry_;
bitField0_ = (bitField0_ & ~0x00000400);
bitField0_ = (bitField0_ & ~0x00000200);
} else {
ensureEnumEntryIsMutable();
enumEntry_.addAll(other.enumEntry_);
}
}
if (other.hasPrimaryConstructor()) {
mergePrimaryConstructor(other.getPrimaryConstructor());
}
return this;
}
@@ -5580,14 +6011,14 @@ public final class ProtoBuf {
return false;
}
}
if (hasPrimaryConstructor()) {
if (!getPrimaryConstructor().isInitialized()) {
for (int i = 0; i < getMemberCount(); i++) {
if (!getMember(i).isInitialized()) {
return false;
}
}
for (int i = 0; i < getMemberCount(); i++) {
if (!getMember(i).isInitialized()) {
if (hasPrimaryConstructor()) {
if (!getPrimaryConstructor().isInitialized()) {
return false;
}
@@ -6264,98 +6695,13 @@ public final class ProtoBuf {
return this;
}
// optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;
private org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public boolean hasPrimaryConstructor() {
return ((bitField0_ & 0x00000100) == 0x00000100);
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getPrimaryConstructor() {
return primaryConstructor_;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public Builder setPrimaryConstructor(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable value) {
if (value == null) {
throw new NullPointerException();
}
primaryConstructor_ = value;
bitField0_ |= 0x00000100;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public Builder setPrimaryConstructor(
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder builderForValue) {
primaryConstructor_ = builderForValue.build();
bitField0_ |= 0x00000100;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public Builder mergePrimaryConstructor(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable value) {
if (((bitField0_ & 0x00000100) == 0x00000100) &&
primaryConstructor_ != org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance()) {
primaryConstructor_ =
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.newBuilder(primaryConstructor_).mergeFrom(value).buildPartial();
} else {
primaryConstructor_ = value;
}
bitField0_ |= 0x00000100;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Callable primary_constructor = 10;</code>
*
* <pre>
* todo: other constructors?
* </pre>
*/
public Builder clearPrimaryConstructor() {
primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000100);
return this;
}
// repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 11;
private java.util.List<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable> member_ =
java.util.Collections.emptyList();
private void ensureMemberIsMutable() {
if (!((bitField0_ & 0x00000200) == 0x00000200)) {
if (!((bitField0_ & 0x00000100) == 0x00000100)) {
member_ = new java.util.ArrayList<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable>(member_);
bitField0_ |= 0x00000200;
bitField0_ |= 0x00000100;
}
}
@@ -6460,7 +6806,7 @@ public final class ProtoBuf {
*/
public Builder clearMember() {
member_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000200);
bitField0_ = (bitField0_ & ~0x00000100);
return this;
}
@@ -6477,9 +6823,9 @@ public final class ProtoBuf {
// repeated int32 enum_entry = 12;
private java.util.List<java.lang.Integer> enumEntry_ = java.util.Collections.emptyList();
private void ensureEnumEntryIsMutable() {
if (!((bitField0_ & 0x00000400) == 0x00000400)) {
if (!((bitField0_ & 0x00000200) == 0x00000200)) {
enumEntry_ = new java.util.ArrayList<java.lang.Integer>(enumEntry_);
bitField0_ |= 0x00000400;
bitField0_ |= 0x00000200;
}
}
/**
@@ -6535,11 +6881,96 @@ public final class ProtoBuf {
*/
public Builder clearEnumEntry() {
enumEntry_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000400);
bitField0_ = (bitField0_ & ~0x00000200);
return this;
}
// optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;
private org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.getDefaultInstance();
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public boolean hasPrimaryConstructor() {
return ((bitField0_ & 0x00000400) == 0x00000400);
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor getPrimaryConstructor() {
return primaryConstructor_;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public Builder setPrimaryConstructor(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor value) {
if (value == null) {
throw new NullPointerException();
}
primaryConstructor_ = value;
bitField0_ |= 0x00000400;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public Builder setPrimaryConstructor(
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.Builder builderForValue) {
primaryConstructor_ = builderForValue.build();
bitField0_ |= 0x00000400;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public Builder mergePrimaryConstructor(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor value) {
if (((bitField0_ & 0x00000400) == 0x00000400) &&
primaryConstructor_ != org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.getDefaultInstance()) {
primaryConstructor_ =
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.newBuilder(primaryConstructor_).mergeFrom(value).buildPartial();
} else {
primaryConstructor_ = value;
}
bitField0_ |= 0x00000400;
return this;
}
/**
* <code>optional .org.jetbrains.jet.descriptors.serialization.Class.PrimaryConstructor primary_constructor = 13;</code>
*
* <pre>
* This field is present if and only if the class has a primary constructor
* </pre>
*/
public Builder clearPrimaryConstructor() {
primaryConstructor_ = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Class.PrimaryConstructor.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000400);
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.jet.descriptors.serialization.Class)
}
@@ -209,8 +209,14 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
private ConstructorDescriptor computePrimaryConstructor() {
if (!classProto.hasPrimaryConstructor()) return null;
ProtoBuf.Callable constructorProto = classProto.getPrimaryConstructor();
return (ConstructorDescriptor) deserializer.loadCallable(constructorProto);
ProtoBuf.Class.PrimaryConstructor constructorProto = classProto.getPrimaryConstructor();
if (!constructorProto.hasData()) {
ConstructorDescriptorImpl descriptor = DescriptorFactory.createPrimaryConstructorForObject(this);
descriptor.setReturnType(getDefaultType());
return descriptor;
}
return (ConstructorDescriptor) deserializer.loadCallable(constructorProto.getData());
}
@Nullable
@@ -35,6 +35,14 @@ public class DescriptorFactory {
public static final Name VALUE_OF_METHOD_NAME = Name.identifier("valueOf");
public static final Name VALUES_METHOD_NAME = Name.identifier("values");
private static class DefaultConstructorDescriptor extends ConstructorDescriptorImpl {
public DefaultConstructorDescriptor(@NotNull ClassDescriptor containingClass) {
super(containingClass, Collections.<AnnotationDescriptor>emptyList(), true);
initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
getDefaultConstructorVisibility(containingClass));
}
}
private DescriptorFactory() {
}
@@ -68,12 +76,11 @@ public class DescriptorFactory {
@NotNull
public static ConstructorDescriptorImpl createPrimaryConstructorForObject(@NotNull ClassDescriptor containingClass) {
ConstructorDescriptorImpl constructorDescriptor =
new ConstructorDescriptorImpl(containingClass, Collections.<AnnotationDescriptor>emptyList(), true);
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(),
Collections.<ValueParameterDescriptor>emptyList(),
getDefaultConstructorVisibility(containingClass));
return constructorDescriptor;
return new DefaultConstructorDescriptor(containingClass);
}
public static boolean isDefaultPrimaryConstructor(@NotNull ConstructorDescriptor constructor) {
return constructor instanceof DefaultConstructorDescriptor;
}
@NotNull