From a165418f613a0cbf97a97a818957e08d1352b2b3 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 2 Aug 2015 20:28:57 +0200 Subject: Support absent protobuf arrays in ProtobufJsonFormat Protobuf does not support concept of absent arrays (repeated field). It does not distinguish empty arrays from absent arrays. ProtobufJsonFormat introduces a naming convention to mark an empty array field as absent. In this case the field is not output to JSON. --- .../org/sonar/core/util/ProtobufJsonFormat.java | 224 +- .../test/gen-java/org/sonar/core/test/Test.java | 2914 ++++++++++++++------ .../sonar/core/util/ProtobufJsonFormatTest.java | 110 +- .../java/org/sonar/core/util/ProtobufTest.java | 12 +- sonar-core/src/test/protobuf/test.proto | 32 +- 5 files changed, 2373 insertions(+), 919 deletions(-) (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/util/ProtobufJsonFormat.java b/sonar-core/src/main/java/org/sonar/core/util/ProtobufJsonFormat.java index e156c17f432..30bc9bccd69 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/ProtobufJsonFormat.java +++ b/sonar-core/src/main/java/org/sonar/core/util/ProtobufJsonFormat.java @@ -19,15 +19,54 @@ */ package org.sonar.core.util; +import com.google.common.base.Preconditions; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import com.google.protobuf.Descriptors; import com.google.protobuf.Message; +import java.io.StringWriter; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.List; import java.util.Map; import org.sonar.api.utils.text.JsonWriter; /** * Converts a Protocol Buffers message to JSON. Unknown fields, binary fields, (deprecated) groups - * and maps are not supported. + * and maps are not supported. Absent fields are ignored, so it's possible to distinguish + * null strings (field is absent) and empty strings (field is present with value {@code ""}). + *

+ *

Empty Arrays

+ * Protobuf does not make the difference between absent arrays and empty arrays (size is zero). + * The consequence is that arrays are always output in JSON. Empty arrays are converted to {@code []}. + *

+ * A workaround is implemented in {@link ProtobufJsonFormat} to not generate absent arrays into JSON document. + * A boolean field is used to declare if the related repeated field (the array) is present or not. The + * name of the boolean field must be the array field name suffixed with "PresentIfEmpty". This field is "for internal + * use" and is not generated into JSON document. It is ignored when the array is not empty. + * + * For example: + *

+ *   // proto specification
+ *   message Response {
+ *     optional bool issuesPresentIfEmpty = 1;
+ *     repeated Issue issues = 2;
+ *   }
+ * 
+ *
+ *   // Java usage
+ *
+ *   Response.newBuilder().build();
+ *   // output: {}
+ *
+ *   Response.newBuilder().setIssuesPresentIfEmpty(true).build();
+ *   // output: {"issues": []}
+ *
+ *   // no need to set the flag to true when the array is not empty
+ *   Response.newBuilder().setIssues(atLeastOneIssues).build();
+ *   // output: {"issues": [{...}, {...}]}
+ * 
*/ public class ProtobufJsonFormat { @@ -35,33 +74,183 @@ public class ProtobufJsonFormat { // only statics } + private static abstract class MessageField { + protected final Descriptors.FieldDescriptor descriptor; + + public MessageField(Descriptors.FieldDescriptor descriptor) { + this.descriptor = descriptor; + } + + public String getName() { + return descriptor.getName(); + } + + public Descriptors.FieldDescriptor.JavaType getJavaType() { + return descriptor.getJavaType(); + } + + public abstract boolean isRepeated(); + + public abstract boolean hasValue(Message message); + + public abstract Object getValue(Message message); + } + + private static class MessageNonRepeatedField extends MessageField { + public MessageNonRepeatedField(Descriptors.FieldDescriptor descriptor) { + super(descriptor); + Preconditions.checkArgument(!descriptor.isRepeated()); + } + + @Override + public boolean isRepeated() { + return false; + } + + @Override + public boolean hasValue(Message message) { + return message.hasField(descriptor); + } + + @Override + public Object getValue(Message message) { + return message.getField(descriptor); + } + } + + private static class MessageRepeatedField extends MessageField { + public MessageRepeatedField(Descriptors.FieldDescriptor descriptor) { + super(descriptor); + Preconditions.checkArgument(descriptor.isRepeated()); + } + + @Override + public boolean isRepeated() { + return true; + } + + @Override + public boolean hasValue(Message message) { + return true; + } + + @Override + public Object getValue(Message message) { + return message.getField(descriptor); + } + } + + private static class MessageNullableRepeatedField extends MessageField { + private final Descriptors.FieldDescriptor booleanDesc; + + public MessageNullableRepeatedField(Descriptors.FieldDescriptor booleanDesc, Descriptors.FieldDescriptor arrayDescriptor) { + super(arrayDescriptor); + Preconditions.checkArgument(arrayDescriptor.isRepeated()); + Preconditions.checkArgument(booleanDesc.getJavaType() == Descriptors.FieldDescriptor.JavaType.BOOLEAN); + this.booleanDesc = booleanDesc; + } + + @Override + public boolean isRepeated() { + return true; + } + + @Override + public boolean hasValue(Message message) { + if (((Collection) message.getField(descriptor)).isEmpty()) { + return message.hasField(booleanDesc) && (boolean) message.getField(booleanDesc); + } + return true; + } + + @Override + public Object getValue(Message message) { + return message.getField(descriptor); + } + } + + static class MessageJsonDescriptor { + private static final Map, MessageJsonDescriptor> BY_CLASS = new HashMap<>(); + private final MessageField[] fields; + + private MessageJsonDescriptor(MessageField[] fields) { + this.fields = fields; + } + + MessageField[] getFields() { + return fields; + } + + static MessageJsonDescriptor of(Message message) { + MessageJsonDescriptor desc = BY_CLASS.get(message.getClass()); + if (desc == null) { + desc = introspect(message); + BY_CLASS.put(message.getClass(), desc); + } + return desc; + } + + private static MessageJsonDescriptor introspect(Message message) { + List fields = new ArrayList<>(); + BiMap repeatedToBoolean = HashBiMap.create(); + for (Descriptors.FieldDescriptor desc : message.getDescriptorForType().getFields()) { + if (desc.isRepeated()) { + String booleanName = desc.getName() + "PresentIfEmpty"; + Descriptors.FieldDescriptor booleanDesc = message.getDescriptorForType().findFieldByName(booleanName); + if (booleanDesc != null && booleanDesc.getJavaType() == Descriptors.FieldDescriptor.JavaType.BOOLEAN) { + repeatedToBoolean.put(desc, booleanDesc); + } + } + } + for (Descriptors.FieldDescriptor descriptor : message.getDescriptorForType().getFields()) { + if (descriptor.isRepeated()) { + Descriptors.FieldDescriptor booleanDesc = repeatedToBoolean.get(descriptor); + if (booleanDesc == null) { + fields.add(new MessageRepeatedField(descriptor)); + } else { + fields.add(new MessageNullableRepeatedField(booleanDesc, descriptor)); + } + } else if (!repeatedToBoolean.containsValue(descriptor)) { + fields.add(new MessageNonRepeatedField(descriptor)); + } + } + return new MessageJsonDescriptor(fields.toArray(new MessageField[fields.size()])); + } + } + public static void write(Message message, JsonWriter writer) { + writer.setSerializeNulls(false).setSerializeEmptys(true); writer.beginObject(); writeMessage(message, writer); writer.endObject(); } - private static void writeMessage(Message message, JsonWriter writer) { - for (Map.Entry entry : message.getAllFields().entrySet()) { - writeField(entry.getKey(), entry.getValue(), writer); - } + public static String toJson(Message message) { + StringWriter json = new StringWriter(); + JsonWriter jsonWriter = JsonWriter.of(json); + write(message, jsonWriter); + return json.toString(); } - private static void writeField(Descriptors.FieldDescriptor field, Object value, JsonWriter writer) { - writer.name(field.getName()); - if (field.isRepeated()) { - // Repeated field. Print each element. - writer.beginArray(); - for (Object o : (Collection) value) { - writeFieldValue(field, o, writer); + private static void writeMessage(Message message, JsonWriter writer) { + MessageJsonDescriptor fields = MessageJsonDescriptor.of(message); + for (MessageField field : fields.getFields()) { + if (field.hasValue(message)) { + writer.name(field.getName()); + if (field.isRepeated()) { + writer.beginArray(); + for (Object o : (Collection) field.getValue(message)) { + writeFieldValue(field, o, writer); + } + writer.endArray(); + } else { + writeFieldValue(field, field.getValue(message), writer); + } } - writer.endArray(); - } else { - writeFieldValue(field, value, writer); } } - private static void writeFieldValue(Descriptors.FieldDescriptor field, Object value, JsonWriter writer) { + private static void writeFieldValue(MessageField field, Object value, JsonWriter writer) { switch (field.getJavaType()) { case INT: writer.value((Integer) value); @@ -78,8 +267,6 @@ public class ProtobufJsonFormat { case STRING: writer.value((String) value); break; - case BYTE_STRING: - throw new IllegalStateException(String.format("JSON format does not support the binary field '%s'", field.getName())); case ENUM: writer.value(((Descriptors.EnumValueDescriptor) value).getName()); break; @@ -89,6 +276,7 @@ public class ProtobufJsonFormat { writer.endObject(); break; default: + throw new IllegalStateException(String.format("JSON format does not support type '%s' of field '%s'", field.getJavaType(), field.getName())); } } } diff --git a/sonar-core/src/test/gen-java/org/sonar/core/test/Test.java b/sonar-core/src/test/gen-java/org/sonar/core/test/Test.java index 18826a8f16d..c687af5b8b8 100644 --- a/sonar-core/src/test/gen-java/org/sonar/core/test/Test.java +++ b/sonar-core/src/test/gen-java/org/sonar/core/test/Test.java @@ -104,104 +104,27 @@ public final class Test { com.google.protobuf.MessageOrBuilder { /** - * optional string aString = 1; - */ - boolean hasAString(); - /** - * optional string aString = 1; - */ - java.lang.String getAString(); - /** - * optional string aString = 1; - */ - com.google.protobuf.ByteString - getAStringBytes(); - - /** - * optional int32 anInt = 2; - */ - boolean hasAnInt(); - /** - * optional int32 anInt = 2; - */ - int getAnInt(); - - /** - * optional int64 aLong = 3; - */ - boolean hasALong(); - /** - * optional int64 aLong = 3; - */ - long getALong(); - - /** - * optional double aDouble = 4; - */ - boolean hasADouble(); - /** - * optional double aDouble = 4; - */ - double getADouble(); - - /** - * optional bool aBoolean = 5; - */ - boolean hasABoolean(); - /** - * optional bool aBoolean = 5; - */ - boolean getABoolean(); - - /** - * optional .FakeEnum anEnum = 6; - */ - boolean hasAnEnum(); - /** - * optional .FakeEnum anEnum = 6; - */ - org.sonar.core.test.Test.FakeEnum getAnEnum(); - - /** - * optional bytes someBytes = 7; - */ - boolean hasSomeBytes(); - /** - * optional bytes someBytes = 7; - */ - com.google.protobuf.ByteString getSomeBytes(); - - /** - * repeated string anArray = 8; - */ - com.google.protobuf.ProtocolStringList - getAnArrayList(); - /** - * repeated string anArray = 8; + * optional string label = 1; */ - int getAnArrayCount(); + boolean hasLabel(); /** - * repeated string anArray = 8; + * optional string label = 1; */ - java.lang.String getAnArray(int index); + java.lang.String getLabel(); /** - * repeated string anArray = 8; + * optional string label = 1; */ com.google.protobuf.ByteString - getAnArrayBytes(int index); + getLabelBytes(); /** - * optional .NestedFake aNestedMessage = 9; - */ - boolean hasANestedMessage(); - /** - * optional .NestedFake aNestedMessage = 9; + * optional int32 line = 2; */ - org.sonar.core.test.Test.NestedFake getANestedMessage(); + boolean hasLine(); /** - * optional .NestedFake aNestedMessage = 9; + * optional int32 line = 2; */ - org.sonar.core.test.Test.NestedFakeOrBuilder getANestedMessageOrBuilder(); + int getLine(); } /** * Protobuf type {@code Fake} @@ -258,65 +181,12 @@ public final class Test { case 10: { com.google.protobuf.ByteString bs = input.readBytes(); bitField0_ |= 0x00000001; - aString_ = bs; + label_ = bs; break; } case 16: { bitField0_ |= 0x00000002; - anInt_ = input.readInt32(); - break; - } - case 24: { - bitField0_ |= 0x00000004; - aLong_ = input.readInt64(); - break; - } - case 33: { - bitField0_ |= 0x00000008; - aDouble_ = input.readDouble(); - break; - } - case 40: { - bitField0_ |= 0x00000010; - aBoolean_ = input.readBool(); - break; - } - case 48: { - int rawValue = input.readEnum(); - org.sonar.core.test.Test.FakeEnum value = org.sonar.core.test.Test.FakeEnum.valueOf(rawValue); - if (value == null) { - unknownFields.mergeVarintField(6, rawValue); - } else { - bitField0_ |= 0x00000020; - anEnum_ = value; - } - break; - } - case 58: { - bitField0_ |= 0x00000040; - someBytes_ = input.readBytes(); - break; - } - case 66: { - com.google.protobuf.ByteString bs = input.readBytes(); - if (!((mutable_bitField0_ & 0x00000080) == 0x00000080)) { - anArray_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000080; - } - anArray_.add(bs); - break; - } - case 74: { - org.sonar.core.test.Test.NestedFake.Builder subBuilder = null; - if (((bitField0_ & 0x00000080) == 0x00000080)) { - subBuilder = aNestedMessage_.toBuilder(); - } - aNestedMessage_ = input.readMessage(org.sonar.core.test.Test.NestedFake.PARSER, extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(aNestedMessage_); - aNestedMessage_ = subBuilder.buildPartial(); - } - bitField0_ |= 0x00000080; + line_ = input.readInt32(); break; } } @@ -327,9 +197,6 @@ public final class Test { throw new com.google.protobuf.InvalidProtocolBufferException( e.getMessage()).setUnfinishedMessage(this); } finally { - if (((mutable_bitField0_ & 0x00000080) == 0x00000080)) { - anArray_ = anArray_.getUnmodifiableView(); - } this.unknownFields = unknownFields.build(); makeExtensionsImmutable(); } @@ -362,19 +229,19 @@ public final class Test { } private int bitField0_; - public static final int ASTRING_FIELD_NUMBER = 1; - private java.lang.Object aString_; + public static final int LABEL_FIELD_NUMBER = 1; + private java.lang.Object label_; /** - * optional string aString = 1; + * optional string label = 1; */ - public boolean hasAString() { + public boolean hasLabel() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * optional string aString = 1; + * optional string label = 1; */ - public java.lang.String getAString() { - java.lang.Object ref = aString_; + public java.lang.String getLabel() { + java.lang.Object ref = label_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { @@ -382,178 +249,46 @@ public final class Test { (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { - aString_ = s; + label_ = s; } return s; } } /** - * optional string aString = 1; + * optional string label = 1; */ public com.google.protobuf.ByteString - getAStringBytes() { - java.lang.Object ref = aString_; + getLabelBytes() { + java.lang.Object ref = label_; if (ref instanceof java.lang.String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); - aString_ = b; + label_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } - public static final int ANINT_FIELD_NUMBER = 2; - private int anInt_; + public static final int LINE_FIELD_NUMBER = 2; + private int line_; /** - * optional int32 anInt = 2; + * optional int32 line = 2; */ - public boolean hasAnInt() { + public boolean hasLine() { return ((bitField0_ & 0x00000002) == 0x00000002); } /** - * optional int32 anInt = 2; - */ - public int getAnInt() { - return anInt_; - } - - public static final int ALONG_FIELD_NUMBER = 3; - private long aLong_; - /** - * optional int64 aLong = 3; - */ - public boolean hasALong() { - return ((bitField0_ & 0x00000004) == 0x00000004); - } - /** - * optional int64 aLong = 3; - */ - public long getALong() { - return aLong_; - } - - public static final int ADOUBLE_FIELD_NUMBER = 4; - private double aDouble_; - /** - * optional double aDouble = 4; - */ - public boolean hasADouble() { - return ((bitField0_ & 0x00000008) == 0x00000008); - } - /** - * optional double aDouble = 4; - */ - public double getADouble() { - return aDouble_; - } - - public static final int ABOOLEAN_FIELD_NUMBER = 5; - private boolean aBoolean_; - /** - * optional bool aBoolean = 5; - */ - public boolean hasABoolean() { - return ((bitField0_ & 0x00000010) == 0x00000010); - } - /** - * optional bool aBoolean = 5; - */ - public boolean getABoolean() { - return aBoolean_; - } - - public static final int ANENUM_FIELD_NUMBER = 6; - private org.sonar.core.test.Test.FakeEnum anEnum_; - /** - * optional .FakeEnum anEnum = 6; - */ - public boolean hasAnEnum() { - return ((bitField0_ & 0x00000020) == 0x00000020); - } - /** - * optional .FakeEnum anEnum = 6; - */ - public org.sonar.core.test.Test.FakeEnum getAnEnum() { - return anEnum_; - } - - public static final int SOMEBYTES_FIELD_NUMBER = 7; - private com.google.protobuf.ByteString someBytes_; - /** - * optional bytes someBytes = 7; - */ - public boolean hasSomeBytes() { - return ((bitField0_ & 0x00000040) == 0x00000040); - } - /** - * optional bytes someBytes = 7; - */ - public com.google.protobuf.ByteString getSomeBytes() { - return someBytes_; - } - - public static final int ANARRAY_FIELD_NUMBER = 8; - private com.google.protobuf.LazyStringList anArray_; - /** - * repeated string anArray = 8; - */ - public com.google.protobuf.ProtocolStringList - getAnArrayList() { - return anArray_; - } - /** - * repeated string anArray = 8; + * optional int32 line = 2; */ - public int getAnArrayCount() { - return anArray_.size(); - } - /** - * repeated string anArray = 8; - */ - public java.lang.String getAnArray(int index) { - return anArray_.get(index); - } - /** - * repeated string anArray = 8; - */ - public com.google.protobuf.ByteString - getAnArrayBytes(int index) { - return anArray_.getByteString(index); - } - - public static final int ANESTEDMESSAGE_FIELD_NUMBER = 9; - private org.sonar.core.test.Test.NestedFake aNestedMessage_; - /** - * optional .NestedFake aNestedMessage = 9; - */ - public boolean hasANestedMessage() { - return ((bitField0_ & 0x00000080) == 0x00000080); - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public org.sonar.core.test.Test.NestedFake getANestedMessage() { - return aNestedMessage_; - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public org.sonar.core.test.Test.NestedFakeOrBuilder getANestedMessageOrBuilder() { - return aNestedMessage_; + public int getLine() { + return line_; } private void initFields() { - aString_ = ""; - anInt_ = 0; - aLong_ = 0L; - aDouble_ = 0D; - aBoolean_ = false; - anEnum_ = org.sonar.core.test.Test.FakeEnum.BLUE; - someBytes_ = com.google.protobuf.ByteString.EMPTY; - anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; - aNestedMessage_ = org.sonar.core.test.Test.NestedFake.getDefaultInstance(); + label_ = ""; + line_ = 0; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -569,31 +304,10 @@ public final class Test { throws java.io.IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, getAStringBytes()); + output.writeBytes(1, getLabelBytes()); } if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeInt32(2, anInt_); - } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - output.writeInt64(3, aLong_); - } - if (((bitField0_ & 0x00000008) == 0x00000008)) { - output.writeDouble(4, aDouble_); - } - if (((bitField0_ & 0x00000010) == 0x00000010)) { - output.writeBool(5, aBoolean_); - } - if (((bitField0_ & 0x00000020) == 0x00000020)) { - output.writeEnum(6, anEnum_.getNumber()); - } - if (((bitField0_ & 0x00000040) == 0x00000040)) { - output.writeBytes(7, someBytes_); - } - for (int i = 0; i < anArray_.size(); i++) { - output.writeBytes(8, anArray_.getByteString(i)); - } - if (((bitField0_ & 0x00000080) == 0x00000080)) { - output.writeMessage(9, aNestedMessage_); + output.writeInt32(2, line_); } getUnknownFields().writeTo(output); } @@ -606,44 +320,11 @@ public final class Test { size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, getAStringBytes()); + .computeBytesSize(1, getLabelBytes()); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += com.google.protobuf.CodedOutputStream - .computeInt32Size(2, anInt_); - } - if (((bitField0_ & 0x00000004) == 0x00000004)) { - size += com.google.protobuf.CodedOutputStream - .computeInt64Size(3, aLong_); - } - if (((bitField0_ & 0x00000008) == 0x00000008)) { - size += com.google.protobuf.CodedOutputStream - .computeDoubleSize(4, aDouble_); - } - if (((bitField0_ & 0x00000010) == 0x00000010)) { - size += com.google.protobuf.CodedOutputStream - .computeBoolSize(5, aBoolean_); - } - if (((bitField0_ & 0x00000020) == 0x00000020)) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(6, anEnum_.getNumber()); - } - if (((bitField0_ & 0x00000040) == 0x00000040)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(7, someBytes_); - } - { - int dataSize = 0; - for (int i = 0; i < anArray_.size(); i++) { - dataSize += com.google.protobuf.CodedOutputStream - .computeBytesSizeNoTag(anArray_.getByteString(i)); - } - size += dataSize; - size += 1 * getAnArrayList().size(); - } - if (((bitField0_ & 0x00000080) == 0x00000080)) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(9, aNestedMessage_); + .computeInt32Size(2, line_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; @@ -754,7 +435,6 @@ public final class Test { } private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getANestedMessageFieldBuilder(); } } private static Builder create() { @@ -763,28 +443,10 @@ public final class Test { public Builder clear() { super.clear(); - aString_ = ""; + label_ = ""; bitField0_ = (bitField0_ & ~0x00000001); - anInt_ = 0; + line_ = 0; bitField0_ = (bitField0_ & ~0x00000002); - aLong_ = 0L; - bitField0_ = (bitField0_ & ~0x00000004); - aDouble_ = 0D; - bitField0_ = (bitField0_ & ~0x00000008); - aBoolean_ = false; - bitField0_ = (bitField0_ & ~0x00000010); - anEnum_ = org.sonar.core.test.Test.FakeEnum.BLUE; - bitField0_ = (bitField0_ & ~0x00000020); - someBytes_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000040); - anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000080); - if (aNestedMessageBuilder_ == null) { - aNestedMessage_ = org.sonar.core.test.Test.NestedFake.getDefaultInstance(); - } else { - aNestedMessageBuilder_.clear(); - } - bitField0_ = (bitField0_ & ~0x00000100); return this; } @@ -816,95 +478,34 @@ public final class Test { if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } - result.aString_ = aString_; + result.label_ = label_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } - result.anInt_ = anInt_; - if (((from_bitField0_ & 0x00000004) == 0x00000004)) { - to_bitField0_ |= 0x00000004; - } - result.aLong_ = aLong_; - if (((from_bitField0_ & 0x00000008) == 0x00000008)) { - to_bitField0_ |= 0x00000008; - } - result.aDouble_ = aDouble_; - if (((from_bitField0_ & 0x00000010) == 0x00000010)) { - to_bitField0_ |= 0x00000010; - } - result.aBoolean_ = aBoolean_; - if (((from_bitField0_ & 0x00000020) == 0x00000020)) { - to_bitField0_ |= 0x00000020; - } - result.anEnum_ = anEnum_; - if (((from_bitField0_ & 0x00000040) == 0x00000040)) { - to_bitField0_ |= 0x00000040; - } - result.someBytes_ = someBytes_; - if (((bitField0_ & 0x00000080) == 0x00000080)) { - anArray_ = anArray_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000080); - } - result.anArray_ = anArray_; - if (((from_bitField0_ & 0x00000100) == 0x00000100)) { - to_bitField0_ |= 0x00000080; - } - if (aNestedMessageBuilder_ == null) { - result.aNestedMessage_ = aNestedMessage_; - } else { - result.aNestedMessage_ = aNestedMessageBuilder_.build(); - } - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.sonar.core.test.Test.Fake) { - return mergeFrom((org.sonar.core.test.Test.Fake)other); - } else { - super.mergeFrom(other); - return this; + result.line_ = line_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.sonar.core.test.Test.Fake) { + return mergeFrom((org.sonar.core.test.Test.Fake)other); + } else { + super.mergeFrom(other); + return this; } } public Builder mergeFrom(org.sonar.core.test.Test.Fake other) { if (other == org.sonar.core.test.Test.Fake.getDefaultInstance()) return this; - if (other.hasAString()) { + if (other.hasLabel()) { bitField0_ |= 0x00000001; - aString_ = other.aString_; - onChanged(); - } - if (other.hasAnInt()) { - setAnInt(other.getAnInt()); - } - if (other.hasALong()) { - setALong(other.getALong()); - } - if (other.hasADouble()) { - setADouble(other.getADouble()); - } - if (other.hasABoolean()) { - setABoolean(other.getABoolean()); - } - if (other.hasAnEnum()) { - setAnEnum(other.getAnEnum()); - } - if (other.hasSomeBytes()) { - setSomeBytes(other.getSomeBytes()); - } - if (!other.anArray_.isEmpty()) { - if (anArray_.isEmpty()) { - anArray_ = other.anArray_; - bitField0_ = (bitField0_ & ~0x00000080); - } else { - ensureAnArrayIsMutable(); - anArray_.addAll(other.anArray_); - } + label_ = other.label_; onChanged(); } - if (other.hasANestedMessage()) { - mergeANestedMessage(other.getANestedMessage()); + if (other.hasLine()) { + setLine(other.getLine()); } this.mergeUnknownFields(other.getUnknownFields()); return this; @@ -933,24 +534,24 @@ public final class Test { } private int bitField0_; - private java.lang.Object aString_ = ""; + private java.lang.Object label_ = ""; /** - * optional string aString = 1; + * optional string label = 1; */ - public boolean hasAString() { + public boolean hasLabel() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * optional string aString = 1; + * optional string label = 1; */ - public java.lang.String getAString() { - java.lang.Object ref = aString_; + public java.lang.String getLabel() { + java.lang.Object ref = label_; if (!(ref instanceof java.lang.String)) { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); if (bs.isValidUtf8()) { - aString_ = s; + label_ = s; } return s; } else { @@ -958,477 +559,2050 @@ public final class Test { } } /** - * optional string aString = 1; + * optional string label = 1; */ public com.google.protobuf.ByteString - getAStringBytes() { - java.lang.Object ref = aString_; + getLabelBytes() { + java.lang.Object ref = label_; if (ref instanceof String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); - aString_ = b; + label_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } /** - * optional string aString = 1; + * optional string label = 1; */ - public Builder setAString( + public Builder setLabel( java.lang.String value) { if (value == null) { throw new NullPointerException(); } bitField0_ |= 0x00000001; - aString_ = value; + label_ = value; onChanged(); return this; } /** - * optional string aString = 1; + * optional string label = 1; */ - public Builder clearAString() { + public Builder clearLabel() { bitField0_ = (bitField0_ & ~0x00000001); - aString_ = getDefaultInstance().getAString(); + label_ = getDefaultInstance().getLabel(); onChanged(); return this; } /** - * optional string aString = 1; + * optional string label = 1; */ - public Builder setAStringBytes( + public Builder setLabelBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } bitField0_ |= 0x00000001; - aString_ = value; + label_ = value; + onChanged(); + return this; + } + + private int line_ ; + /** + * optional int32 line = 2; + */ + public boolean hasLine() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional int32 line = 2; + */ + public int getLine() { + return line_; + } + /** + * optional int32 line = 2; + */ + public Builder setLine(int value) { + bitField0_ |= 0x00000002; + line_ = value; onChanged(); return this; } + /** + * optional int32 line = 2; + */ + public Builder clearLine() { + bitField0_ = (bitField0_ & ~0x00000002); + line_ = 0; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:Fake) + } + + static { + defaultInstance = new Fake(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:Fake) + } + + public interface JsonTestOrBuilder extends + // @@protoc_insertion_point(interface_extends:JsonTest) + com.google.protobuf.MessageOrBuilder { + + /** + * optional string stringField = 1; + */ + boolean hasStringField(); + /** + * optional string stringField = 1; + */ + java.lang.String getStringField(); + /** + * optional string stringField = 1; + */ + com.google.protobuf.ByteString + getStringFieldBytes(); + + /** + * optional int32 intField = 2; + */ + boolean hasIntField(); + /** + * optional int32 intField = 2; + */ + int getIntField(); + + /** + * optional int64 longField = 3; + */ + boolean hasLongField(); + /** + * optional int64 longField = 3; + */ + long getLongField(); + + /** + * optional double doubleField = 4; + */ + boolean hasDoubleField(); + /** + * optional double doubleField = 4; + */ + double getDoubleField(); + + /** + * optional bool booleanField = 5; + */ + boolean hasBooleanField(); + /** + * optional bool booleanField = 5; + */ + boolean getBooleanField(); + + /** + * optional .FakeEnum enumField = 6; + */ + boolean hasEnumField(); + /** + * optional .FakeEnum enumField = 6; + */ + org.sonar.core.test.Test.FakeEnum getEnumField(); + + /** + * optional bytes bytesField = 7; + */ + boolean hasBytesField(); + /** + * optional bytes bytesField = 7; + */ + com.google.protobuf.ByteString getBytesField(); + + /** + * optional .NestedJsonTest nested = 8; + */ + boolean hasNested(); + /** + * optional .NestedJsonTest nested = 8; + */ + org.sonar.core.test.Test.NestedJsonTest getNested(); + /** + * optional .NestedJsonTest nested = 8; + */ + org.sonar.core.test.Test.NestedJsonTestOrBuilder getNestedOrBuilder(); + + /** + * repeated string anArray = 9; + */ + com.google.protobuf.ProtocolStringList + getAnArrayList(); + /** + * repeated string anArray = 9; + */ + int getAnArrayCount(); + /** + * repeated string anArray = 9; + */ + java.lang.String getAnArray(int index); + /** + * repeated string anArray = 9; + */ + com.google.protobuf.ByteString + getAnArrayBytes(int index); + } + /** + * Protobuf type {@code JsonTest} + */ + public static final class JsonTest extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:JsonTest) + JsonTestOrBuilder { + // Use JsonTest.newBuilder() to construct. + private JsonTest(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private JsonTest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final JsonTest defaultInstance; + public static JsonTest getDefaultInstance() { + return defaultInstance; + } + + public JsonTest getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private JsonTest( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.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 10: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000001; + stringField_ = bs; + break; + } + case 16: { + bitField0_ |= 0x00000002; + intField_ = input.readInt32(); + break; + } + case 24: { + bitField0_ |= 0x00000004; + longField_ = input.readInt64(); + break; + } + case 33: { + bitField0_ |= 0x00000008; + doubleField_ = input.readDouble(); + break; + } + case 40: { + bitField0_ |= 0x00000010; + booleanField_ = input.readBool(); + break; + } + case 48: { + int rawValue = input.readEnum(); + org.sonar.core.test.Test.FakeEnum value = org.sonar.core.test.Test.FakeEnum.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(6, rawValue); + } else { + bitField0_ |= 0x00000020; + enumField_ = value; + } + break; + } + case 58: { + bitField0_ |= 0x00000040; + bytesField_ = input.readBytes(); + break; + } + case 66: { + org.sonar.core.test.Test.NestedJsonTest.Builder subBuilder = null; + if (((bitField0_ & 0x00000080) == 0x00000080)) { + subBuilder = nested_.toBuilder(); + } + nested_ = input.readMessage(org.sonar.core.test.Test.NestedJsonTest.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(nested_); + nested_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000080; + break; + } + case 74: { + com.google.protobuf.ByteString bs = input.readBytes(); + if (!((mutable_bitField0_ & 0x00000100) == 0x00000100)) { + anArray_ = new com.google.protobuf.LazyStringArrayList(); + mutable_bitField0_ |= 0x00000100; + } + anArray_.add(bs); + 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 { + if (((mutable_bitField0_ & 0x00000100) == 0x00000100)) { + anArray_ = anArray_.getUnmodifiableView(); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.core.test.Test.internal_static_JsonTest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.core.test.Test.internal_static_JsonTest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.core.test.Test.JsonTest.class, org.sonar.core.test.Test.JsonTest.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public JsonTest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new JsonTest(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + public static final int STRINGFIELD_FIELD_NUMBER = 1; + private java.lang.Object stringField_; + /** + * optional string stringField = 1; + */ + public boolean hasStringField() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string stringField = 1; + */ + public java.lang.String getStringField() { + java.lang.Object ref = stringField_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + stringField_ = s; + } + return s; + } + } + /** + * optional string stringField = 1; + */ + public com.google.protobuf.ByteString + getStringFieldBytes() { + java.lang.Object ref = stringField_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + stringField_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int INTFIELD_FIELD_NUMBER = 2; + private int intField_; + /** + * optional int32 intField = 2; + */ + public boolean hasIntField() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional int32 intField = 2; + */ + public int getIntField() { + return intField_; + } + + public static final int LONGFIELD_FIELD_NUMBER = 3; + private long longField_; + /** + * optional int64 longField = 3; + */ + public boolean hasLongField() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional int64 longField = 3; + */ + public long getLongField() { + return longField_; + } + + public static final int DOUBLEFIELD_FIELD_NUMBER = 4; + private double doubleField_; + /** + * optional double doubleField = 4; + */ + public boolean hasDoubleField() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional double doubleField = 4; + */ + public double getDoubleField() { + return doubleField_; + } + + public static final int BOOLEANFIELD_FIELD_NUMBER = 5; + private boolean booleanField_; + /** + * optional bool booleanField = 5; + */ + public boolean hasBooleanField() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional bool booleanField = 5; + */ + public boolean getBooleanField() { + return booleanField_; + } + + public static final int ENUMFIELD_FIELD_NUMBER = 6; + private org.sonar.core.test.Test.FakeEnum enumField_; + /** + * optional .FakeEnum enumField = 6; + */ + public boolean hasEnumField() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional .FakeEnum enumField = 6; + */ + public org.sonar.core.test.Test.FakeEnum getEnumField() { + return enumField_; + } + + public static final int BYTESFIELD_FIELD_NUMBER = 7; + private com.google.protobuf.ByteString bytesField_; + /** + * optional bytes bytesField = 7; + */ + public boolean hasBytesField() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional bytes bytesField = 7; + */ + public com.google.protobuf.ByteString getBytesField() { + return bytesField_; + } + + public static final int NESTED_FIELD_NUMBER = 8; + private org.sonar.core.test.Test.NestedJsonTest nested_; + /** + * optional .NestedJsonTest nested = 8; + */ + public boolean hasNested() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional .NestedJsonTest nested = 8; + */ + public org.sonar.core.test.Test.NestedJsonTest getNested() { + return nested_; + } + /** + * optional .NestedJsonTest nested = 8; + */ + public org.sonar.core.test.Test.NestedJsonTestOrBuilder getNestedOrBuilder() { + return nested_; + } + + public static final int ANARRAY_FIELD_NUMBER = 9; + private com.google.protobuf.LazyStringList anArray_; + /** + * repeated string anArray = 9; + */ + public com.google.protobuf.ProtocolStringList + getAnArrayList() { + return anArray_; + } + /** + * repeated string anArray = 9; + */ + public int getAnArrayCount() { + return anArray_.size(); + } + /** + * repeated string anArray = 9; + */ + public java.lang.String getAnArray(int index) { + return anArray_.get(index); + } + /** + * repeated string anArray = 9; + */ + public com.google.protobuf.ByteString + getAnArrayBytes(int index) { + return anArray_.getByteString(index); + } + + private void initFields() { + stringField_ = ""; + intField_ = 0; + longField_ = 0L; + doubleField_ = 0D; + booleanField_ = false; + enumField_ = org.sonar.core.test.Test.FakeEnum.BLUE; + bytesField_ = com.google.protobuf.ByteString.EMPTY; + nested_ = org.sonar.core.test.Test.NestedJsonTest.getDefaultInstance(); + anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + } + 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(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBytes(1, getStringFieldBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeInt32(2, intField_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeInt64(3, longField_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeDouble(4, doubleField_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeBool(5, booleanField_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + output.writeEnum(6, enumField_.getNumber()); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeBytes(7, bytesField_); + } + if (((bitField0_ & 0x00000080) == 0x00000080)) { + output.writeMessage(8, nested_); + } + for (int i = 0; i < anArray_.size(); i++) { + output.writeBytes(9, anArray_.getByteString(i)); + } + 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 += com.google.protobuf.CodedOutputStream + .computeBytesSize(1, getStringFieldBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(2, intField_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(3, longField_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeDoubleSize(4, doubleField_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(5, booleanField_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(6, enumField_.getNumber()); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(7, bytesField_); + } + if (((bitField0_ & 0x00000080) == 0x00000080)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(8, nested_); + } + { + int dataSize = 0; + for (int i = 0; i < anArray_.size(); i++) { + dataSize += com.google.protobuf.CodedOutputStream + .computeBytesSizeNoTag(anArray_.getByteString(i)); + } + size += dataSize; + size += 1 * getAnArrayList().size(); + } + 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.sonar.core.test.Test.JsonTest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.core.test.Test.JsonTest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonTest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.core.test.Test.JsonTest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonTest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.core.test.Test.JsonTest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonTest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static org.sonar.core.test.Test.JsonTest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonTest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.core.test.Test.JsonTest 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.sonar.core.test.Test.JsonTest prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code JsonTest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:JsonTest) + org.sonar.core.test.Test.JsonTestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.core.test.Test.internal_static_JsonTest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.core.test.Test.internal_static_JsonTest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.core.test.Test.JsonTest.class, org.sonar.core.test.Test.JsonTest.Builder.class); + } + + // Construct using org.sonar.core.test.Test.JsonTest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getNestedFieldBuilder(); + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + stringField_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + intField_ = 0; + bitField0_ = (bitField0_ & ~0x00000002); + longField_ = 0L; + bitField0_ = (bitField0_ & ~0x00000004); + doubleField_ = 0D; + bitField0_ = (bitField0_ & ~0x00000008); + booleanField_ = false; + bitField0_ = (bitField0_ & ~0x00000010); + enumField_ = org.sonar.core.test.Test.FakeEnum.BLUE; + bitField0_ = (bitField0_ & ~0x00000020); + bytesField_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000040); + if (nestedBuilder_ == null) { + nested_ = org.sonar.core.test.Test.NestedJsonTest.getDefaultInstance(); + } else { + nestedBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000080); + anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000100); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.sonar.core.test.Test.internal_static_JsonTest_descriptor; + } + + public org.sonar.core.test.Test.JsonTest getDefaultInstanceForType() { + return org.sonar.core.test.Test.JsonTest.getDefaultInstance(); + } + + public org.sonar.core.test.Test.JsonTest build() { + org.sonar.core.test.Test.JsonTest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public org.sonar.core.test.Test.JsonTest buildPartial() { + org.sonar.core.test.Test.JsonTest result = new org.sonar.core.test.Test.JsonTest(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.stringField_ = stringField_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.intField_ = intField_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.longField_ = longField_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.doubleField_ = doubleField_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000010; + } + result.booleanField_ = booleanField_; + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + to_bitField0_ |= 0x00000020; + } + result.enumField_ = enumField_; + if (((from_bitField0_ & 0x00000040) == 0x00000040)) { + to_bitField0_ |= 0x00000040; + } + result.bytesField_ = bytesField_; + if (((from_bitField0_ & 0x00000080) == 0x00000080)) { + to_bitField0_ |= 0x00000080; + } + if (nestedBuilder_ == null) { + result.nested_ = nested_; + } else { + result.nested_ = nestedBuilder_.build(); + } + if (((bitField0_ & 0x00000100) == 0x00000100)) { + anArray_ = anArray_.getUnmodifiableView(); + bitField0_ = (bitField0_ & ~0x00000100); + } + result.anArray_ = anArray_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.sonar.core.test.Test.JsonTest) { + return mergeFrom((org.sonar.core.test.Test.JsonTest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.sonar.core.test.Test.JsonTest other) { + if (other == org.sonar.core.test.Test.JsonTest.getDefaultInstance()) return this; + if (other.hasStringField()) { + bitField0_ |= 0x00000001; + stringField_ = other.stringField_; + onChanged(); + } + if (other.hasIntField()) { + setIntField(other.getIntField()); + } + if (other.hasLongField()) { + setLongField(other.getLongField()); + } + if (other.hasDoubleField()) { + setDoubleField(other.getDoubleField()); + } + if (other.hasBooleanField()) { + setBooleanField(other.getBooleanField()); + } + if (other.hasEnumField()) { + setEnumField(other.getEnumField()); + } + if (other.hasBytesField()) { + setBytesField(other.getBytesField()); + } + if (other.hasNested()) { + mergeNested(other.getNested()); + } + if (!other.anArray_.isEmpty()) { + if (anArray_.isEmpty()) { + anArray_ = other.anArray_; + bitField0_ = (bitField0_ & ~0x00000100); + } else { + ensureAnArrayIsMutable(); + anArray_.addAll(other.anArray_); + } + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.sonar.core.test.Test.JsonTest parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.sonar.core.test.Test.JsonTest) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private java.lang.Object stringField_ = ""; + /** + * optional string stringField = 1; + */ + public boolean hasStringField() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string stringField = 1; + */ + public java.lang.String getStringField() { + java.lang.Object ref = stringField_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + stringField_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string stringField = 1; + */ + public com.google.protobuf.ByteString + getStringFieldBytes() { + java.lang.Object ref = stringField_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + stringField_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string stringField = 1; + */ + public Builder setStringField( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + stringField_ = value; + onChanged(); + return this; + } + /** + * optional string stringField = 1; + */ + public Builder clearStringField() { + bitField0_ = (bitField0_ & ~0x00000001); + stringField_ = getDefaultInstance().getStringField(); + onChanged(); + return this; + } + /** + * optional string stringField = 1; + */ + public Builder setStringFieldBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + stringField_ = value; + onChanged(); + return this; + } + + private int intField_ ; + /** + * optional int32 intField = 2; + */ + public boolean hasIntField() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional int32 intField = 2; + */ + public int getIntField() { + return intField_; + } + /** + * optional int32 intField = 2; + */ + public Builder setIntField(int value) { + bitField0_ |= 0x00000002; + intField_ = value; + onChanged(); + return this; + } + /** + * optional int32 intField = 2; + */ + public Builder clearIntField() { + bitField0_ = (bitField0_ & ~0x00000002); + intField_ = 0; + onChanged(); + return this; + } + + private long longField_ ; + /** + * optional int64 longField = 3; + */ + public boolean hasLongField() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional int64 longField = 3; + */ + public long getLongField() { + return longField_; + } + /** + * optional int64 longField = 3; + */ + public Builder setLongField(long value) { + bitField0_ |= 0x00000004; + longField_ = value; + onChanged(); + return this; + } + /** + * optional int64 longField = 3; + */ + public Builder clearLongField() { + bitField0_ = (bitField0_ & ~0x00000004); + longField_ = 0L; + onChanged(); + return this; + } + + private double doubleField_ ; + /** + * optional double doubleField = 4; + */ + public boolean hasDoubleField() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional double doubleField = 4; + */ + public double getDoubleField() { + return doubleField_; + } + /** + * optional double doubleField = 4; + */ + public Builder setDoubleField(double value) { + bitField0_ |= 0x00000008; + doubleField_ = value; + onChanged(); + return this; + } + /** + * optional double doubleField = 4; + */ + public Builder clearDoubleField() { + bitField0_ = (bitField0_ & ~0x00000008); + doubleField_ = 0D; + onChanged(); + return this; + } + + private boolean booleanField_ ; + /** + * optional bool booleanField = 5; + */ + public boolean hasBooleanField() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional bool booleanField = 5; + */ + public boolean getBooleanField() { + return booleanField_; + } + /** + * optional bool booleanField = 5; + */ + public Builder setBooleanField(boolean value) { + bitField0_ |= 0x00000010; + booleanField_ = value; + onChanged(); + return this; + } + /** + * optional bool booleanField = 5; + */ + public Builder clearBooleanField() { + bitField0_ = (bitField0_ & ~0x00000010); + booleanField_ = false; + onChanged(); + return this; + } + + private org.sonar.core.test.Test.FakeEnum enumField_ = org.sonar.core.test.Test.FakeEnum.BLUE; + /** + * optional .FakeEnum enumField = 6; + */ + public boolean hasEnumField() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional .FakeEnum enumField = 6; + */ + public org.sonar.core.test.Test.FakeEnum getEnumField() { + return enumField_; + } + /** + * optional .FakeEnum enumField = 6; + */ + public Builder setEnumField(org.sonar.core.test.Test.FakeEnum value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000020; + enumField_ = value; + onChanged(); + return this; + } + /** + * optional .FakeEnum enumField = 6; + */ + public Builder clearEnumField() { + bitField0_ = (bitField0_ & ~0x00000020); + enumField_ = org.sonar.core.test.Test.FakeEnum.BLUE; + onChanged(); + return this; + } + + private com.google.protobuf.ByteString bytesField_ = com.google.protobuf.ByteString.EMPTY; + /** + * optional bytes bytesField = 7; + */ + public boolean hasBytesField() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional bytes bytesField = 7; + */ + public com.google.protobuf.ByteString getBytesField() { + return bytesField_; + } + /** + * optional bytes bytesField = 7; + */ + public Builder setBytesField(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000040; + bytesField_ = value; + onChanged(); + return this; + } + /** + * optional bytes bytesField = 7; + */ + public Builder clearBytesField() { + bitField0_ = (bitField0_ & ~0x00000040); + bytesField_ = getDefaultInstance().getBytesField(); + onChanged(); + return this; + } + + private org.sonar.core.test.Test.NestedJsonTest nested_ = org.sonar.core.test.Test.NestedJsonTest.getDefaultInstance(); + private com.google.protobuf.SingleFieldBuilder< + org.sonar.core.test.Test.NestedJsonTest, org.sonar.core.test.Test.NestedJsonTest.Builder, org.sonar.core.test.Test.NestedJsonTestOrBuilder> nestedBuilder_; + /** + * optional .NestedJsonTest nested = 8; + */ + public boolean hasNested() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional .NestedJsonTest nested = 8; + */ + public org.sonar.core.test.Test.NestedJsonTest getNested() { + if (nestedBuilder_ == null) { + return nested_; + } else { + return nestedBuilder_.getMessage(); + } + } + /** + * optional .NestedJsonTest nested = 8; + */ + public Builder setNested(org.sonar.core.test.Test.NestedJsonTest value) { + if (nestedBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + nested_ = value; + onChanged(); + } else { + nestedBuilder_.setMessage(value); + } + bitField0_ |= 0x00000080; + return this; + } + /** + * optional .NestedJsonTest nested = 8; + */ + public Builder setNested( + org.sonar.core.test.Test.NestedJsonTest.Builder builderForValue) { + if (nestedBuilder_ == null) { + nested_ = builderForValue.build(); + onChanged(); + } else { + nestedBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000080; + return this; + } + /** + * optional .NestedJsonTest nested = 8; + */ + public Builder mergeNested(org.sonar.core.test.Test.NestedJsonTest value) { + if (nestedBuilder_ == null) { + if (((bitField0_ & 0x00000080) == 0x00000080) && + nested_ != org.sonar.core.test.Test.NestedJsonTest.getDefaultInstance()) { + nested_ = + org.sonar.core.test.Test.NestedJsonTest.newBuilder(nested_).mergeFrom(value).buildPartial(); + } else { + nested_ = value; + } + onChanged(); + } else { + nestedBuilder_.mergeFrom(value); + } + bitField0_ |= 0x00000080; + return this; + } + /** + * optional .NestedJsonTest nested = 8; + */ + public Builder clearNested() { + if (nestedBuilder_ == null) { + nested_ = org.sonar.core.test.Test.NestedJsonTest.getDefaultInstance(); + onChanged(); + } else { + nestedBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000080); + return this; + } + /** + * optional .NestedJsonTest nested = 8; + */ + public org.sonar.core.test.Test.NestedJsonTest.Builder getNestedBuilder() { + bitField0_ |= 0x00000080; + onChanged(); + return getNestedFieldBuilder().getBuilder(); + } + /** + * optional .NestedJsonTest nested = 8; + */ + public org.sonar.core.test.Test.NestedJsonTestOrBuilder getNestedOrBuilder() { + if (nestedBuilder_ != null) { + return nestedBuilder_.getMessageOrBuilder(); + } else { + return nested_; + } + } + /** + * optional .NestedJsonTest nested = 8; + */ + private com.google.protobuf.SingleFieldBuilder< + org.sonar.core.test.Test.NestedJsonTest, org.sonar.core.test.Test.NestedJsonTest.Builder, org.sonar.core.test.Test.NestedJsonTestOrBuilder> + getNestedFieldBuilder() { + if (nestedBuilder_ == null) { + nestedBuilder_ = new com.google.protobuf.SingleFieldBuilder< + org.sonar.core.test.Test.NestedJsonTest, org.sonar.core.test.Test.NestedJsonTest.Builder, org.sonar.core.test.Test.NestedJsonTestOrBuilder>( + getNested(), + getParentForChildren(), + isClean()); + nested_ = null; + } + return nestedBuilder_; + } + + private com.google.protobuf.LazyStringList anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + private void ensureAnArrayIsMutable() { + if (!((bitField0_ & 0x00000100) == 0x00000100)) { + anArray_ = new com.google.protobuf.LazyStringArrayList(anArray_); + bitField0_ |= 0x00000100; + } + } + /** + * repeated string anArray = 9; + */ + public com.google.protobuf.ProtocolStringList + getAnArrayList() { + return anArray_.getUnmodifiableView(); + } + /** + * repeated string anArray = 9; + */ + public int getAnArrayCount() { + return anArray_.size(); + } + /** + * repeated string anArray = 9; + */ + public java.lang.String getAnArray(int index) { + return anArray_.get(index); + } + /** + * repeated string anArray = 9; + */ + public com.google.protobuf.ByteString + getAnArrayBytes(int index) { + return anArray_.getByteString(index); + } + /** + * repeated string anArray = 9; + */ + public Builder setAnArray( + int index, java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureAnArrayIsMutable(); + anArray_.set(index, value); + onChanged(); + return this; + } + /** + * repeated string anArray = 9; + */ + public Builder addAnArray( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureAnArrayIsMutable(); + anArray_.add(value); + onChanged(); + return this; + } + /** + * repeated string anArray = 9; + */ + public Builder addAllAnArray( + java.lang.Iterable values) { + ensureAnArrayIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, anArray_); + onChanged(); + return this; + } + /** + * repeated string anArray = 9; + */ + public Builder clearAnArray() { + anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000100); + onChanged(); + return this; + } + /** + * repeated string anArray = 9; + */ + public Builder addAnArrayBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + ensureAnArrayIsMutable(); + anArray_.add(value); + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:JsonTest) + } + + static { + defaultInstance = new JsonTest(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:JsonTest) + } + + public interface JsonArrayTestOrBuilder extends + // @@protoc_insertion_point(interface_extends:JsonArrayTest) + com.google.protobuf.MessageOrBuilder { + + /** + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+     * naming convention. A boolean field is used
+     * to know if the array field is present.
+     * 
+ */ + boolean hasANullableArrayPresentIfEmpty(); + /** + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+     * naming convention. A boolean field is used
+     * to know if the array field is present.
+     * 
+ */ + boolean getANullableArrayPresentIfEmpty(); + + /** + * repeated string aNullableArray = 2; + */ + com.google.protobuf.ProtocolStringList + getANullableArrayList(); + /** + * repeated string aNullableArray = 2; + */ + int getANullableArrayCount(); + /** + * repeated string aNullableArray = 2; + */ + java.lang.String getANullableArray(int index); + /** + * repeated string aNullableArray = 2; + */ + com.google.protobuf.ByteString + getANullableArrayBytes(int index); + } + /** + * Protobuf type {@code JsonArrayTest} + */ + public static final class JsonArrayTest extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:JsonArrayTest) + JsonArrayTestOrBuilder { + // Use JsonArrayTest.newBuilder() to construct. + private JsonArrayTest(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private JsonArrayTest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final JsonArrayTest defaultInstance; + public static JsonArrayTest getDefaultInstance() { + return defaultInstance; + } + + public JsonArrayTest getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private JsonArrayTest( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.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; + aNullableArrayPresentIfEmpty_ = input.readBool(); + break; + } + case 18: { + com.google.protobuf.ByteString bs = input.readBytes(); + if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { + aNullableArray_ = new com.google.protobuf.LazyStringArrayList(); + mutable_bitField0_ |= 0x00000002; + } + aNullableArray_.add(bs); + 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 { + if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { + aNullableArray_ = aNullableArray_.getUnmodifiableView(); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.core.test.Test.internal_static_JsonArrayTest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.core.test.Test.internal_static_JsonArrayTest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.core.test.Test.JsonArrayTest.class, org.sonar.core.test.Test.JsonArrayTest.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public JsonArrayTest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new JsonArrayTest(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + public static final int ANULLABLEARRAYPRESENTIFEMPTY_FIELD_NUMBER = 1; + private boolean aNullableArrayPresentIfEmpty_; + /** + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+     * naming convention. A boolean field is used
+     * to know if the array field is present.
+     * 
+ */ + public boolean hasANullableArrayPresentIfEmpty() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+     * naming convention. A boolean field is used
+     * to know if the array field is present.
+     * 
+ */ + public boolean getANullableArrayPresentIfEmpty() { + return aNullableArrayPresentIfEmpty_; + } + + public static final int ANULLABLEARRAY_FIELD_NUMBER = 2; + private com.google.protobuf.LazyStringList aNullableArray_; + /** + * repeated string aNullableArray = 2; + */ + public com.google.protobuf.ProtocolStringList + getANullableArrayList() { + return aNullableArray_; + } + /** + * repeated string aNullableArray = 2; + */ + public int getANullableArrayCount() { + return aNullableArray_.size(); + } + /** + * repeated string aNullableArray = 2; + */ + public java.lang.String getANullableArray(int index) { + return aNullableArray_.get(index); + } + /** + * repeated string aNullableArray = 2; + */ + public com.google.protobuf.ByteString + getANullableArrayBytes(int index) { + return aNullableArray_.getByteString(index); + } + + private void initFields() { + aNullableArrayPresentIfEmpty_ = false; + aNullableArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + } + 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(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBool(1, aNullableArrayPresentIfEmpty_); + } + for (int i = 0; i < aNullableArray_.size(); i++) { + output.writeBytes(2, aNullableArray_.getByteString(i)); + } + 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 += com.google.protobuf.CodedOutputStream + .computeBoolSize(1, aNullableArrayPresentIfEmpty_); + } + { + int dataSize = 0; + for (int i = 0; i < aNullableArray_.size(); i++) { + dataSize += com.google.protobuf.CodedOutputStream + .computeBytesSizeNoTag(aNullableArray_.getByteString(i)); + } + size += dataSize; + size += 1 * getANullableArrayList().size(); + } + 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.sonar.core.test.Test.JsonArrayTest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.core.test.Test.JsonArrayTest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonArrayTest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.core.test.Test.JsonArrayTest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonArrayTest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.core.test.Test.JsonArrayTest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonArrayTest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static org.sonar.core.test.Test.JsonArrayTest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static org.sonar.core.test.Test.JsonArrayTest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.core.test.Test.JsonArrayTest 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.sonar.core.test.Test.JsonArrayTest prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code JsonArrayTest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:JsonArrayTest) + org.sonar.core.test.Test.JsonArrayTestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.core.test.Test.internal_static_JsonArrayTest_descriptor; + } - private int anInt_ ; - /** - * optional int32 anInt = 2; - */ - public boolean hasAnInt() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional int32 anInt = 2; - */ - public int getAnInt() { - return anInt_; - } - /** - * optional int32 anInt = 2; - */ - public Builder setAnInt(int value) { - bitField0_ |= 0x00000002; - anInt_ = value; - onChanged(); - return this; + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.core.test.Test.internal_static_JsonArrayTest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.core.test.Test.JsonArrayTest.class, org.sonar.core.test.Test.JsonArrayTest.Builder.class); } - /** - * optional int32 anInt = 2; - */ - public Builder clearAnInt() { - bitField0_ = (bitField0_ & ~0x00000002); - anInt_ = 0; - onChanged(); - return this; + + // Construct using org.sonar.core.test.Test.JsonArrayTest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); } - private long aLong_ ; - /** - * optional int64 aLong = 3; - */ - public boolean hasALong() { - return ((bitField0_ & 0x00000004) == 0x00000004); + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); } - /** - * optional int64 aLong = 3; - */ - public long getALong() { - return aLong_; + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } } - /** - * optional int64 aLong = 3; - */ - public Builder setALong(long value) { - bitField0_ |= 0x00000004; - aLong_ = value; - onChanged(); - return this; + private static Builder create() { + return new Builder(); } - /** - * optional int64 aLong = 3; - */ - public Builder clearALong() { - bitField0_ = (bitField0_ & ~0x00000004); - aLong_ = 0L; - onChanged(); + + public Builder clear() { + super.clear(); + aNullableArrayPresentIfEmpty_ = false; + bitField0_ = (bitField0_ & ~0x00000001); + aNullableArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000002); return this; } - private double aDouble_ ; - /** - * optional double aDouble = 4; - */ - public boolean hasADouble() { - return ((bitField0_ & 0x00000008) == 0x00000008); - } - /** - * optional double aDouble = 4; - */ - public double getADouble() { - return aDouble_; + public Builder clone() { + return create().mergeFrom(buildPartial()); } - /** - * optional double aDouble = 4; - */ - public Builder setADouble(double value) { - bitField0_ |= 0x00000008; - aDouble_ = value; - onChanged(); - return this; + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.sonar.core.test.Test.internal_static_JsonArrayTest_descriptor; } - /** - * optional double aDouble = 4; - */ - public Builder clearADouble() { - bitField0_ = (bitField0_ & ~0x00000008); - aDouble_ = 0D; - onChanged(); - return this; + + public org.sonar.core.test.Test.JsonArrayTest getDefaultInstanceForType() { + return org.sonar.core.test.Test.JsonArrayTest.getDefaultInstance(); } - private boolean aBoolean_ ; - /** - * optional bool aBoolean = 5; - */ - public boolean hasABoolean() { - return ((bitField0_ & 0x00000010) == 0x00000010); + public org.sonar.core.test.Test.JsonArrayTest build() { + org.sonar.core.test.Test.JsonArrayTest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; } - /** - * optional bool aBoolean = 5; - */ - public boolean getABoolean() { - return aBoolean_; + + public org.sonar.core.test.Test.JsonArrayTest buildPartial() { + org.sonar.core.test.Test.JsonArrayTest result = new org.sonar.core.test.Test.JsonArrayTest(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.aNullableArrayPresentIfEmpty_ = aNullableArrayPresentIfEmpty_; + if (((bitField0_ & 0x00000002) == 0x00000002)) { + aNullableArray_ = aNullableArray_.getUnmodifiableView(); + bitField0_ = (bitField0_ & ~0x00000002); + } + result.aNullableArray_ = aNullableArray_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; } - /** - * optional bool aBoolean = 5; - */ - public Builder setABoolean(boolean value) { - bitField0_ |= 0x00000010; - aBoolean_ = value; - onChanged(); - return this; + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.sonar.core.test.Test.JsonArrayTest) { + return mergeFrom((org.sonar.core.test.Test.JsonArrayTest)other); + } else { + super.mergeFrom(other); + return this; + } } - /** - * optional bool aBoolean = 5; - */ - public Builder clearABoolean() { - bitField0_ = (bitField0_ & ~0x00000010); - aBoolean_ = false; - onChanged(); + + public Builder mergeFrom(org.sonar.core.test.Test.JsonArrayTest other) { + if (other == org.sonar.core.test.Test.JsonArrayTest.getDefaultInstance()) return this; + if (other.hasANullableArrayPresentIfEmpty()) { + setANullableArrayPresentIfEmpty(other.getANullableArrayPresentIfEmpty()); + } + if (!other.aNullableArray_.isEmpty()) { + if (aNullableArray_.isEmpty()) { + aNullableArray_ = other.aNullableArray_; + bitField0_ = (bitField0_ & ~0x00000002); + } else { + ensureANullableArrayIsMutable(); + aNullableArray_.addAll(other.aNullableArray_); + } + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); return this; } - private org.sonar.core.test.Test.FakeEnum anEnum_ = org.sonar.core.test.Test.FakeEnum.BLUE; - /** - * optional .FakeEnum anEnum = 6; - */ - public boolean hasAnEnum() { - return ((bitField0_ & 0x00000020) == 0x00000020); - } - /** - * optional .FakeEnum anEnum = 6; - */ - public org.sonar.core.test.Test.FakeEnum getAnEnum() { - return anEnum_; + public final boolean isInitialized() { + return true; } - /** - * optional .FakeEnum anEnum = 6; - */ - public Builder setAnEnum(org.sonar.core.test.Test.FakeEnum value) { - if (value == null) { - throw new NullPointerException(); + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.sonar.core.test.Test.JsonArrayTest parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.sonar.core.test.Test.JsonArrayTest) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } } - bitField0_ |= 0x00000020; - anEnum_ = value; - onChanged(); - return this; - } - /** - * optional .FakeEnum anEnum = 6; - */ - public Builder clearAnEnum() { - bitField0_ = (bitField0_ & ~0x00000020); - anEnum_ = org.sonar.core.test.Test.FakeEnum.BLUE; - onChanged(); return this; } + private int bitField0_; - private com.google.protobuf.ByteString someBytes_ = com.google.protobuf.ByteString.EMPTY; + private boolean aNullableArrayPresentIfEmpty_ ; /** - * optional bytes someBytes = 7; + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+       * naming convention. A boolean field is used
+       * to know if the array field is present.
+       * 
*/ - public boolean hasSomeBytes() { - return ((bitField0_ & 0x00000040) == 0x00000040); + public boolean hasANullableArrayPresentIfEmpty() { + return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * optional bytes someBytes = 7; + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+       * naming convention. A boolean field is used
+       * to know if the array field is present.
+       * 
*/ - public com.google.protobuf.ByteString getSomeBytes() { - return someBytes_; + public boolean getANullableArrayPresentIfEmpty() { + return aNullableArrayPresentIfEmpty_; } /** - * optional bytes someBytes = 7; + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+       * naming convention. A boolean field is used
+       * to know if the array field is present.
+       * 
*/ - public Builder setSomeBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000040; - someBytes_ = value; + public Builder setANullableArrayPresentIfEmpty(boolean value) { + bitField0_ |= 0x00000001; + aNullableArrayPresentIfEmpty_ = value; onChanged(); return this; } /** - * optional bytes someBytes = 7; + * optional bool aNullableArrayPresentIfEmpty = 1; + * + *
+       * naming convention. A boolean field is used
+       * to know if the array field is present.
+       * 
*/ - public Builder clearSomeBytes() { - bitField0_ = (bitField0_ & ~0x00000040); - someBytes_ = getDefaultInstance().getSomeBytes(); + public Builder clearANullableArrayPresentIfEmpty() { + bitField0_ = (bitField0_ & ~0x00000001); + aNullableArrayPresentIfEmpty_ = false; onChanged(); return this; } - private com.google.protobuf.LazyStringList anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureAnArrayIsMutable() { - if (!((bitField0_ & 0x00000080) == 0x00000080)) { - anArray_ = new com.google.protobuf.LazyStringArrayList(anArray_); - bitField0_ |= 0x00000080; + private com.google.protobuf.LazyStringList aNullableArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + private void ensureANullableArrayIsMutable() { + if (!((bitField0_ & 0x00000002) == 0x00000002)) { + aNullableArray_ = new com.google.protobuf.LazyStringArrayList(aNullableArray_); + bitField0_ |= 0x00000002; } } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ public com.google.protobuf.ProtocolStringList - getAnArrayList() { - return anArray_.getUnmodifiableView(); + getANullableArrayList() { + return aNullableArray_.getUnmodifiableView(); } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ - public int getAnArrayCount() { - return anArray_.size(); + public int getANullableArrayCount() { + return aNullableArray_.size(); } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ - public java.lang.String getAnArray(int index) { - return anArray_.get(index); + public java.lang.String getANullableArray(int index) { + return aNullableArray_.get(index); } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ public com.google.protobuf.ByteString - getAnArrayBytes(int index) { - return anArray_.getByteString(index); + getANullableArrayBytes(int index) { + return aNullableArray_.getByteString(index); } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ - public Builder setAnArray( + public Builder setANullableArray( int index, java.lang.String value) { if (value == null) { throw new NullPointerException(); } - ensureAnArrayIsMutable(); - anArray_.set(index, value); + ensureANullableArrayIsMutable(); + aNullableArray_.set(index, value); onChanged(); return this; } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ - public Builder addAnArray( + public Builder addANullableArray( java.lang.String value) { if (value == null) { throw new NullPointerException(); } - ensureAnArrayIsMutable(); - anArray_.add(value); + ensureANullableArrayIsMutable(); + aNullableArray_.add(value); onChanged(); return this; } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ - public Builder addAllAnArray( + public Builder addAllANullableArray( java.lang.Iterable values) { - ensureAnArrayIsMutable(); + ensureANullableArrayIsMutable(); com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, anArray_); + values, aNullableArray_); onChanged(); return this; } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ - public Builder clearAnArray() { - anArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000080); + public Builder clearANullableArray() { + aNullableArray_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000002); onChanged(); return this; } /** - * repeated string anArray = 8; + * repeated string aNullableArray = 2; */ - public Builder addAnArrayBytes( + public Builder addANullableArrayBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } - ensureAnArrayIsMutable(); - anArray_.add(value); + ensureANullableArrayIsMutable(); + aNullableArray_.add(value); onChanged(); return this; } - private org.sonar.core.test.Test.NestedFake aNestedMessage_ = org.sonar.core.test.Test.NestedFake.getDefaultInstance(); - private com.google.protobuf.SingleFieldBuilder< - org.sonar.core.test.Test.NestedFake, org.sonar.core.test.Test.NestedFake.Builder, org.sonar.core.test.Test.NestedFakeOrBuilder> aNestedMessageBuilder_; - /** - * optional .NestedFake aNestedMessage = 9; - */ - public boolean hasANestedMessage() { - return ((bitField0_ & 0x00000100) == 0x00000100); - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public org.sonar.core.test.Test.NestedFake getANestedMessage() { - if (aNestedMessageBuilder_ == null) { - return aNestedMessage_; - } else { - return aNestedMessageBuilder_.getMessage(); - } - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public Builder setANestedMessage(org.sonar.core.test.Test.NestedFake value) { - if (aNestedMessageBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - aNestedMessage_ = value; - onChanged(); - } else { - aNestedMessageBuilder_.setMessage(value); - } - bitField0_ |= 0x00000100; - return this; - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public Builder setANestedMessage( - org.sonar.core.test.Test.NestedFake.Builder builderForValue) { - if (aNestedMessageBuilder_ == null) { - aNestedMessage_ = builderForValue.build(); - onChanged(); - } else { - aNestedMessageBuilder_.setMessage(builderForValue.build()); - } - bitField0_ |= 0x00000100; - return this; - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public Builder mergeANestedMessage(org.sonar.core.test.Test.NestedFake value) { - if (aNestedMessageBuilder_ == null) { - if (((bitField0_ & 0x00000100) == 0x00000100) && - aNestedMessage_ != org.sonar.core.test.Test.NestedFake.getDefaultInstance()) { - aNestedMessage_ = - org.sonar.core.test.Test.NestedFake.newBuilder(aNestedMessage_).mergeFrom(value).buildPartial(); - } else { - aNestedMessage_ = value; - } - onChanged(); - } else { - aNestedMessageBuilder_.mergeFrom(value); - } - bitField0_ |= 0x00000100; - return this; - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public Builder clearANestedMessage() { - if (aNestedMessageBuilder_ == null) { - aNestedMessage_ = org.sonar.core.test.Test.NestedFake.getDefaultInstance(); - onChanged(); - } else { - aNestedMessageBuilder_.clear(); - } - bitField0_ = (bitField0_ & ~0x00000100); - return this; - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public org.sonar.core.test.Test.NestedFake.Builder getANestedMessageBuilder() { - bitField0_ |= 0x00000100; - onChanged(); - return getANestedMessageFieldBuilder().getBuilder(); - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - public org.sonar.core.test.Test.NestedFakeOrBuilder getANestedMessageOrBuilder() { - if (aNestedMessageBuilder_ != null) { - return aNestedMessageBuilder_.getMessageOrBuilder(); - } else { - return aNestedMessage_; - } - } - /** - * optional .NestedFake aNestedMessage = 9; - */ - private com.google.protobuf.SingleFieldBuilder< - org.sonar.core.test.Test.NestedFake, org.sonar.core.test.Test.NestedFake.Builder, org.sonar.core.test.Test.NestedFakeOrBuilder> - getANestedMessageFieldBuilder() { - if (aNestedMessageBuilder_ == null) { - aNestedMessageBuilder_ = new com.google.protobuf.SingleFieldBuilder< - org.sonar.core.test.Test.NestedFake, org.sonar.core.test.Test.NestedFake.Builder, org.sonar.core.test.Test.NestedFakeOrBuilder>( - getANestedMessage(), - getParentForChildren(), - isClean()); - aNestedMessage_ = null; - } - return aNestedMessageBuilder_; - } - - // @@protoc_insertion_point(builder_scope:Fake) + // @@protoc_insertion_point(builder_scope:JsonArrayTest) } static { - defaultInstance = new Fake(true); + defaultInstance = new JsonArrayTest(true); defaultInstance.initFields(); } - // @@protoc_insertion_point(class_scope:Fake) + // @@protoc_insertion_point(class_scope:JsonArrayTest) } - public interface NestedFakeOrBuilder extends - // @@protoc_insertion_point(interface_extends:NestedFake) + public interface NestedJsonTestOrBuilder extends + // @@protoc_insertion_point(interface_extends:NestedJsonTest) com.google.protobuf.MessageOrBuilder { /** @@ -1446,25 +2620,25 @@ public final class Test { getLabelBytes(); } /** - * Protobuf type {@code NestedFake} + * Protobuf type {@code NestedJsonTest} */ - public static final class NestedFake extends + public static final class NestedJsonTest extends com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:NestedFake) - NestedFakeOrBuilder { - // Use NestedFake.newBuilder() to construct. - private NestedFake(com.google.protobuf.GeneratedMessage.Builder builder) { + // @@protoc_insertion_point(message_implements:NestedJsonTest) + NestedJsonTestOrBuilder { + // Use NestedJsonTest.newBuilder() to construct. + private NestedJsonTest(com.google.protobuf.GeneratedMessage.Builder builder) { super(builder); this.unknownFields = builder.getUnknownFields(); } - private NestedFake(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + private NestedJsonTest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - private static final NestedFake defaultInstance; - public static NestedFake getDefaultInstance() { + private static final NestedJsonTest defaultInstance; + public static NestedJsonTest getDefaultInstance() { return defaultInstance; } - public NestedFake getDefaultInstanceForType() { + public NestedJsonTest getDefaultInstanceForType() { return defaultInstance; } @@ -1474,7 +2648,7 @@ public final class Test { getUnknownFields() { return this.unknownFields; } - private NestedFake( + private NestedJsonTest( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { @@ -1517,28 +2691,28 @@ public final class Test { } public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.sonar.core.test.Test.internal_static_NestedFake_descriptor; + return org.sonar.core.test.Test.internal_static_NestedJsonTest_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return org.sonar.core.test.Test.internal_static_NestedFake_fieldAccessorTable + return org.sonar.core.test.Test.internal_static_NestedJsonTest_fieldAccessorTable .ensureFieldAccessorsInitialized( - org.sonar.core.test.Test.NestedFake.class, org.sonar.core.test.Test.NestedFake.Builder.class); + org.sonar.core.test.Test.NestedJsonTest.class, org.sonar.core.test.Test.NestedJsonTest.Builder.class); } - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public NestedFake parsePartialFrom( + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public NestedJsonTest parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { - return new NestedFake(input, extensionRegistry); + return new NestedJsonTest(input, extensionRegistry); } }; @java.lang.Override - public com.google.protobuf.Parser getParserForType() { + public com.google.protobuf.Parser getParserForType() { return PARSER; } @@ -1629,53 +2803,53 @@ public final class Test { return super.writeReplace(); } - public static org.sonar.core.test.Test.NestedFake parseFrom( + public static org.sonar.core.test.Test.NestedJsonTest parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } - public static org.sonar.core.test.Test.NestedFake parseFrom( + public static org.sonar.core.test.Test.NestedJsonTest parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static org.sonar.core.test.Test.NestedFake parseFrom(byte[] data) + public static org.sonar.core.test.Test.NestedJsonTest parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } - public static org.sonar.core.test.Test.NestedFake parseFrom( + public static org.sonar.core.test.Test.NestedJsonTest parseFrom( byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static org.sonar.core.test.Test.NestedFake parseFrom(java.io.InputStream input) + public static org.sonar.core.test.Test.NestedJsonTest parseFrom(java.io.InputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } - public static org.sonar.core.test.Test.NestedFake parseFrom( + public static org.sonar.core.test.Test.NestedJsonTest parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return PARSER.parseFrom(input, extensionRegistry); } - public static org.sonar.core.test.Test.NestedFake parseDelimitedFrom(java.io.InputStream input) + public static org.sonar.core.test.Test.NestedJsonTest parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return PARSER.parseDelimitedFrom(input); } - public static org.sonar.core.test.Test.NestedFake parseDelimitedFrom( + public static org.sonar.core.test.Test.NestedJsonTest parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return PARSER.parseDelimitedFrom(input, extensionRegistry); } - public static org.sonar.core.test.Test.NestedFake parseFrom( + public static org.sonar.core.test.Test.NestedJsonTest parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } - public static org.sonar.core.test.Test.NestedFake parseFrom( + public static org.sonar.core.test.Test.NestedJsonTest parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { @@ -1684,7 +2858,7 @@ public final class Test { public static Builder newBuilder() { return Builder.create(); } public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(org.sonar.core.test.Test.NestedFake prototype) { + public static Builder newBuilder(org.sonar.core.test.Test.NestedJsonTest prototype) { return newBuilder().mergeFrom(prototype); } public Builder toBuilder() { return newBuilder(this); } @@ -1696,25 +2870,25 @@ public final class Test { return builder; } /** - * Protobuf type {@code NestedFake} + * Protobuf type {@code NestedJsonTest} */ public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:NestedFake) - org.sonar.core.test.Test.NestedFakeOrBuilder { + // @@protoc_insertion_point(builder_implements:NestedJsonTest) + org.sonar.core.test.Test.NestedJsonTestOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.sonar.core.test.Test.internal_static_NestedFake_descriptor; + return org.sonar.core.test.Test.internal_static_NestedJsonTest_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return org.sonar.core.test.Test.internal_static_NestedFake_fieldAccessorTable + return org.sonar.core.test.Test.internal_static_NestedJsonTest_fieldAccessorTable .ensureFieldAccessorsInitialized( - org.sonar.core.test.Test.NestedFake.class, org.sonar.core.test.Test.NestedFake.Builder.class); + org.sonar.core.test.Test.NestedJsonTest.class, org.sonar.core.test.Test.NestedJsonTest.Builder.class); } - // Construct using org.sonar.core.test.Test.NestedFake.newBuilder() + // Construct using org.sonar.core.test.Test.NestedJsonTest.newBuilder() private Builder() { maybeForceBuilderInitialization(); } @@ -1745,23 +2919,23 @@ public final class Test { public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return org.sonar.core.test.Test.internal_static_NestedFake_descriptor; + return org.sonar.core.test.Test.internal_static_NestedJsonTest_descriptor; } - public org.sonar.core.test.Test.NestedFake getDefaultInstanceForType() { - return org.sonar.core.test.Test.NestedFake.getDefaultInstance(); + public org.sonar.core.test.Test.NestedJsonTest getDefaultInstanceForType() { + return org.sonar.core.test.Test.NestedJsonTest.getDefaultInstance(); } - public org.sonar.core.test.Test.NestedFake build() { - org.sonar.core.test.Test.NestedFake result = buildPartial(); + public org.sonar.core.test.Test.NestedJsonTest build() { + org.sonar.core.test.Test.NestedJsonTest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; } - public org.sonar.core.test.Test.NestedFake buildPartial() { - org.sonar.core.test.Test.NestedFake result = new org.sonar.core.test.Test.NestedFake(this); + public org.sonar.core.test.Test.NestedJsonTest buildPartial() { + org.sonar.core.test.Test.NestedJsonTest result = new org.sonar.core.test.Test.NestedJsonTest(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { @@ -1774,16 +2948,16 @@ public final class Test { } public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.sonar.core.test.Test.NestedFake) { - return mergeFrom((org.sonar.core.test.Test.NestedFake)other); + if (other instanceof org.sonar.core.test.Test.NestedJsonTest) { + return mergeFrom((org.sonar.core.test.Test.NestedJsonTest)other); } else { super.mergeFrom(other); return this; } } - public Builder mergeFrom(org.sonar.core.test.Test.NestedFake other) { - if (other == org.sonar.core.test.Test.NestedFake.getDefaultInstance()) return this; + public Builder mergeFrom(org.sonar.core.test.Test.NestedJsonTest other) { + if (other == org.sonar.core.test.Test.NestedJsonTest.getDefaultInstance()) return this; if (other.hasLabel()) { bitField0_ |= 0x00000001; label_ = other.label_; @@ -1801,11 +2975,11 @@ public final class Test { com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - org.sonar.core.test.Test.NestedFake parsedMessage = null; + org.sonar.core.test.Test.NestedJsonTest parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.sonar.core.test.Test.NestedFake) e.getUnfinishedMessage(); + parsedMessage = (org.sonar.core.test.Test.NestedJsonTest) e.getUnfinishedMessage(); throw e; } finally { if (parsedMessage != null) { @@ -1892,15 +3066,15 @@ public final class Test { return this; } - // @@protoc_insertion_point(builder_scope:NestedFake) + // @@protoc_insertion_point(builder_scope:NestedJsonTest) } static { - defaultInstance = new NestedFake(true); + defaultInstance = new NestedJsonTest(true); defaultInstance.initFields(); } - // @@protoc_insertion_point(class_scope:NestedFake) + // @@protoc_insertion_point(class_scope:NestedJsonTest) } private static final com.google.protobuf.Descriptors.Descriptor @@ -1909,10 +3083,20 @@ public final class Test { com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_Fake_fieldAccessorTable; private static final com.google.protobuf.Descriptors.Descriptor - internal_static_NestedFake_descriptor; + internal_static_JsonTest_descriptor; private static com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_NestedFake_fieldAccessorTable; + internal_static_JsonTest_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_JsonArrayTest_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_JsonArrayTest_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_NestedJsonTest_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_NestedJsonTest_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { @@ -1922,14 +3106,18 @@ public final class Test { descriptor; static { java.lang.String[] descriptorData = { - "\n\ntest.proto\"\274\001\n\004Fake\022\017\n\007aString\030\001 \001(\t\022\r" + - "\n\005anInt\030\002 \001(\005\022\r\n\005aLong\030\003 \001(\003\022\017\n\007aDouble\030" + - "\004 \001(\001\022\020\n\010aBoolean\030\005 \001(\010\022\031\n\006anEnum\030\006 \001(\0162" + - "\t.FakeEnum\022\021\n\tsomeBytes\030\007 \001(\014\022\017\n\007anArray" + - "\030\010 \003(\t\022#\n\016aNestedMessage\030\t \001(\0132\013.NestedF" + - "ake\"\033\n\nNestedFake\022\r\n\005label\030\001 \001(\t*(\n\010Fake" + - "Enum\022\010\n\004BLUE\020\000\022\007\n\003RED\020\001\022\t\n\005GREEN\020\002B\027\n\023or" + - "g.sonar.core.testH\001" + "\n\ntest.proto\"#\n\004Fake\022\r\n\005label\030\001 \001(\t\022\014\n\004l" + + "ine\030\002 \001(\005\"\323\001\n\010JsonTest\022\023\n\013stringField\030\001 " + + "\001(\t\022\020\n\010intField\030\002 \001(\005\022\021\n\tlongField\030\003 \001(\003" + + "\022\023\n\013doubleField\030\004 \001(\001\022\024\n\014booleanField\030\005 " + + "\001(\010\022\034\n\tenumField\030\006 \001(\0162\t.FakeEnum\022\022\n\nbyt" + + "esField\030\007 \001(\014\022\037\n\006nested\030\010 \001(\0132\017.NestedJs" + + "onTest\022\017\n\007anArray\030\t \003(\t\"M\n\rJsonArrayTest" + + "\022$\n\034aNullableArrayPresentIfEmpty\030\001 \001(\010\022\026" + + "\n\016aNullableArray\030\002 \003(\t\"\037\n\016NestedJsonTest" + + "\022\r\n\005label\030\001 \001(\t*(\n\010FakeEnum\022\010\n\004BLUE\020\000\022\007\n", + "\003RED\020\001\022\t\n\005GREEN\020\002B\027\n\023org.sonar.core.test" + + "H\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { @@ -1948,12 +3136,24 @@ public final class Test { internal_static_Fake_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_Fake_descriptor, - new java.lang.String[] { "AString", "AnInt", "ALong", "ADouble", "ABoolean", "AnEnum", "SomeBytes", "AnArray", "ANestedMessage", }); - internal_static_NestedFake_descriptor = + new java.lang.String[] { "Label", "Line", }); + internal_static_JsonTest_descriptor = getDescriptor().getMessageTypes().get(1); - internal_static_NestedFake_fieldAccessorTable = new + internal_static_JsonTest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_JsonTest_descriptor, + new java.lang.String[] { "StringField", "IntField", "LongField", "DoubleField", "BooleanField", "EnumField", "BytesField", "Nested", "AnArray", }); + internal_static_JsonArrayTest_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_JsonArrayTest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_JsonArrayTest_descriptor, + new java.lang.String[] { "ANullableArrayPresentIfEmpty", "ANullableArray", }); + internal_static_NestedJsonTest_descriptor = + getDescriptor().getMessageTypes().get(3); + internal_static_NestedJsonTest_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_NestedFake_descriptor, + internal_static_NestedJsonTest_descriptor, new java.lang.String[] { "Label", }); } diff --git a/sonar-core/src/test/java/org/sonar/core/util/ProtobufJsonFormatTest.java b/sonar-core/src/test/java/org/sonar/core/util/ProtobufJsonFormatTest.java index d81033e5fd8..19a4e09a176 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/ProtobufJsonFormatTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/ProtobufJsonFormatTest.java @@ -25,9 +25,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.text.JsonWriter; +import org.sonar.core.test.Test.JsonArrayTest; +import org.sonar.core.test.Test.JsonTest; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.core.util.ProtobufJsonFormat.toJson; public class ProtobufJsonFormatTest { @@ -35,49 +38,100 @@ public class ProtobufJsonFormatTest { public ExpectedException expectedException = ExpectedException.none(); @Test - public void convert_protobuf_to_json() throws Exception { - org.sonar.core.test.Test.Fake protobuf = org.sonar.core.test.Test.Fake.newBuilder() - .setAString("foo") - .setAnInt(10) - .setALong(100L) - .setABoolean(true) - .setADouble(3.14) - .setAnEnum(org.sonar.core.test.Test.FakeEnum.GREEN) + public void convert_protobuf_to_json() { + JsonTest protobuf = JsonTest.newBuilder() + .setStringField("foo") + .setIntField(10) + .setLongField(100L) + .setDoubleField(3.14) + .setBooleanField(true) + .setEnumField(org.sonar.core.test.Test.FakeEnum.GREEN) .addAllAnArray(asList("one", "two", "three")) - .setANestedMessage(org.sonar.core.test.Test.NestedFake.newBuilder().setLabel("bar").build()) + .setNested(org.sonar.core.test.Test.NestedJsonTest.newBuilder().setLabel("bar").build()) .build(); - StringWriter json = new StringWriter(); - JsonWriter jsonWriter = JsonWriter.of(json); - ProtobufJsonFormat.write(protobuf, jsonWriter); - - assertThat(json.toString()) - .isEqualTo("{\"aString\":\"foo\",\"anInt\":10,\"aLong\":100,\"aDouble\":3.14,\"aBoolean\":true,\"anEnum\":\"GREEN\",\"anArray\":[\"one\",\"two\",\"three\"],\"aNestedMessage\":{\"label\":\"bar\"}}"); + assertThat(toJson(protobuf)) + .isEqualTo( + "{\"stringField\":\"foo\",\"intField\":10,\"longField\":100,\"doubleField\":3.14,\"booleanField\":true,\"enumField\":\"GREEN\",\"nested\":{\"label\":\"bar\"},\"anArray\":[\"one\",\"two\",\"three\"]}"); } @Test - public void protobuf_bytes_field_can_not_be_converted_to_json() throws Exception { + public void protobuf_bytes_field_can_not_be_converted_to_json() { expectedException.expect(RuntimeException.class); - expectedException.expectMessage("JSON format does not support the binary field 'someBytes'"); + expectedException.expectMessage("JSON format does not support type 'BYTE_STRING' of field 'bytesField'"); - org.sonar.core.test.Test.Fake protobuf = org.sonar.core.test.Test.Fake.newBuilder() - .setSomeBytes(ByteString.copyFrom(new byte[]{2, 4})) + JsonTest protobuf = JsonTest.newBuilder() + .setBytesField(ByteString.copyFrom(new byte[]{2, 4})) .build(); ProtobufJsonFormat.write(protobuf, JsonWriter.of(new StringWriter())); } @Test - public void protobuf_empty_strings_are_not_output() throws Exception { - org.sonar.core.test.Test.Fake protobuf = org.sonar.core.test.Test.Fake.newBuilder().build(); + public void protobuf_absent_fields_are_not_output() { + JsonTest msg = JsonTest.newBuilder().build(); + + // fields are absent + assertThat(msg.hasStringField()).isFalse(); + assertThat(msg.hasIntField()).isFalse(); + + // the repeated field "anArray" is always present. This is the standard behavior of protobuf. It + // does not make the difference between null and empty arrays. + assertThat(toJson(msg)).isEqualTo("{\"anArray\":[]}"); + } + + @Test + public void protobuf_present_and_empty_string_field_is_output() { + JsonTest msg = JsonTest.newBuilder().setStringField("").build(); + + // field is present + assertThat(msg.hasStringField()).isTrue(); + assertThat(msg.getStringField()).isEqualTo(""); + + assertThat(toJson(msg)).contains("\"stringField\":\"\""); + } + + + @Test + public void protobuf_empty_array_marked_as_present_is_output() { + JsonArrayTest msg = JsonArrayTest.newBuilder() + .setANullableArrayPresentIfEmpty(true) + .build(); + + // repeated field "aNullableArray" is marked as present through the boolean field "aNullableArrayPresentIfEmpty" + assertThat(msg.hasANullableArrayPresentIfEmpty()).isTrue(); + assertThat(msg.getANullableArrayPresentIfEmpty()).isTrue(); + + // JSON contains the repeated field, but not the boolean marker field + assertThat(toJson(msg)).isEqualTo("{\"aNullableArray\":[]}"); + } + + @Test + public void protobuf_empty_array_marked_as_absent_is_not_output() { + JsonArrayTest msg = JsonArrayTest.newBuilder() + .setANullableArrayPresentIfEmpty(false) + .build(); + + // repeated field "aNullableArray" is marked as absent through the boolean field "aNullableArrayPresentIfEmpty" + assertThat(msg.hasANullableArrayPresentIfEmpty()).isTrue(); + assertThat(msg.getANullableArrayPresentIfEmpty()).isFalse(); + + // JSON does not contain the array nor the boolean marker + assertThat(toJson(msg)).isEqualTo("{}"); + } + + @Test + public void protobuf_non_empty_array_is_output_even_if_not_marked_as_present() { + JsonArrayTest msg = JsonArrayTest.newBuilder() + .addANullableArray("foo") + .build(); - // field is not set but value is "", not null - assertThat(protobuf.hasAString()).isFalse(); - assertThat(protobuf.getAString()).isEqualTo(""); + // repeated field "aNullableArray" is present, but the boolean marker "aNullableArrayPresentIfEmpty" + // is not set. + assertThat(msg.hasANullableArrayPresentIfEmpty()).isFalse(); + assertThat(msg.getANullableArrayPresentIfEmpty()).isFalse(); - StringWriter json = new StringWriter(); - JsonWriter jsonWriter = JsonWriter.of(json); - ProtobufJsonFormat.write(protobuf, jsonWriter); - assertThat(json.toString()).isEqualTo("{}"); + // JSON contains the array but not the boolean marker + assertThat(toJson(msg)).isEqualTo("{\"aNullableArray\":[\"foo\"]}"); } } diff --git a/sonar-core/src/test/java/org/sonar/core/util/ProtobufTest.java b/sonar-core/src/test/java/org/sonar/core/util/ProtobufTest.java index d0e0d603a5c..493da413789 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/ProtobufTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/ProtobufTest.java @@ -84,17 +84,17 @@ public class ProtobufTest { public void write_and_read_streams() throws Exception { File file = temp.newFile(); - Fake item1 = Fake.newBuilder().setAString("one").setAnInt(1).build(); - Fake item2 = Fake.newBuilder().setAString("two").build(); + Fake item1 = Fake.newBuilder().setLabel("one").setLine(1).build(); + Fake item2 = Fake.newBuilder().setLabel("two").build(); Protobuf.writeStream(asList(item1, item2), file, false); CloseableIterator it = Protobuf.readStream(file, Fake.PARSER); Fake read = it.next(); - assertThat(read.getAString()).isEqualTo("one"); - assertThat(read.getAnInt()).isEqualTo(1); + assertThat(read.getLabel()).isEqualTo("one"); + assertThat(read.getLine()).isEqualTo(1); read = it.next(); - assertThat(read.getAString()).isEqualTo("two"); - assertThat(read.hasAnInt()).isFalse(); + assertThat(read.getLabel()).isEqualTo("two"); + assertThat(read.hasLine()).isFalse(); assertThat(it.hasNext()).isFalse(); } diff --git a/sonar-core/src/test/protobuf/test.proto b/sonar-core/src/test/protobuf/test.proto index fa51e06995b..2e1c09a00ae 100644 --- a/sonar-core/src/test/protobuf/test.proto +++ b/sonar-core/src/test/protobuf/test.proto @@ -24,15 +24,8 @@ option java_package = "org.sonar.core.test"; option optimize_for = SPEED; message Fake { - optional string aString = 1; - optional int32 anInt = 2; - optional int64 aLong = 3; - optional double aDouble = 4; - optional bool aBoolean = 5; - optional FakeEnum anEnum = 6; - optional bytes someBytes = 7; - repeated string anArray = 8; - optional NestedFake aNestedMessage = 9; + optional string label = 1; + optional int32 line = 2; } enum FakeEnum { @@ -41,6 +34,25 @@ enum FakeEnum { GREEN = 2; } -message NestedFake { +message JsonTest { + optional string stringField = 1; + optional int32 intField = 2; + optional int64 longField = 3; + optional double doubleField = 4; + optional bool booleanField = 5; + optional FakeEnum enumField = 6; + optional bytes bytesField = 7; + optional NestedJsonTest nested = 8; + repeated string anArray = 9; +} + +message JsonArrayTest { +// naming convention. A boolean field is used + // to know if the array field is present. + optional bool aNullableArrayPresentIfEmpty = 1; + repeated string aNullableArray = 2; +} + +message NestedJsonTest { optional string label = 1; } -- cgit v1.2.3