Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 21 matching lines...) Expand all
32 32
33 import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; 33 import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream;
34 import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException ; 34 import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException ;
35 import com.google.protobuf.Internal.BooleanList; 35 import com.google.protobuf.Internal.BooleanList;
36 import com.google.protobuf.Internal.DoubleList; 36 import com.google.protobuf.Internal.DoubleList;
37 import com.google.protobuf.Internal.FloatList; 37 import com.google.protobuf.Internal.FloatList;
38 import com.google.protobuf.Internal.IntList; 38 import com.google.protobuf.Internal.IntList;
39 import com.google.protobuf.Internal.LongList; 39 import com.google.protobuf.Internal.LongList;
40 import com.google.protobuf.Internal.ProtobufList; 40 import com.google.protobuf.Internal.ProtobufList;
41 import com.google.protobuf.WireFormat.FieldType; 41 import com.google.protobuf.WireFormat.FieldType;
42
43 import java.io.IOException; 42 import java.io.IOException;
44 import java.io.InputStream; 43 import java.io.InputStream;
45 import java.io.ObjectStreamException; 44 import java.io.ObjectStreamException;
46 import java.io.Serializable; 45 import java.io.Serializable;
47 import java.lang.reflect.InvocationTargetException; 46 import java.lang.reflect.InvocationTargetException;
48 import java.lang.reflect.Method; 47 import java.lang.reflect.Method;
49 import java.util.ArrayList; 48 import java.util.ArrayList;
50 import java.util.Collections; 49 import java.util.Collections;
51 import java.util.Iterator; 50 import java.util.Iterator;
52 import java.util.List; 51 import java.util.List;
53 import java.util.Map; 52 import java.util.Map;
54 53
55 /** 54 /**
56 * Lite version of {@link GeneratedMessage}. 55 * Lite version of {@link GeneratedMessage}.
57 * 56 *
58 * @author kenton@google.com Kenton Varda 57 * @author kenton@google.com Kenton Varda
59 */ 58 */
60 public abstract class GeneratedMessageLite< 59 public abstract class GeneratedMessageLite<
61 MessageType extends GeneratedMessageLite<MessageType, BuilderType>, 60 MessageType extends GeneratedMessageLite<MessageType, BuilderType>,
62 BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> 61 BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>>
63 extends AbstractMessageLite<MessageType, BuilderType> { 62 extends AbstractMessageLite<MessageType, BuilderType> {
64 63
65 /** For use by generated code only. Lazily initialized to reduce allocations. */ 64 /** For use by generated code only. Lazily initialized to reduce allocations. */
66 protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultIn stance(); 65 protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultIn stance();
67 66
68 /** For use by generated code only. */ 67 /** For use by generated code only. */
69 protected int memoizedSerializedSize = -1; 68 protected int memoizedSerializedSize = -1;
70 69
71 @Override 70 @Override
72 @SuppressWarnings("unchecked") // Guaranteed by runtime. 71 @SuppressWarnings("unchecked") // Guaranteed by runtime.
73 public final Parser<MessageType> getParserForType() { 72 public final Parser<MessageType> getParserForType() {
74 return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER); 73 return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER);
75 } 74 }
76 75
77 @Override 76 @Override
78 @SuppressWarnings("unchecked") // Guaranteed by runtime. 77 @SuppressWarnings("unchecked") // Guaranteed by runtime.
79 public final MessageType getDefaultInstanceForType() { 78 public final MessageType getDefaultInstanceForType() {
80 return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE); 79 return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE);
(...skipping 25 matching lines...) Expand all
106 @SuppressWarnings("unchecked") // Guaranteed by runtime 105 @SuppressWarnings("unchecked") // Guaranteed by runtime
107 @Override 106 @Override
108 public int hashCode() { 107 public int hashCode() {
109 if (memoizedHashCode == 0) { 108 if (memoizedHashCode == 0) {
110 HashCodeVisitor visitor = new HashCodeVisitor(); 109 HashCodeVisitor visitor = new HashCodeVisitor();
111 visit(visitor, (MessageType) this); 110 visit(visitor, (MessageType) this);
112 memoizedHashCode = visitor.hashCode; 111 memoizedHashCode = visitor.hashCode;
113 } 112 }
114 return memoizedHashCode; 113 return memoizedHashCode;
115 } 114 }
116 115
117 @SuppressWarnings("unchecked") // Guaranteed by runtime 116 @SuppressWarnings("unchecked") // Guaranteed by runtime
118 int hashCode(HashCodeVisitor visitor) { 117 int hashCode(HashCodeVisitor visitor) {
119 if (memoizedHashCode == 0) { 118 if (memoizedHashCode == 0) {
120 int inProgressHashCode = visitor.hashCode; 119 int inProgressHashCode = visitor.hashCode;
121 visitor.hashCode = 0; 120 visitor.hashCode = 0;
122 visit(visitor, (MessageType) this); 121 visit(visitor, (MessageType) this);
123 memoizedHashCode = visitor.hashCode; 122 memoizedHashCode = visitor.hashCode;
124 visitor.hashCode = inProgressHashCode; 123 visitor.hashCode = inProgressHashCode;
125 } 124 }
126 return memoizedHashCode; 125 return memoizedHashCode;
127 } 126 }
128 127
129 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime 128 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime
130 @Override 129 @Override
131 public boolean equals(Object other) { 130 public boolean equals(Object other) {
132 if (this == other) { 131 if (this == other) {
133 return true; 132 return true;
134 } 133 }
135 134
136 if (!getDefaultInstanceForType().getClass().isInstance(other)) { 135 if (!getDefaultInstanceForType().getClass().isInstance(other)) {
137 return false; 136 return false;
138 } 137 }
139 138
140 try { 139 try {
141 visit(EqualsVisitor.INSTANCE, (MessageType) other); 140 visit(EqualsVisitor.INSTANCE, (MessageType) other);
142 } catch (NotEqualsException e) { 141 } catch (NotEqualsException e) {
143 return false; 142 return false;
144 } 143 }
145 return true; 144 return true;
146 } 145 }
147 146
148 /** 147 /**
149 * Same as {@link #equals(Object)} but throws {@code NotEqualsException}. 148 * Same as {@link #equals(Object)} but throws {@code NotEqualsException}.
150 */ 149 */
151 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime 150 @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime
152 boolean equals(EqualsVisitor visitor, MessageLite other) { 151 boolean equals(EqualsVisitor visitor, MessageLite other) {
153 if (this == other) { 152 if (this == other) {
154 return true; 153 return true;
155 } 154 }
156 155
157 if (!getDefaultInstanceForType().getClass().isInstance(other)) { 156 if (!getDefaultInstanceForType().getClass().isInstance(other)) {
158 return false; 157 return false;
159 } 158 }
160 159
161 visit(visitor, (MessageType) other); 160 visit(visitor, (MessageType) other);
162 return true; 161 return true;
163 } 162 }
164 163
165 // The general strategy for unknown fields is to use an UnknownFieldSetLite th at is treated as 164 // The general strategy for unknown fields is to use an UnknownFieldSetLite th at is treated as
166 // mutable during the parsing constructor and immutable after. This allows us to avoid 165 // mutable during the parsing constructor and immutable after. This allows us to avoid
167 // any unnecessary intermediary allocations while reducing the generated code size. 166 // any unnecessary intermediary allocations while reducing the generated code size.
168 167
169 /** 168 /**
170 * Lazily initializes unknown fields. 169 * Lazily initializes unknown fields.
171 */ 170 */
172 private final void ensureUnknownFieldsInitialized() { 171 private final void ensureUnknownFieldsInitialized() {
173 if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { 172 if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) {
174 unknownFields = UnknownFieldSetLite.newInstance(); 173 unknownFields = UnknownFieldSetLite.newInstance();
175 } 174 }
176 } 175 }
177 176
178 /** 177 /**
179 * Called by subclasses to parse an unknown field. For use by generated code o nly. 178 * Called by subclasses to parse an unknown field. For use by generated code o nly.
180 * 179 *
181 * @return {@code true} unless the tag is an end-group tag. 180 * @return {@code true} unless the tag is an end-group tag.
182 */ 181 */
183 protected boolean parseUnknownField(int tag, CodedInputStream input) throws IO Exception { 182 protected boolean parseUnknownField(int tag, CodedInputStream input) throws IO Exception {
184 // This will avoid the allocation of unknown fields when a group tag is enco untered. 183 // This will avoid the allocation of unknown fields when a group tag is enco untered.
185 if (WireFormat.getTagWireType(tag) == WireFormat.WIRETYPE_END_GROUP) { 184 if (WireFormat.getTagWireType(tag) == WireFormat.WIRETYPE_END_GROUP) {
186 return false; 185 return false;
187 } 186 }
188 187
189 ensureUnknownFieldsInitialized(); 188 ensureUnknownFieldsInitialized();
190 return unknownFields.mergeFieldFrom(tag, input); 189 return unknownFields.mergeFieldFrom(tag, input);
191 } 190 }
192 191
193 /** 192 /**
194 * Called by subclasses to parse an unknown field. For use by generated code o nly. 193 * Called by subclasses to parse an unknown field. For use by generated code o nly.
195 */ 194 */
196 protected void mergeVarintField(int tag, int value) { 195 protected void mergeVarintField(int tag, int value) {
197 ensureUnknownFieldsInitialized(); 196 ensureUnknownFieldsInitialized();
198 unknownFields.mergeVarintField(tag, value); 197 unknownFields.mergeVarintField(tag, value);
199 } 198 }
200 199
201 /** 200 /**
202 * Called by subclasses to parse an unknown field. For use by generated code o nly. 201 * Called by subclasses to parse an unknown field. For use by generated code o nly.
203 */ 202 */
204 protected void mergeLengthDelimitedField(int fieldNumber, ByteString value) { 203 protected void mergeLengthDelimitedField(int fieldNumber, ByteString value) {
205 ensureUnknownFieldsInitialized(); 204 ensureUnknownFieldsInitialized();
206 unknownFields.mergeLengthDelimitedField(fieldNumber, value); 205 unknownFields.mergeLengthDelimitedField(fieldNumber, value);
207 } 206 }
208 207
209 /** 208 /**
210 * Called by subclasses to complete parsing. For use by generated code only. 209 * Called by subclasses to complete parsing. For use by generated code only.
211 */ 210 */
212 protected void makeImmutable() { 211 protected void makeImmutable() {
213 dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); 212 dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE);
214 213
215 unknownFields.makeImmutable(); 214 unknownFields.makeImmutable();
216 } 215 }
217 216
218 @Override 217 @Override
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 * Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. 284 * Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding.
286 */ 285 */
287 protected Object dynamicMethod(MethodToInvoke method) { 286 protected Object dynamicMethod(MethodToInvoke method) {
288 return dynamicMethod(method, null, null); 287 return dynamicMethod(method, null, null);
289 } 288 }
290 289
291 void visit(Visitor visitor, MessageType other) { 290 void visit(Visitor visitor, MessageType other) {
292 dynamicMethod(MethodToInvoke.VISIT, visitor, other); 291 dynamicMethod(MethodToInvoke.VISIT, visitor, other);
293 unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownField s); 292 unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownField s);
294 } 293 }
295 294
296 /** 295 /**
297 * Merge some unknown fields into the {@link UnknownFieldSetLite} for this 296 * Merge some unknown fields into the {@link UnknownFieldSetLite} for this
298 * message. 297 * message.
299 * 298 *
300 * <p>For use by generated code only. 299 * <p>For use by generated code only.
301 */ 300 */
302 protected final void mergeUnknownFields(UnknownFieldSetLite unknownFields) { 301 protected final void mergeUnknownFields(UnknownFieldSetLite unknownFields) {
303 this.unknownFields = UnknownFieldSetLite.mutableCopyOf(this.unknownFields, u nknownFields); 302 this.unknownFields = UnknownFieldSetLite.mutableCopyOf(this.unknownFields, u nknownFields);
304 } 303 }
305 304
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 (BuilderType) getDefaultInstanceForType().newBuilderForType(); 351 (BuilderType) getDefaultInstanceForType().newBuilderForType();
353 builder.mergeFrom(buildPartial()); 352 builder.mergeFrom(buildPartial());
354 return builder; 353 return builder;
355 } 354 }
356 355
357 @Override 356 @Override
358 public MessageType buildPartial() { 357 public MessageType buildPartial() {
359 if (isBuilt) { 358 if (isBuilt) {
360 return instance; 359 return instance;
361 } 360 }
362 361
363 instance.makeImmutable(); 362 instance.makeImmutable();
364 363
365 isBuilt = true; 364 isBuilt = true;
366 return instance; 365 return instance;
367 } 366 }
368 367
369 @Override 368 @Override
370 public final MessageType build() { 369 public final MessageType build() {
371 MessageType result = buildPartial(); 370 MessageType result = buildPartial();
372 if (!result.isInitialized()) { 371 if (!result.isInitialized()) {
373 throw newUninitializedMessageException(result); 372 throw newUninitializedMessageException(result);
374 } 373 }
375 return result; 374 return result;
376 } 375 }
377 376
378 @Override 377 @Override
379 protected BuilderType internalMergeFrom(MessageType message) { 378 protected BuilderType internalMergeFrom(MessageType message) {
380 return mergeFrom(message); 379 return mergeFrom(message);
381 } 380 }
382 381
383 /** All subclasses implement this. */ 382 /** All subclasses implement this. */
384 public BuilderType mergeFrom(MessageType message) { 383 public BuilderType mergeFrom(MessageType message) {
385 copyOnWrite(); 384 copyOnWrite();
386 instance.visit(MergeFromVisitor.INSTANCE, message); 385 instance.visit(MergeFromVisitor.INSTANCE, message);
387 return (BuilderType) this; 386 return (BuilderType) this;
388 } 387 }
389 388
390 @Override 389 @Override
391 public MessageType getDefaultInstanceForType() { 390 public MessageType getDefaultInstanceForType() {
392 return defaultInstance; 391 return defaultInstance;
393 } 392 }
394 393
395 @Override 394 @Override
396 public BuilderType mergeFrom( 395 public BuilderType mergeFrom(
397 com.google.protobuf.CodedInputStream input, 396 com.google.protobuf.CodedInputStream input,
398 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 397 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
399 throws IOException { 398 throws IOException {
400 copyOnWrite(); 399 copyOnWrite();
401 try { 400 try {
402 instance.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensio nRegistry); 401 instance.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensio nRegistry);
403 } catch (RuntimeException e) { 402 } catch (RuntimeException e) {
404 if (e.getCause() instanceof IOException) { 403 if (e.getCause() instanceof IOException) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 extensions = extensions.clone(); 458 extensions = extensions.clone();
460 } 459 }
461 extensions.mergeFrom(((ExtendableMessage) other).extensions); 460 extensions.mergeFrom(((ExtendableMessage) other).extensions);
462 } 461 }
463 462
464 @Override 463 @Override
465 final void visit(Visitor visitor, MessageType other) { 464 final void visit(Visitor visitor, MessageType other) {
466 super.visit(visitor, other); 465 super.visit(visitor, other);
467 extensions = visitor.visitExtensions(extensions, other.extensions); 466 extensions = visitor.visitExtensions(extensions, other.extensions);
468 } 467 }
469 468
470 /** 469 /**
471 * Parse an unknown field or an extension. For use by generated code only. 470 * Parse an unknown field or an extension. For use by generated code only.
472 * 471 *
473 * <p>For use by generated code only. 472 * <p>For use by generated code only.
474 * 473 *
475 * @return {@code true} unless the tag is an end-group tag. 474 * @return {@code true} unless the tag is an end-group tag.
476 */ 475 */
477 protected <MessageType extends MessageLite> boolean parseUnknownField( 476 protected <MessageType extends MessageLite> boolean parseUnknownField(
478 MessageType defaultInstance, 477 MessageType defaultInstance,
479 CodedInputStream input, 478 CodedInputStream input,
480 ExtensionRegistryLite extensionRegistry, 479 ExtensionRegistryLite extensionRegistry,
481 int tag) throws IOException { 480 int tag) throws IOException {
482 int wireType = WireFormat.getTagWireType(tag);
483 int fieldNumber = WireFormat.getTagFieldNumber(tag); 481 int fieldNumber = WireFormat.getTagFieldNumber(tag);
484 482
485 // TODO(dweis): How much bytecode would be saved by not requiring the gene rated code to 483 // TODO(dweis): How much bytecode would be saved by not requiring the gene rated code to
486 // provide the default instance? 484 // provide the default instance?
487 GeneratedExtension<MessageType, ?> extension = extensionRegistry.findLiteE xtensionByNumber( 485 GeneratedExtension<MessageType, ?> extension = extensionRegistry.findLiteE xtensionByNumber(
488 defaultInstance, fieldNumber); 486 defaultInstance, fieldNumber);
489 487
488 return parseExtension(input, extensionRegistry, extension, tag, fieldNumbe r);
489 }
490
491 private boolean parseExtension(
492 CodedInputStream input,
493 ExtensionRegistryLite extensionRegistry,
494 GeneratedExtension<?, ?> extension,
495 int tag,
496 int fieldNumber)
497 throws IOException {
498 int wireType = WireFormat.getTagWireType(tag);
490 boolean unknown = false; 499 boolean unknown = false;
491 boolean packed = false; 500 boolean packed = false;
492 if (extension == null) { 501 if (extension == null) {
493 unknown = true; // Unknown field. 502 unknown = true; // Unknown field.
494 } else if (wireType == FieldSet.getWireFormatForFieldType( 503 } else if (wireType == FieldSet.getWireFormatForFieldType(
495 extension.descriptor.getLiteType(), 504 extension.descriptor.getLiteType(),
496 false /* isPacked */)) { 505 false /* isPacked */)) {
497 packed = false; // Normal, unpacked value. 506 packed = false; // Normal, unpacked value.
498 } else if (extension.descriptor.isRepeated && 507 } else if (extension.descriptor.isRepeated &&
499 extension.descriptor.type.isPackable() && 508 extension.descriptor.type.isPackable() &&
500 wireType == FieldSet.getWireFormatForFieldType( 509 wireType == FieldSet.getWireFormatForFieldType(
501 extension.descriptor.getLiteType(), 510 extension.descriptor.getLiteType(),
502 true /* isPacked */)) { 511 true /* isPacked */)) {
503 packed = true; // Packed value. 512 packed = true; // Packed value.
504 } else { 513 } else {
505 unknown = true; // Wrong wire type. 514 unknown = true; // Wrong wire type.
506 } 515 }
507 516
508 if (unknown) { // Unknown field or wrong wire type. Skip. 517 if (unknown) { // Unknown field or wrong wire type. Skip.
509 return parseUnknownField(tag, input); 518 return parseUnknownField(tag, input);
510 } 519 }
511 520
512 if (packed) { 521 if (packed) {
513 int length = input.readRawVarint32(); 522 int length = input.readRawVarint32();
514 int limit = input.pushLimit(length); 523 int limit = input.pushLimit(length);
515 if (extension.descriptor.getLiteType() == WireFormat.FieldType.ENUM) { 524 if (extension.descriptor.getLiteType() == WireFormat.FieldType.ENUM) {
516 while (input.getBytesUntilLimit() > 0) { 525 while (input.getBytesUntilLimit() > 0) {
517 int rawValue = input.readEnum(); 526 int rawValue = input.readEnum();
518 Object value = 527 Object value =
519 extension.descriptor.getEnumType().findValueByNumber(rawValue); 528 extension.descriptor.getEnumType().findValueByNumber(rawValue);
520 if (value == null) { 529 if (value == null) {
521 // If the number isn't recognized as a valid value for this 530 // If the number isn't recognized as a valid value for this
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 589 }
581 590
582 if (extension.descriptor.isRepeated()) { 591 if (extension.descriptor.isRepeated()) {
583 extensions.addRepeatedField(extension.descriptor, 592 extensions.addRepeatedField(extension.descriptor,
584 extension.singularToFieldSetType(value)); 593 extension.singularToFieldSetType(value));
585 } else { 594 } else {
586 extensions.setField(extension.descriptor, 595 extensions.setField(extension.descriptor,
587 extension.singularToFieldSetType(value)); 596 extension.singularToFieldSetType(value));
588 } 597 }
589 } 598 }
590
591 return true; 599 return true;
592 } 600 }
593 601
602 /**
603 * Parse an unknown field or an extension. For use by generated code only.
604 *
605 * <p>For use by generated code only.
606 *
607 * @return {@code true} unless the tag is an end-group tag.
608 */
609 protected <MessageType extends MessageLite> boolean parseUnknownFieldAsMessa geSet(
610 MessageType defaultInstance,
611 CodedInputStream input,
612 ExtensionRegistryLite extensionRegistry,
613 int tag)
614 throws IOException {
615
616 if (tag == WireFormat.MESSAGE_SET_ITEM_TAG) {
617 mergeMessageSetExtensionFromCodedStream(defaultInstance, input, extensio nRegistry);
618 return true;
619 }
620
621 // TODO(dweis): Do we really want to support non message set wire format i n message sets?
622 // Full runtime does... So we do for now.
623 int wireType = WireFormat.getTagWireType(tag);
624 if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) {
625 return parseUnknownField(defaultInstance, input, extensionRegistry, tag) ;
626 } else {
627 // TODO(dweis): Should we throw on invalid input? Full runtime does not. ..
628 return input.skipField(tag);
629 }
630 }
631
632 /**
633 * Merges the message set from the input stream; requires message set wire f ormat.
634 *
635 * @param defaultInstance the default instance of the containing message we are parsing in
636 * @param input the stream to parse from
637 * @param extensionRegistry the registry to use when parsing
638 */
639 private <MessageType extends MessageLite> void mergeMessageSetExtensionFromC odedStream(
640 MessageType defaultInstance,
641 CodedInputStream input,
642 ExtensionRegistryLite extensionRegistry)
643 throws IOException {
644 // The wire format for MessageSet is:
645 // message MessageSet {
646 // repeated group Item = 1 {
647 // required int32 typeId = 2;
648 // required bytes message = 3;
649 // }
650 // }
651 // "typeId" is the extension's field number. The extension can only be
652 // a message type, where "message" contains the encoded bytes of that
653 // message.
654 //
655 // In practice, we will probably never see a MessageSet item in which
656 // the message appears before the type ID, or where either field does not
657 // appear exactly once. However, in theory such cases are valid, so we
658 // should be prepared to accept them.
659
660 int typeId = 0;
661 ByteString rawBytes = null; // If we encounter "message" before "typeId"
662 GeneratedExtension<?, ?> extension = null;
663
664 // Read bytes from input, if we get it's type first then parse it eagerly,
665 // otherwise we store the raw bytes in a local variable.
666 while (true) {
667 final int tag = input.readTag();
668 if (tag == 0) {
669 break;
670 }
671
672 if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) {
673 typeId = input.readUInt32();
674 if (typeId != 0) {
675 extension = extensionRegistry.findLiteExtensionByNumber(defaultInsta nce, typeId);
676 }
677
678 } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) {
679 if (typeId != 0) {
680 if (extension != null) {
681 // We already know the type, so we can parse directly from the
682 // input with no copying. Hooray!
683 eagerlyMergeMessageSetExtension(input, extension, extensionRegistr y, typeId);
684 rawBytes = null;
685 continue;
686 }
687 }
688 // We haven't seen a type ID yet or we want parse message lazily.
689 rawBytes = input.readBytes();
690
691 } else { // Unknown tag. Skip it.
692 if (!input.skipField(tag)) {
693 break; // End of group
694 }
695 }
696 }
697 input.checkLastTagWas(WireFormat.MESSAGE_SET_ITEM_END_TAG);
698
699 // Process the raw bytes.
700 if (rawBytes != null && typeId != 0) { // Zero is not a valid type ID.
701 if (extension != null) { // We known the type
702 mergeMessageSetExtensionFromBytes(rawBytes, extensionRegistry, extensi on);
703 } else { // We don't know how to parse this. Ignore it.
704 if (rawBytes != null) {
705 mergeLengthDelimitedField(typeId, rawBytes);
706 }
707 }
708 }
709 }
710
711 private void eagerlyMergeMessageSetExtension(
712 CodedInputStream input,
713 GeneratedExtension<?, ?> extension,
714 ExtensionRegistryLite extensionRegistry,
715 int typeId)
716 throws IOException {
717 int fieldNumber = typeId;
718 int tag = WireFormat.makeTag(typeId, WireFormat.WIRETYPE_LENGTH_DELIMITED) ;
719 parseExtension(input, extensionRegistry, extension, tag, fieldNumber);
720 }
721
722 private void mergeMessageSetExtensionFromBytes(
723 ByteString rawBytes,
724 ExtensionRegistryLite extensionRegistry,
725 GeneratedExtension<?, ?> extension)
726 throws IOException {
727 MessageLite.Builder subBuilder = null;
728 MessageLite existingValue = (MessageLite) extensions.getField(extension.de scriptor);
729 if (existingValue != null) {
730 subBuilder = existingValue.toBuilder();
731 }
732 if (subBuilder == null) {
733 subBuilder = extension.getMessageDefaultInstance().newBuilderForType();
734 }
735 rawBytes.newCodedInput().readMessage(subBuilder, extensionRegistry);
736 MessageLite value = subBuilder.build();
737
738 extensions.setField(extension.descriptor, extension.singularToFieldSetType (value));
739 }
740
594 private void verifyExtensionContainingType( 741 private void verifyExtensionContainingType(
595 final GeneratedExtension<MessageType, ?> extension) { 742 final GeneratedExtension<MessageType, ?> extension) {
596 if (extension.getContainingTypeDefaultInstance() != 743 if (extension.getContainingTypeDefaultInstance() !=
597 getDefaultInstanceForType()) { 744 getDefaultInstanceForType()) {
598 // This can only happen if someone uses unchecked operations. 745 // This can only happen if someone uses unchecked operations.
599 throw new IllegalArgumentException( 746 throw new IllegalArgumentException(
600 "This extension is for a different message type. Please make " + 747 "This extension is for a different message type. Please make " +
601 "sure that you are not suppressing any generics type warnings."); 748 "sure that you are not suppressing any generics type warnings.");
602 } 749 }
603 } 750 }
604 751
605 /** Check if a singular extension is present. */ 752 /** Check if a singular extension is present. */
606 @Override 753 @Override
607 public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Ty pe> extension) { 754 public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Ty pe> extension) {
608 GeneratedExtension<MessageType, Type> extensionLite = 755 GeneratedExtension<MessageType, Type> extensionLite =
609 checkIsLite(extension); 756 checkIsLite(extension);
610 757
611 verifyExtensionContainingType(extensionLite); 758 verifyExtensionContainingType(extensionLite);
612 return extensions.hasField(extensionLite.descriptor); 759 return extensions.hasField(extensionLite.descriptor);
613 } 760 }
614 761
615 /** Get the number of elements in a repeated extension. */ 762 /** Get the number of elements in a repeated extension. */
616 @Override 763 @Override
617 public final <Type> int getExtensionCount( 764 public final <Type> int getExtensionCount(
618 final ExtensionLite<MessageType, List<Type>> extension) { 765 final ExtensionLite<MessageType, List<Type>> extension) {
619 GeneratedExtension<MessageType, List<Type>> extensionLite = 766 GeneratedExtension<MessageType, List<Type>> extensionLite =
620 checkIsLite(extension); 767 checkIsLite(extension);
621 768
622 verifyExtensionContainingType(extensionLite); 769 verifyExtensionContainingType(extensionLite);
623 return extensions.getRepeatedFieldCount(extensionLite.descriptor); 770 return extensions.getRepeatedFieldCount(extensionLite.descriptor);
624 } 771 }
625 772
626 /** Get the value of an extension. */ 773 /** Get the value of an extension. */
627 @Override 774 @Override
628 @SuppressWarnings("unchecked") 775 @SuppressWarnings("unchecked")
629 public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extension) { 776 public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extension) {
630 GeneratedExtension<MessageType, Type> extensionLite = 777 GeneratedExtension<MessageType, Type> extensionLite =
631 checkIsLite(extension); 778 checkIsLite(extension);
632 779
633 verifyExtensionContainingType(extensionLite); 780 verifyExtensionContainingType(extensionLite);
634 final Object value = extensions.getField(extensionLite.descriptor); 781 final Object value = extensions.getField(extensionLite.descriptor);
635 if (value == null) { 782 if (value == null) {
636 return extensionLite.defaultValue; 783 return extensionLite.defaultValue;
637 } else { 784 } else {
638 return (Type) extensionLite.fromFieldSetType(value); 785 return (Type) extensionLite.fromFieldSetType(value);
639 } 786 }
640 } 787 }
641 788
642 /** Get one element of a repeated extension. */ 789 /** Get one element of a repeated extension. */
(...skipping 10 matching lines...) Expand all
653 } 800 }
654 801
655 /** Called by subclasses to check if all extensions are initialized. */ 802 /** Called by subclasses to check if all extensions are initialized. */
656 protected boolean extensionsAreInitialized() { 803 protected boolean extensionsAreInitialized() {
657 return extensions.isInitialized(); 804 return extensions.isInitialized();
658 } 805 }
659 806
660 @Override 807 @Override
661 protected final void makeImmutable() { 808 protected final void makeImmutable() {
662 super.makeImmutable(); 809 super.makeImmutable();
663 810
664 extensions.makeImmutable(); 811 extensions.makeImmutable();
665 } 812 }
666 813
667 /** 814 /**
668 * Used by subclasses to serialize extensions. Extension ranges may be 815 * Used by subclasses to serialize extensions. Extension ranges may be
669 * interleaved with field numbers, but we must write them in canonical 816 * interleaved with field numbers, but we must write them in canonical
670 * (sorted by field number) order. ExtensionWriter helps us write 817 * (sorted by field number) order. ExtensionWriter helps us write
671 * individual ranges of extensions at once. 818 * individual ranges of extensions at once.
672 */ 819 */
673 protected class ExtensionWriter { 820 protected class ExtensionWriter {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 * Lite equivalent of {@link GeneratedMessage.ExtendableBuilder}. 874 * Lite equivalent of {@link GeneratedMessage.ExtendableBuilder}.
728 */ 875 */
729 @SuppressWarnings("unchecked") 876 @SuppressWarnings("unchecked")
730 public abstract static class ExtendableBuilder< 877 public abstract static class ExtendableBuilder<
731 MessageType extends ExtendableMessage<MessageType, BuilderType>, 878 MessageType extends ExtendableMessage<MessageType, BuilderType>,
732 BuilderType extends ExtendableBuilder<MessageType, BuilderType>> 879 BuilderType extends ExtendableBuilder<MessageType, BuilderType>>
733 extends Builder<MessageType, BuilderType> 880 extends Builder<MessageType, BuilderType>
734 implements ExtendableMessageOrBuilder<MessageType, BuilderType> { 881 implements ExtendableMessageOrBuilder<MessageType, BuilderType> {
735 protected ExtendableBuilder(MessageType defaultInstance) { 882 protected ExtendableBuilder(MessageType defaultInstance) {
736 super(defaultInstance); 883 super(defaultInstance);
737 884
738 // TODO(dweis): This is kind of an unnecessary clone since we construct a 885 // TODO(dweis): This is kind of an unnecessary clone since we construct a
739 // new instance in the parent constructor which makes the extensions 886 // new instance in the parent constructor which makes the extensions
740 // immutable. This extra allocation shouldn't matter in practice 887 // immutable. This extra allocation shouldn't matter in practice
741 // though. 888 // though.
742 instance.extensions = instance.extensions.clone(); 889 instance.extensions = instance.extensions.clone();
743 } 890 }
744 891
745 // For immutable message conversion. 892 // For immutable message conversion.
746 void internalSetExtensionSet(FieldSet<ExtensionDescriptor> extensions) { 893 void internalSetExtensionSet(FieldSet<ExtensionDescriptor> extensions) {
747 copyOnWrite(); 894 copyOnWrite();
748 instance.extensions = extensions; 895 instance.extensions = extensions;
749 } 896 }
750 897
751 @Override 898 @Override
752 protected void copyOnWrite() { 899 protected void copyOnWrite() {
753 if (!isBuilt) { 900 if (!isBuilt) {
754 return; 901 return;
755 } 902 }
756 903
757 super.copyOnWrite(); 904 super.copyOnWrite();
758 instance.extensions = instance.extensions.clone(); 905 instance.extensions = instance.extensions.clone();
759 } 906 }
760 907
761 @Override 908 @Override
762 public final MessageType buildPartial() { 909 public final MessageType buildPartial() {
763 if (isBuilt) { 910 if (isBuilt) {
764 return instance; 911 return instance;
765 } 912 }
766 913
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 947 }
801 948
802 /** Get one element of a repeated extension. */ 949 /** Get one element of a repeated extension. */
803 @Override 950 @Override
804 @SuppressWarnings("unchecked") 951 @SuppressWarnings("unchecked")
805 public final <Type> Type getExtension( 952 public final <Type> Type getExtension(
806 final ExtensionLite<MessageType, List<Type>> extension, final int index) { 953 final ExtensionLite<MessageType, List<Type>> extension, final int index) {
807 return instance.getExtension(extension, index); 954 return instance.getExtension(extension, index);
808 } 955 }
809 956
810 // This is implemented here only to work around an apparent bug in the
811 // Java compiler and/or build system. See bug #1898463. The mere presence
812 // of this dummy clone() implementation makes it go away.
813 @Override
814 public BuilderType clone() {
815 return super.clone();
816 }
817
818 /** Set the value of an extension. */ 957 /** Set the value of an extension. */
819 public final <Type> BuilderType setExtension( 958 public final <Type> BuilderType setExtension(
820 final ExtensionLite<MessageType, Type> extension, 959 final ExtensionLite<MessageType, Type> extension,
821 final Type value) { 960 final Type value) {
822 GeneratedExtension<MessageType, Type> extensionLite = 961 GeneratedExtension<MessageType, Type> extensionLite =
823 checkIsLite(extension); 962 checkIsLite(extension);
824 963
825 verifyExtensionContainingType(extensionLite); 964 verifyExtensionContainingType(extensionLite);
826 copyOnWrite(); 965 copyOnWrite();
827 instance.extensions.setField(extensionLite.descriptor, extensionLite.toFie ldSetType(value)); 966 instance.extensions.setField(extensionLite.descriptor, extensionLite.toFie ldSetType(value));
828 return (BuilderType) this; 967 return (BuilderType) this;
829 } 968 }
830 969
831 /** Set the value of one element of a repeated extension. */ 970 /** Set the value of one element of a repeated extension. */
832 public final <Type> BuilderType setExtension( 971 public final <Type> BuilderType setExtension(
833 final ExtensionLite<MessageType, List<Type>> extension, 972 final ExtensionLite<MessageType, List<Type>> extension,
834 final int index, final Type value) { 973 final int index, final Type value) {
835 GeneratedExtension<MessageType, List<Type>> extensionLite = 974 GeneratedExtension<MessageType, List<Type>> extensionLite =
836 checkIsLite(extension); 975 checkIsLite(extension);
837 976
838 verifyExtensionContainingType(extensionLite); 977 verifyExtensionContainingType(extensionLite);
839 copyOnWrite(); 978 copyOnWrite();
840 instance.extensions.setRepeatedField( 979 instance.extensions.setRepeatedField(
841 extensionLite.descriptor, index, extensionLite.singularToFieldSetType( value)); 980 extensionLite.descriptor, index, extensionLite.singularToFieldSetType( value));
842 return (BuilderType) this; 981 return (BuilderType) this;
843 } 982 }
844 983
845 /** Append a value to a repeated extension. */ 984 /** Append a value to a repeated extension. */
846 public final <Type> BuilderType addExtension( 985 public final <Type> BuilderType addExtension(
847 final ExtensionLite<MessageType, List<Type>> extension, 986 final ExtensionLite<MessageType, List<Type>> extension,
848 final Type value) { 987 final Type value) {
849 GeneratedExtension<MessageType, List<Type>> extensionLite = 988 GeneratedExtension<MessageType, List<Type>> extensionLite =
850 checkIsLite(extension); 989 checkIsLite(extension);
851 990
852 verifyExtensionContainingType(extensionLite); 991 verifyExtensionContainingType(extensionLite);
853 copyOnWrite(); 992 copyOnWrite();
854 instance.extensions.addRepeatedField( 993 instance.extensions.addRepeatedField(
855 extensionLite.descriptor, extensionLite.singularToFieldSetType(value)) ; 994 extensionLite.descriptor, extensionLite.singularToFieldSetType(value)) ;
856 return (BuilderType) this; 995 return (BuilderType) this;
857 } 996 }
858 997
859 /** Clear an extension. */ 998 /** Clear an extension. */
860 public final <Type> BuilderType clearExtension( 999 public final <Type> BuilderType clearExtension(
861 final ExtensionLite<MessageType, ?> extension) { 1000 final ExtensionLite<MessageType, ?> extension) {
862 GeneratedExtension<MessageType, ?> extensionLite = checkIsLite(extension); 1001 GeneratedExtension<MessageType, ?> extensionLite = checkIsLite(extension);
863 1002
864 verifyExtensionContainingType(extensionLite); 1003 verifyExtensionContainingType(extensionLite);
865 copyOnWrite(); 1004 copyOnWrite();
866 instance.extensions.clearField(extensionLite.descriptor); 1005 instance.extensions.clearField(extensionLite.descriptor);
867 return (BuilderType) this; 1006 return (BuilderType) this;
868 } 1007 }
869 } 1008 }
870 1009
871 // ----------------------------------------------------------------- 1010 // -----------------------------------------------------------------
872 1011
873 /** For use by generated code only. */ 1012 /** For use by generated code only. */
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1289
1151 /** 1290 /**
1152 * A serialized (serializable) form of the generated message. Stores the 1291 * A serialized (serializable) form of the generated message. Stores the
1153 * message as a class name and a byte array. 1292 * message as a class name and a byte array.
1154 */ 1293 */
1155 protected static final class SerializedForm implements Serializable { 1294 protected static final class SerializedForm implements Serializable {
1156 1295
1157 public static SerializedForm of(MessageLite message) { 1296 public static SerializedForm of(MessageLite message) {
1158 return new SerializedForm(message); 1297 return new SerializedForm(message);
1159 } 1298 }
1160 1299
1161 private static final long serialVersionUID = 0L; 1300 private static final long serialVersionUID = 0L;
1162 1301
1163 private final String messageClassName; 1302 private final String messageClassName;
1164 private final byte[] asBytes; 1303 private final byte[] asBytes;
1165 1304
1166 /** 1305 /**
1167 * Creates the serialized form by calling {@link com.google.protobuf.Message Lite#toByteArray}. 1306 * Creates the serialized form by calling {@link com.google.protobuf.Message Lite#toByteArray}.
1168 * @param regularForm the message to serialize 1307 * @param regularForm the message to serialize
1169 */ 1308 */
1170 SerializedForm(MessageLite regularForm) { 1309 SerializedForm(MessageLite regularForm) {
(...skipping 13 matching lines...) Expand all
1184 java.lang.reflect.Field defaultInstanceField = 1323 java.lang.reflect.Field defaultInstanceField =
1185 messageClass.getDeclaredField("DEFAULT_INSTANCE"); 1324 messageClass.getDeclaredField("DEFAULT_INSTANCE");
1186 defaultInstanceField.setAccessible(true); 1325 defaultInstanceField.setAccessible(true);
1187 MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(nul l); 1326 MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(nul l);
1188 return defaultInstance.newBuilderForType() 1327 return defaultInstance.newBuilderForType()
1189 .mergeFrom(asBytes) 1328 .mergeFrom(asBytes)
1190 .buildPartial(); 1329 .buildPartial();
1191 } catch (ClassNotFoundException e) { 1330 } catch (ClassNotFoundException e) {
1192 throw new RuntimeException("Unable to find proto buffer class: " + messa geClassName, e); 1331 throw new RuntimeException("Unable to find proto buffer class: " + messa geClassName, e);
1193 } catch (NoSuchFieldException e) { 1332 } catch (NoSuchFieldException e) {
1194 throw new RuntimeException("Unable to find DEFAULT_INSTANCE in " + messa geClassName, e); 1333 return readResolveFallback();
1195 } catch (SecurityException e) { 1334 } catch (SecurityException e) {
1196 throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messa geClassName, e); 1335 throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messa geClassName, e);
1197 } catch (IllegalAccessException e) { 1336 } catch (IllegalAccessException e) {
1198 throw new RuntimeException("Unable to call parsePartialFrom", e); 1337 throw new RuntimeException("Unable to call parsePartialFrom", e);
1199 } catch (InvalidProtocolBufferException e) { 1338 } catch (InvalidProtocolBufferException e) {
1200 throw new RuntimeException("Unable to understand proto buffer", e); 1339 throw new RuntimeException("Unable to understand proto buffer", e);
1201 } 1340 }
1202 } 1341 }
1342
1343 /**
1344 * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
1345 */
1346 @Deprecated
1347 private Object readResolveFallback() throws ObjectStreamException {
1348 try {
1349 Class<?> messageClass = Class.forName(messageClassName);
1350 java.lang.reflect.Field defaultInstanceField =
1351 messageClass.getDeclaredField("defaultInstance");
1352 defaultInstanceField.setAccessible(true);
1353 MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(nul l);
1354 return defaultInstance.newBuilderForType()
1355 .mergeFrom(asBytes)
1356 .buildPartial();
1357 } catch (ClassNotFoundException e) {
1358 throw new RuntimeException("Unable to find proto buffer class: " + messa geClassName, e);
1359 } catch (NoSuchFieldException e) {
1360 throw new RuntimeException("Unable to find defaultInstance in " + messag eClassName, e);
1361 } catch (SecurityException e) {
1362 throw new RuntimeException("Unable to call defaultInstance in " + messag eClassName, e);
1363 } catch (IllegalAccessException e) {
1364 throw new RuntimeException("Unable to call parsePartialFrom", e);
1365 } catch (InvalidProtocolBufferException e) {
1366 throw new RuntimeException("Unable to understand proto buffer", e);
1367 }
1368 }
1203 } 1369 }
1204 1370
1205 /** 1371 /**
1206 * Checks that the {@link Extension} is Lite and returns it as a 1372 * Checks that the {@link Extension} is Lite and returns it as a
1207 * {@link GeneratedExtension}. 1373 * {@link GeneratedExtension}.
1208 */ 1374 */
1209 private static < 1375 private static <
1210 MessageType extends ExtendableMessage<MessageType, BuilderType>, 1376 MessageType extends ExtendableMessage<MessageType, BuilderType>,
1211 BuilderType extends ExtendableBuilder<MessageType, BuilderType>, 1377 BuilderType extends ExtendableBuilder<MessageType, BuilderType>,
1212 T> 1378 T>
1213 GeneratedExtension<MessageType, T> checkIsLite( 1379 GeneratedExtension<MessageType, T> checkIsLite(
1214 ExtensionLite<MessageType, T> extension) { 1380 ExtensionLite<MessageType, T> extension) {
1215 if (!extension.isLite()) { 1381 if (!extension.isLite()) {
1216 throw new IllegalArgumentException("Expected a lite extension."); 1382 throw new IllegalArgumentException("Expected a lite extension.");
1217 } 1383 }
1218 1384
1219 return (GeneratedExtension<MessageType, T>) extension; 1385 return (GeneratedExtension<MessageType, T>) extension;
1220 } 1386 }
1221 1387
1222 /** 1388 /**
1223 * A static helper method for checking if a message is initialized, optionally memoizing. 1389 * A static helper method for checking if a message is initialized, optionally memoizing.
1224 * <p> 1390 * <p>
1225 * For use by generated code only. 1391 * For use by generated code only.
1226 */ 1392 */
1227 protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitia lized( 1393 protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitia lized(
1228 T message, boolean shouldMemoize) { 1394 T message, boolean shouldMemoize) {
1229 return message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, shouldMemoize) ! = null; 1395 return message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, shouldMemoize) ! = null;
1230 } 1396 }
1231 1397
1232 protected static final <T extends GeneratedMessageLite<T, ?>> void makeImmutab le(T message) { 1398 protected static final <T extends GeneratedMessageLite<T, ?>> void makeImmutab le(T message) {
1233 message.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); 1399 message.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE);
1234 } 1400 }
1235 1401
1236 protected static IntList emptyIntList() { 1402 protected static IntList emptyIntList() {
1237 return IntArrayList.emptyList(); 1403 return IntArrayList.emptyList();
1238 } 1404 }
1239 1405
1240 protected static IntList mutableCopy(IntList list) { 1406 protected static IntList mutableCopy(IntList list) {
1241 int size = list.size(); 1407 int size = list.size();
1242 return list.mutableCopyWithCapacity( 1408 return list.mutableCopyWithCapacity(
1243 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); 1409 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
1244 } 1410 }
1245 1411
1246 protected static LongList emptyLongList() { 1412 protected static LongList emptyLongList() {
1247 return LongArrayList.emptyList(); 1413 return LongArrayList.emptyList();
1248 } 1414 }
1249 1415
1250 protected static LongList mutableCopy(LongList list) { 1416 protected static LongList mutableCopy(LongList list) {
1251 int size = list.size(); 1417 int size = list.size();
1252 return list.mutableCopyWithCapacity( 1418 return list.mutableCopyWithCapacity(
1253 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); 1419 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
1254 } 1420 }
1255 1421
1256 protected static FloatList emptyFloatList() { 1422 protected static FloatList emptyFloatList() {
1257 return FloatArrayList.emptyList(); 1423 return FloatArrayList.emptyList();
1258 } 1424 }
1259 1425
1260 protected static FloatList mutableCopy(FloatList list) { 1426 protected static FloatList mutableCopy(FloatList list) {
1261 int size = list.size(); 1427 int size = list.size();
1262 return list.mutableCopyWithCapacity( 1428 return list.mutableCopyWithCapacity(
1263 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); 1429 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
1264 } 1430 }
1265 1431
1266 protected static DoubleList emptyDoubleList() { 1432 protected static DoubleList emptyDoubleList() {
1267 return DoubleArrayList.emptyList(); 1433 return DoubleArrayList.emptyList();
1268 } 1434 }
1269 1435
1270 protected static DoubleList mutableCopy(DoubleList list) { 1436 protected static DoubleList mutableCopy(DoubleList list) {
1271 int size = list.size(); 1437 int size = list.size();
1272 return list.mutableCopyWithCapacity( 1438 return list.mutableCopyWithCapacity(
1273 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); 1439 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
1274 } 1440 }
1275 1441
1276 protected static BooleanList emptyBooleanList() { 1442 protected static BooleanList emptyBooleanList() {
1277 return BooleanArrayList.emptyList(); 1443 return BooleanArrayList.emptyList();
1278 } 1444 }
1279 1445
1280 protected static BooleanList mutableCopy(BooleanList list) { 1446 protected static BooleanList mutableCopy(BooleanList list) {
1281 int size = list.size(); 1447 int size = list.size();
1282 return list.mutableCopyWithCapacity( 1448 return list.mutableCopyWithCapacity(
1283 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); 1449 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
1284 } 1450 }
1285 1451
1286 protected static <E> ProtobufList<E> emptyProtobufList() { 1452 protected static <E> ProtobufList<E> emptyProtobufList() {
1287 return ProtobufArrayList.emptyList(); 1453 return ProtobufArrayList.emptyList();
1288 } 1454 }
1289 1455
1290 protected static <E> ProtobufList<E> mutableCopy(ProtobufList<E> list) { 1456 protected static <E> ProtobufList<E> mutableCopy(ProtobufList<E> list) {
1291 int size = list.size(); 1457 int size = list.size();
1292 return list.mutableCopyWithCapacity( 1458 return list.mutableCopyWithCapacity(
1293 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); 1459 size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
1294 } 1460 }
1295 1461
1296 /** 1462 /**
1297 * A {@link Parser} implementation that delegates to the default instance. 1463 * A {@link Parser} implementation that delegates to the default instance.
1298 * <p> 1464 * <p>
1299 * For use by generated code only. 1465 * For use by generated code only.
1300 */ 1466 */
1301 protected static class DefaultInstanceBasedParser<T extends GeneratedMessageLi te<T, ?>> 1467 protected static class DefaultInstanceBasedParser<T extends GeneratedMessageLi te<T, ?>>
1302 extends AbstractParser<T> { 1468 extends AbstractParser<T> {
1303 1469
1304 private T defaultInstance; 1470 private T defaultInstance;
1305 1471
1306 public DefaultInstanceBasedParser(T defaultInstance) { 1472 public DefaultInstanceBasedParser(T defaultInstance) {
1307 this.defaultInstance = defaultInstance; 1473 this.defaultInstance = defaultInstance;
1308 } 1474 }
1309 1475
1310 @Override 1476 @Override
1311 public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite exte nsionRegistry) 1477 public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite exte nsionRegistry)
1312 throws InvalidProtocolBufferException { 1478 throws InvalidProtocolBufferException {
1313 return GeneratedMessageLite.parsePartialFrom(defaultInstance, input, exten sionRegistry); 1479 return GeneratedMessageLite.parsePartialFrom(defaultInstance, input, exten sionRegistry);
1314 } 1480 }
1315 } 1481 }
1316 1482
1317 /** 1483 /**
1318 * A static helper method for parsing a partial from input using the extension registry and the 1484 * A static helper method for parsing a partial from input using the extension registry and the
1319 * instance. 1485 * instance.
1320 */ 1486 */
1321 // TODO(dweis): Should this verify that the last tag was 0? 1487 // TODO(dweis): Should this verify that the last tag was 0?
1322 static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( 1488 static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
1323 T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistr y) 1489 T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistr y)
1324 throws InvalidProtocolBufferException { 1490 throws InvalidProtocolBufferException {
1325 @SuppressWarnings("unchecked") // Guaranteed by protoc 1491 @SuppressWarnings("unchecked") // Guaranteed by protoc
1326 T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); 1492 T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
1327 try { 1493 try {
1328 result.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionReg istry); 1494 result.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionReg istry);
1329 result.makeImmutable(); 1495 result.makeImmutable();
1330 } catch (RuntimeException e) { 1496 } catch (RuntimeException e) {
1331 if (e.getCause() instanceof InvalidProtocolBufferException) { 1497 if (e.getCause() instanceof InvalidProtocolBufferException) {
1332 throw (InvalidProtocolBufferException) e.getCause(); 1498 throw (InvalidProtocolBufferException) e.getCause();
1333 } 1499 }
1334 throw e; 1500 throw e;
1335 } 1501 }
1336 return result; 1502 return result;
1337 } 1503 }
1338 1504
1339 protected static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( 1505 protected static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
1340 T defaultInstance, 1506 T defaultInstance,
1341 CodedInputStream input) 1507 CodedInputStream input)
1342 throws InvalidProtocolBufferException { 1508 throws InvalidProtocolBufferException {
1343 return parsePartialFrom(defaultInstance, input, ExtensionRegistryLite.getEmp tyRegistry()); 1509 return parsePartialFrom(defaultInstance, input, ExtensionRegistryLite.getEmp tyRegistry());
1344 } 1510 }
1345 1511
1346 /** 1512 /**
1347 * Helper method to check if message is initialized. 1513 * Helper method to check if message is initialized.
1348 * 1514 *
1349 * @throws InvalidProtocolBufferException if it is not initialized. 1515 * @throws InvalidProtocolBufferException if it is not initialized.
1350 * @return The message to check. 1516 * @return The message to check.
1351 */ 1517 */
1352 private static <T extends GeneratedMessageLite<T, ?>> T checkMessageInitialize d(T message) 1518 private static <T extends GeneratedMessageLite<T, ?>> T checkMessageInitialize d(T message)
1353 throws InvalidProtocolBufferException { 1519 throws InvalidProtocolBufferException {
1354 if (message != null && !message.isInitialized()) { 1520 if (message != null && !message.isInitialized()) {
1355 throw message.newUninitializedMessageException() 1521 throw message.newUninitializedMessageException()
(...skipping 10 matching lines...) Expand all
1366 return checkMessageInitialized( 1532 return checkMessageInitialized(
1367 parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry( ))); 1533 parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry( )));
1368 } 1534 }
1369 1535
1370 // Validates last tag. 1536 // Validates last tag.
1371 protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom( 1537 protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
1372 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr y) 1538 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr y)
1373 throws InvalidProtocolBufferException { 1539 throws InvalidProtocolBufferException {
1374 return checkMessageInitialized(parsePartialFrom(defaultInstance, data, exten sionRegistry)); 1540 return checkMessageInitialized(parsePartialFrom(defaultInstance, data, exten sionRegistry));
1375 } 1541 }
1376 1542
1377 // This is a special case since we want to verify that the last tag is 0. We a ssume we exhaust the 1543 // This is a special case since we want to verify that the last tag is 0. We a ssume we exhaust the
1378 // ByteString. 1544 // ByteString.
1379 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( 1545 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
1380 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr y) 1546 T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistr y)
1381 throws InvalidProtocolBufferException { 1547 throws InvalidProtocolBufferException {
1382 T message; 1548 T message;
1383 try { 1549 try {
1384 CodedInputStream input = data.newCodedInput(); 1550 CodedInputStream input = data.newCodedInput();
1385 message = parsePartialFrom(defaultInstance, input, extensionRegistry); 1551 message = parsePartialFrom(defaultInstance, input, extensionRegistry);
1386 try { 1552 try {
1387 input.checkLastTagWas(0); 1553 input.checkLastTagWas(0);
1388 } catch (InvalidProtocolBufferException e) { 1554 } catch (InvalidProtocolBufferException e) {
1389 throw e.setUnfinishedMessage(message); 1555 throw e.setUnfinishedMessage(message);
1390 } 1556 }
1391 return message; 1557 return message;
1392 } catch (InvalidProtocolBufferException e) { 1558 } catch (InvalidProtocolBufferException e) {
1393 throw e; 1559 throw e;
1394 } 1560 }
1395 } 1561 }
1396 1562
1397 // This is a special case since we want to verify that the last tag is 0. We a ssume we exhaust the 1563 // This is a special case since we want to verify that the last tag is 0. We a ssume we exhaust the
1398 // ByteString. 1564 // ByteString.
1399 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( 1565 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
1400 T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry) 1566 T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry)
1401 throws InvalidProtocolBufferException { 1567 throws InvalidProtocolBufferException {
1402 T message; 1568 T message;
1403 try { 1569 try {
1404 CodedInputStream input = CodedInputStream.newInstance(data); 1570 CodedInputStream input = CodedInputStream.newInstance(data);
1405 message = parsePartialFrom(defaultInstance, input, extensionRegistry); 1571 message = parsePartialFrom(defaultInstance, input, extensionRegistry);
1406 try { 1572 try {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 ExtensionRegistryLite.getEmptyRegistry())); 1636 ExtensionRegistryLite.getEmptyRegistry()));
1471 } 1637 }
1472 1638
1473 // Validates last tag. 1639 // Validates last tag.
1474 protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom( 1640 protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom(
1475 T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegis try) 1641 T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegis try)
1476 throws InvalidProtocolBufferException { 1642 throws InvalidProtocolBufferException {
1477 return checkMessageInitialized( 1643 return checkMessageInitialized(
1478 parsePartialDelimitedFrom(defaultInstance, input, extensionRegistry)); 1644 parsePartialDelimitedFrom(defaultInstance, input, extensionRegistry));
1479 } 1645 }
1480 1646
1481 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialDelimitedF rom( 1647 private static <T extends GeneratedMessageLite<T, ?>> T parsePartialDelimitedF rom(
1482 T defaultInstance, 1648 T defaultInstance,
1483 InputStream input, 1649 InputStream input,
1484 ExtensionRegistryLite extensionRegistry) 1650 ExtensionRegistryLite extensionRegistry)
1485 throws InvalidProtocolBufferException { 1651 throws InvalidProtocolBufferException {
1486 int size; 1652 int size;
1487 try { 1653 try {
1488 int firstByte = input.read(); 1654 int firstByte = input.read();
1489 if (firstByte == -1) { 1655 if (firstByte == -1) {
1490 return null; 1656 return null;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 Object visitOneofBoolean(boolean minePresent, Object mine, Object other); 1689 Object visitOneofBoolean(boolean minePresent, Object mine, Object other);
1524 Object visitOneofInt(boolean minePresent, Object mine, Object other); 1690 Object visitOneofInt(boolean minePresent, Object mine, Object other);
1525 Object visitOneofDouble(boolean minePresent, Object mine, Object other); 1691 Object visitOneofDouble(boolean minePresent, Object mine, Object other);
1526 Object visitOneofFloat(boolean minePresent, Object mine, Object other); 1692 Object visitOneofFloat(boolean minePresent, Object mine, Object other);
1527 Object visitOneofLong(boolean minePresent, Object mine, Object other); 1693 Object visitOneofLong(boolean minePresent, Object mine, Object other);
1528 Object visitOneofString(boolean minePresent, Object mine, Object other); 1694 Object visitOneofString(boolean minePresent, Object mine, Object other);
1529 Object visitOneofByteString(boolean minePresent, Object mine, Object other); 1695 Object visitOneofByteString(boolean minePresent, Object mine, Object other);
1530 Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) ; 1696 Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) ;
1531 Object visitOneofMessage(boolean minePresent, Object mine, Object other); 1697 Object visitOneofMessage(boolean minePresent, Object mine, Object other);
1532 void visitOneofNotSet(boolean minePresent); 1698 void visitOneofNotSet(boolean minePresent);
1533 1699
1534 /** 1700 /**
1535 * Message fields use null sentinals. 1701 * Message fields use null sentinals.
1536 */ 1702 */
1537 <T extends MessageLite> T visitMessage(T mine, T other); 1703 <T extends MessageLite> T visitMessage(T mine, T other);
1538 LazyFieldLite visitLazyMessage( 1704 LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other);
1539 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField Lite other);
1540 1705
1541 <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other); 1706 <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other);
1542 BooleanList visitBooleanList(BooleanList mine, BooleanList other); 1707 BooleanList visitBooleanList(BooleanList mine, BooleanList other);
1543 IntList visitIntList(IntList mine, IntList other); 1708 IntList visitIntList(IntList mine, IntList other);
1544 DoubleList visitDoubleList(DoubleList mine, DoubleList other); 1709 DoubleList visitDoubleList(DoubleList mine, DoubleList other);
1545 FloatList visitFloatList(FloatList mine, FloatList other); 1710 FloatList visitFloatList(FloatList mine, FloatList other);
1546 LongList visitLongList(LongList mine, LongList other); 1711 LongList visitLongList(LongList mine, LongList other);
1547 FieldSet<ExtensionDescriptor> visitExtensions( 1712 FieldSet<ExtensionDescriptor> visitExtensions(
1548 FieldSet<ExtensionDescriptor> mine, FieldSet<ExtensionDescriptor> other) ; 1713 FieldSet<ExtensionDescriptor> mine, FieldSet<ExtensionDescriptor> other) ;
1549 UnknownFieldSetLite visitUnknownFields(UnknownFieldSetLite mine, UnknownFiel dSetLite other); 1714 UnknownFieldSetLite visitUnknownFields(UnknownFieldSetLite mine, UnknownFiel dSetLite other);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 throw NOT_EQUALS; 1844 throw NOT_EQUALS;
1680 } 1845 }
1681 1846
1682 @Override 1847 @Override
1683 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) { 1848 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
1684 if (minePresent && mine.equals(other)) { 1849 if (minePresent && mine.equals(other)) {
1685 return mine; 1850 return mine;
1686 } 1851 }
1687 throw NOT_EQUALS; 1852 throw NOT_EQUALS;
1688 } 1853 }
1689 1854
1690 @Override 1855 @Override
1691 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth er) { 1856 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth er) {
1692 if (minePresent && ((GeneratedMessageLite<?, ?>) mine).equals(this, (Messa geLite) other)) { 1857 if (minePresent && ((GeneratedMessageLite<?, ?>) mine).equals(this, (Messa geLite) other)) {
1693 return mine; 1858 return mine;
1694 } 1859 }
1695 throw NOT_EQUALS; 1860 throw NOT_EQUALS;
1696 } 1861 }
1697 1862
1698 @Override 1863 @Override
1699 public void visitOneofNotSet(boolean minePresent) { 1864 public void visitOneofNotSet(boolean minePresent) {
1700 if (minePresent) { 1865 if (minePresent) {
1701 throw NOT_EQUALS; 1866 throw NOT_EQUALS;
1702 } 1867 }
1703 } 1868 }
1704 1869
1705 @Override 1870 @Override
1706 public <T extends MessageLite> T visitMessage(T mine, T other) { 1871 public <T extends MessageLite> T visitMessage(T mine, T other) {
1707 if (mine == null && other == null) { 1872 if (mine == null && other == null) {
1708 return null; 1873 return null;
1709 } 1874 }
1710 1875
1711 if (mine == null || other == null) { 1876 if (mine == null || other == null) {
1712 throw NOT_EQUALS; 1877 throw NOT_EQUALS;
1713 } 1878 }
1714 1879
1715 ((GeneratedMessageLite<?, ?>) mine).equals(this, other); 1880 ((GeneratedMessageLite<?, ?>) mine).equals(this, other);
1716 1881
1717 return mine; 1882 return mine;
1718 } 1883 }
1719 1884
1720 @Override 1885 @Override
1721 public LazyFieldLite visitLazyMessage( 1886 public LazyFieldLite visitLazyMessage(
1722 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField Lite other) { 1887 LazyFieldLite mine, LazyFieldLite other) {
1723 if (!minePresent && !otherPresent) { 1888 if (mine == null && other == null) {
1724 return mine; 1889 return null;
1725 } else if (minePresent && otherPresent && mine.equals(other)) { 1890 }
1891 if (mine == null || other == null) {
1892 throw NOT_EQUALS;
1893 }
1894 if (mine.equals(other)) {
1726 return mine; 1895 return mine;
1727 } 1896 }
1728 throw NOT_EQUALS; 1897 throw NOT_EQUALS;
1729 } 1898 }
1730 1899
1731 @Override 1900 @Override
1732 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o ther) { 1901 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o ther) {
1733 if (!mine.equals(other)) { 1902 if (!mine.equals(other)) {
1734 throw NOT_EQUALS; 1903 throw NOT_EQUALS;
1735 } 1904 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 } 1975 }
1807 1976
1808 /** 1977 /**
1809 * Implements hashCode by accumulating state. 1978 * Implements hashCode by accumulating state.
1810 */ 1979 */
1811 private static class HashCodeVisitor implements Visitor { 1980 private static class HashCodeVisitor implements Visitor {
1812 1981
1813 // The caller must ensure that the visitor is invoked parameterized with thi s and this such that 1982 // The caller must ensure that the visitor is invoked parameterized with thi s and this such that
1814 // other is this. This is required due to how oneof cases are handled. See t he class comment 1983 // other is this. This is required due to how oneof cases are handled. See t he class comment
1815 // on Visitor for more information. 1984 // on Visitor for more information.
1816 1985
1817 private int hashCode = 0; 1986 private int hashCode = 0;
1818 1987
1819 @Override 1988 @Override
1820 public boolean visitBoolean( 1989 public boolean visitBoolean(
1821 boolean minePresent, boolean mine, boolean otherPresent, boolean other) { 1990 boolean minePresent, boolean mine, boolean otherPresent, boolean other) {
1822 hashCode = (53 * hashCode) + Internal.hashBoolean(mine); 1991 hashCode = (53 * hashCode) + Internal.hashBoolean(mine);
1823 return mine; 1992 return mine;
1824 } 1993 }
1825 1994
1826 @Override 1995 @Override
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 public Object visitOneofByteString(boolean minePresent, Object mine, Object other) { 2071 public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
1903 hashCode = (53 * hashCode) + mine.hashCode(); 2072 hashCode = (53 * hashCode) + mine.hashCode();
1904 return mine; 2073 return mine;
1905 } 2074 }
1906 2075
1907 @Override 2076 @Override
1908 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) { 2077 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
1909 hashCode = (53 * hashCode) + mine.hashCode(); 2078 hashCode = (53 * hashCode) + mine.hashCode();
1910 return mine; 2079 return mine;
1911 } 2080 }
1912 2081
1913 @Override 2082 @Override
1914 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth er) { 2083 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth er) {
1915 return visitMessage((MessageLite) mine, (MessageLite) other); 2084 return visitMessage((MessageLite) mine, (MessageLite) other);
1916 } 2085 }
1917 2086
1918 @Override 2087 @Override
1919 public void visitOneofNotSet(boolean minePresent) { 2088 public void visitOneofNotSet(boolean minePresent) {
1920 if (minePresent) { 2089 if (minePresent) {
1921 throw new IllegalStateException(); // Can't happen if other == this. 2090 throw new IllegalStateException(); // Can't happen if other == this.
1922 } 2091 }
1923 } 2092 }
1924 2093
1925 @Override 2094 @Override
1926 public <T extends MessageLite> T visitMessage(T mine, T other) { 2095 public <T extends MessageLite> T visitMessage(T mine, T other) {
1927 final int protoHash; 2096 final int protoHash;
1928 if (mine != null) { 2097 if (mine != null) {
1929 if (mine instanceof GeneratedMessageLite) { 2098 if (mine instanceof GeneratedMessageLite) {
1930 protoHash = ((GeneratedMessageLite) mine).hashCode(this); 2099 protoHash = ((GeneratedMessageLite) mine).hashCode(this);
1931 } else { 2100 } else {
1932 protoHash = mine.hashCode(); 2101 protoHash = mine.hashCode();
1933 } 2102 }
1934 } else { 2103 } else {
1935 protoHash = 37; 2104 protoHash = 37;
1936 } 2105 }
1937 hashCode = (53 * hashCode) + protoHash; 2106 hashCode = (53 * hashCode) + protoHash;
1938 return mine; 2107 return mine;
1939 } 2108 }
1940 2109
1941 @Override 2110 @Override
1942 public LazyFieldLite visitLazyMessage( 2111 public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite othe r) {
1943 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField Lite other) { 2112 final int protoHash;
1944 hashCode = (53 * hashCode) + mine.hashCode(); 2113 if (mine != null) {
2114 protoHash = mine.hashCode();
2115 } else {
2116 protoHash = 37;
2117 }
2118 hashCode = (53 * hashCode) + protoHash;
1945 return mine; 2119 return mine;
1946 } 2120 }
1947 2121
1948 @Override 2122 @Override
1949 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o ther) { 2123 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o ther) {
1950 hashCode = (53 * hashCode) + mine.hashCode(); 2124 hashCode = (53 * hashCode) + mine.hashCode();
1951 return mine; 2125 return mine;
1952 } 2126 }
1953 2127
1954 @Override 2128 @Override
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 return mine; 2163 return mine;
1990 } 2164 }
1991 2165
1992 @Override 2166 @Override
1993 public UnknownFieldSetLite visitUnknownFields( 2167 public UnknownFieldSetLite visitUnknownFields(
1994 UnknownFieldSetLite mine, 2168 UnknownFieldSetLite mine,
1995 UnknownFieldSetLite other) { 2169 UnknownFieldSetLite other) {
1996 hashCode = (53 * hashCode) + mine.hashCode(); 2170 hashCode = (53 * hashCode) + mine.hashCode();
1997 return mine; 2171 return mine;
1998 } 2172 }
1999 2173
2000 @Override 2174 @Override
2001 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL ite<K, V> other) { 2175 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL ite<K, V> other) {
2002 hashCode = (53 * hashCode) + mine.hashCode(); 2176 hashCode = (53 * hashCode) + mine.hashCode();
2003 return mine; 2177 return mine;
2004 } 2178 }
2005 } 2179 }
2006 2180
2007 /** 2181 /**
2008 * Implements field merging semantics over the visitor interface. 2182 * Implements field merging semantics over the visitor interface.
2009 */ 2183 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 return other; 2231 return other;
2058 } 2232 }
2059 2233
2060 @Override 2234 @Override
2061 public Object visitOneofInt(boolean minePresent, Object mine, Object other) { 2235 public Object visitOneofInt(boolean minePresent, Object mine, Object other) {
2062 return other; 2236 return other;
2063 } 2237 }
2064 2238
2065 @Override 2239 @Override
2066 public Object visitOneofDouble(boolean minePresent, Object mine, Object othe r) { 2240 public Object visitOneofDouble(boolean minePresent, Object mine, Object othe r) {
2067 return other; 2241 return other;
2068 } 2242 }
2069 2243
2070 @Override 2244 @Override
2071 public Object visitOneofFloat(boolean minePresent, Object mine, Object other ) { 2245 public Object visitOneofFloat(boolean minePresent, Object mine, Object other ) {
2072 return other; 2246 return other;
2073 } 2247 }
2074 2248
2075 @Override 2249 @Override
2076 public Object visitOneofLong(boolean minePresent, Object mine, Object other) { 2250 public Object visitOneofLong(boolean minePresent, Object mine, Object other) {
2077 return other; 2251 return other;
2078 } 2252 }
2079 2253
2080 @Override 2254 @Override
2081 public Object visitOneofString(boolean minePresent, Object mine, Object othe r) { 2255 public Object visitOneofString(boolean minePresent, Object mine, Object othe r) {
2082 return other; 2256 return other;
2083 } 2257 }
2084 2258
2085 @Override 2259 @Override
2086 public Object visitOneofByteString(boolean minePresent, Object mine, Object other) { 2260 public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
2087 return other; 2261 return other;
2088 } 2262 }
2089 2263
2090 @Override 2264 @Override
2091 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) { 2265 public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
2092 if (minePresent) { 2266 LazyFieldLite lazy = minePresent ? (LazyFieldLite) mine : new LazyFieldLit e();
2093 LazyFieldLite lazy = (LazyFieldLite) mine; 2267 lazy.merge((LazyFieldLite) other);
2094 lazy.merge((LazyFieldLite) other); 2268 return lazy;
2095 return lazy;
2096 }
2097 return other;
2098 } 2269 }
2099 2270
2100 @Override 2271 @Override
2101 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth er) { 2272 public Object visitOneofMessage(boolean minePresent, Object mine, Object oth er) {
2102 if (minePresent) { 2273 if (minePresent) {
2103 return visitMessage((MessageLite) mine, (MessageLite) other); 2274 return visitMessage((MessageLite) mine, (MessageLite) other);
2104 } 2275 }
2105 return other; 2276 return other;
2106 } 2277 }
2107 2278
2108 @Override 2279 @Override
2109 public void visitOneofNotSet(boolean minePresent) { 2280 public void visitOneofNotSet(boolean minePresent) {
2110 return; 2281 return;
2111 } 2282 }
2112 2283
2113 @SuppressWarnings("unchecked") // Guaranteed by runtime. 2284 @SuppressWarnings("unchecked") // Guaranteed by runtime.
2114 @Override 2285 @Override
2115 public <T extends MessageLite> T visitMessage(T mine, T other) { 2286 public <T extends MessageLite> T visitMessage(T mine, T other) {
2116 if (mine != null && other != null) { 2287 if (mine != null && other != null) {
2117 return (T) mine.toBuilder().mergeFrom(other).build(); 2288 return (T) mine.toBuilder().mergeFrom(other).build();
2118 } 2289 }
2119 2290
2120 return mine != null ? mine : other; 2291 return mine != null ? mine : other;
2121 } 2292 }
2122 2293
2123 @Override 2294 @Override
2124 public LazyFieldLite visitLazyMessage( 2295 public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite othe r) {
2125 boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyField Lite other) { 2296 if (other != null) {
2126 // LazyFieldLite's are never null so we can just copy across. Necessary to avoid leakage 2297 if (mine == null) {
2127 // from builder into immutable message. 2298 mine = new LazyFieldLite();
2128 // TODO(dweis): Change to null sentinels? 2299 }
2129 mine.merge(other); 2300 mine.merge(other);
2301 }
2130 return mine; 2302 return mine;
2131 } 2303 }
2132 2304
2133 @Override 2305 @Override
2134 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o ther) { 2306 public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> o ther) {
2135 int size = mine.size(); 2307 int size = mine.size();
2136 int otherSize = other.size(); 2308 int otherSize = other.size();
2137 if (size > 0 && otherSize > 0) { 2309 if (size > 0 && otherSize > 0) {
2138 if (!mine.isModifiable()) { 2310 if (!mine.isModifiable()) {
2139 mine = mine.mutableCopyWithCapacity(size + otherSize); 2311 mine = mine.mutableCopyWithCapacity(size + otherSize);
2140 } 2312 }
2141 mine.addAll(other); 2313 mine.addAll(other);
2142 } 2314 }
2143 2315
2144 return size > 0 ? mine : other; 2316 return size > 0 ? mine : other;
2145 } 2317 }
2146 2318
2147 @Override 2319 @Override
2148 public BooleanList visitBooleanList(BooleanList mine, BooleanList other) { 2320 public BooleanList visitBooleanList(BooleanList mine, BooleanList other) {
2149 int size = mine.size(); 2321 int size = mine.size();
2150 int otherSize = other.size(); 2322 int otherSize = other.size();
2151 if (size > 0 && otherSize > 0) { 2323 if (size > 0 && otherSize > 0) {
2152 if (!mine.isModifiable()) { 2324 if (!mine.isModifiable()) {
2153 mine = mine.mutableCopyWithCapacity(size + otherSize); 2325 mine = mine.mutableCopyWithCapacity(size + otherSize);
2154 } 2326 }
2155 mine.addAll(other); 2327 mine.addAll(other);
2156 } 2328 }
2157 2329
2158 return size > 0 ? mine : other; 2330 return size > 0 ? mine : other;
2159 } 2331 }
2160 2332
2161 @Override 2333 @Override
2162 public IntList visitIntList(IntList mine, IntList other) { 2334 public IntList visitIntList(IntList mine, IntList other) {
2163 int size = mine.size(); 2335 int size = mine.size();
2164 int otherSize = other.size(); 2336 int otherSize = other.size();
2165 if (size > 0 && otherSize > 0) { 2337 if (size > 0 && otherSize > 0) {
2166 if (!mine.isModifiable()) { 2338 if (!mine.isModifiable()) {
2167 mine = mine.mutableCopyWithCapacity(size + otherSize); 2339 mine = mine.mutableCopyWithCapacity(size + otherSize);
2168 } 2340 }
2169 mine.addAll(other); 2341 mine.addAll(other);
2170 } 2342 }
2171 2343
2172 return size > 0 ? mine : other; 2344 return size > 0 ? mine : other;
2173 } 2345 }
2174 2346
2175 @Override 2347 @Override
2176 public DoubleList visitDoubleList(DoubleList mine, DoubleList other) { 2348 public DoubleList visitDoubleList(DoubleList mine, DoubleList other) {
2177 int size = mine.size(); 2349 int size = mine.size();
2178 int otherSize = other.size(); 2350 int otherSize = other.size();
2179 if (size > 0 && otherSize > 0) { 2351 if (size > 0 && otherSize > 0) {
2180 if (!mine.isModifiable()) { 2352 if (!mine.isModifiable()) {
2181 mine = mine.mutableCopyWithCapacity(size + otherSize); 2353 mine = mine.mutableCopyWithCapacity(size + otherSize);
2182 } 2354 }
2183 mine.addAll(other); 2355 mine.addAll(other);
2184 } 2356 }
2185 2357
2186 return size > 0 ? mine : other; 2358 return size > 0 ? mine : other;
2187 } 2359 }
2188 2360
2189 @Override 2361 @Override
2190 public FloatList visitFloatList(FloatList mine, FloatList other) { 2362 public FloatList visitFloatList(FloatList mine, FloatList other) {
2191 int size = mine.size(); 2363 int size = mine.size();
2192 int otherSize = other.size(); 2364 int otherSize = other.size();
2193 if (size > 0 && otherSize > 0) { 2365 if (size > 0 && otherSize > 0) {
2194 if (!mine.isModifiable()) { 2366 if (!mine.isModifiable()) {
2195 mine = mine.mutableCopyWithCapacity(size + otherSize); 2367 mine = mine.mutableCopyWithCapacity(size + otherSize);
2196 } 2368 }
2197 mine.addAll(other); 2369 mine.addAll(other);
2198 } 2370 }
2199 2371
2200 return size > 0 ? mine : other; 2372 return size > 0 ? mine : other;
2201 } 2373 }
2202 2374
2203 @Override 2375 @Override
2204 public LongList visitLongList(LongList mine, LongList other) { 2376 public LongList visitLongList(LongList mine, LongList other) {
2205 int size = mine.size(); 2377 int size = mine.size();
2206 int otherSize = other.size(); 2378 int otherSize = other.size();
2207 if (size > 0 && otherSize > 0) { 2379 if (size > 0 && otherSize > 0) {
2208 if (!mine.isModifiable()) { 2380 if (!mine.isModifiable()) {
2209 mine = mine.mutableCopyWithCapacity(size + otherSize); 2381 mine = mine.mutableCopyWithCapacity(size + otherSize);
2210 } 2382 }
2211 mine.addAll(other); 2383 mine.addAll(other);
2212 } 2384 }
2213 2385
2214 return size > 0 ? mine : other; 2386 return size > 0 ? mine : other;
2215 } 2387 }
2216 2388
2217 @Override 2389 @Override
2218 public FieldSet<ExtensionDescriptor> visitExtensions( 2390 public FieldSet<ExtensionDescriptor> visitExtensions(
2219 FieldSet<ExtensionDescriptor> mine, 2391 FieldSet<ExtensionDescriptor> mine,
2220 FieldSet<ExtensionDescriptor> other) { 2392 FieldSet<ExtensionDescriptor> other) {
2221 if (mine.isImmutable()) { 2393 if (mine.isImmutable()) {
2222 mine = mine.clone(); 2394 mine = mine.clone();
2223 } 2395 }
2224 mine.mergeFrom(other); 2396 mine.mergeFrom(other);
2225 return mine; 2397 return mine;
2226 } 2398 }
2227 2399
2228 @Override 2400 @Override
2229 public UnknownFieldSetLite visitUnknownFields( 2401 public UnknownFieldSetLite visitUnknownFields(
2230 UnknownFieldSetLite mine, 2402 UnknownFieldSetLite mine,
2231 UnknownFieldSetLite other) { 2403 UnknownFieldSetLite other) {
2232 return other == UnknownFieldSetLite.getDefaultInstance() 2404 return other == UnknownFieldSetLite.getDefaultInstance()
2233 ? mine : UnknownFieldSetLite.mutableCopyOf(mine, other); 2405 ? mine : UnknownFieldSetLite.mutableCopyOf(mine, other);
2234 } 2406 }
2235 2407
2236 @Override 2408 @Override
2237 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL ite<K, V> other) { 2409 public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldL ite<K, V> other) {
2238 mine.mergeFrom(other); 2410 if (!other.isEmpty()) {
2411 if (!mine.isMutable()) {
2412 mine = mine.mutableCopy();
2413 }
2414 mine.mergeFrom(other);
2415 }
2239 return mine; 2416 return mine;
2240 } 2417 }
2241 } 2418 }
2242 } 2419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698