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

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

Issue 2599263002: third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Address comments Created 3 years, 12 months 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 /** 47 /**
48 * A partial implementation of the {@link Message} interface which implements 48 * A partial implementation of the {@link Message} interface which implements
49 * as many methods of that interface as possible in terms of other methods. 49 * as many methods of that interface as possible in terms of other methods.
50 * 50 *
51 * @author kenton@google.com Kenton Varda 51 * @author kenton@google.com Kenton Varda
52 */ 52 */
53 public abstract class AbstractMessage 53 public abstract class AbstractMessage
54 // TODO(dweis): Update GeneratedMessage to parameterize with MessageType and BuilderType. 54 // TODO(dweis): Update GeneratedMessage to parameterize with MessageType and BuilderType.
55 extends AbstractMessageLite 55 extends AbstractMessageLite
56 implements Message { 56 implements Message {
57 57
58 @Override 58 @Override
59 public boolean isInitialized() { 59 public boolean isInitialized() {
60 return MessageReflection.isInitialized(this); 60 return MessageReflection.isInitialized(this);
61 } 61 }
62 62
63 /**
64 * Interface for the parent of a Builder that allows the builder to
65 * communicate invalidations back to the parent for use when using nested
66 * builders.
67 */
68 protected interface BuilderParent {
69
70 /**
71 * A builder becomes dirty whenever a field is modified -- including fields
72 * in nested builders -- and becomes clean when build() is called. Thus,
73 * when a builder becomes dirty, all its parents become dirty as well, and
74 * when it becomes clean, all its children become clean. The dirtiness
75 * state is used to invalidate certain cached values.
76 * <br>
77 * To this end, a builder calls markDirty() on its parent whenever it
78 * transitions from clean to dirty. The parent must propagate this call to
79 * its own parent, unless it was already dirty, in which case the
80 * grandparent must necessarily already be dirty as well. The parent can
81 * only transition back to "clean" after calling build() on all children.
82 */
83 void markDirty();
84 }
85
86 /** Create a nested builder. */
87 protected Message.Builder newBuilderForType(BuilderParent parent) {
88 throw new UnsupportedOperationException("Nested builder is not supported for this type.");
89 }
90
63 91
64 @Override 92 @Override
65 public List<String> findInitializationErrors() { 93 public List<String> findInitializationErrors() {
66 return MessageReflection.findMissingFields(this); 94 return MessageReflection.findMissingFields(this);
67 } 95 }
68 96
69 @Override 97 @Override
70 public String getInitializationErrorString() { 98 public String getInitializationErrorString() {
71 return MessageReflection.delimitWithCommas(findInitializationErrors()); 99 return MessageReflection.delimitWithCommas(findInitializationErrors());
72 } 100 }
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 /** 481 /**
454 * Construct an UninitializedMessageException reporting missing fields in 482 * Construct an UninitializedMessageException reporting missing fields in
455 * the given message. 483 * the given message.
456 */ 484 */
457 protected static UninitializedMessageException 485 protected static UninitializedMessageException
458 newUninitializedMessageException(Message message) { 486 newUninitializedMessageException(Message message) {
459 return new UninitializedMessageException( 487 return new UninitializedMessageException(
460 MessageReflection.findMissingFields(message)); 488 MessageReflection.findMissingFields(message));
461 } 489 }
462 490
491 /**
492 * Used to support nested builders and called to mark this builder as clean.
493 * Clean builders will propagate the {@link BuilderParent#markDirty()} event
494 * to their parent builders, while dirty builders will not, as their parents
495 * should be dirty already.
496 *
497 * NOTE: Implementations that don't support nested builders don't need to
498 * override this method.
499 */
500 void markClean() {
501 throw new IllegalStateException("Should be overridden by subclasses.");
502 }
503
504 /**
505 * Used to support nested builders and called when this nested builder is
506 * no longer used by its parent builder and should release the reference
507 * to its parent builder.
508 *
509 * NOTE: Implementations that don't support nested builders don't need to
510 * override this method.
511 */
512 void dispose() {
513 throw new IllegalStateException("Should be overridden by subclasses.");
514 }
515
463 // =============================================================== 516 // ===============================================================
464 // The following definitions seem to be required in order to make javac 517 // The following definitions seem to be required in order to make javac
465 // not produce weird errors like: 518 // not produce weird errors like:
466 // 519 //
467 // java/com/google/protobuf/DynamicMessage.java:203: types 520 // java/com/google/protobuf/DynamicMessage.java:203: types
468 // com.google.protobuf.AbstractMessage.Builder< 521 // com.google.protobuf.AbstractMessage.Builder<
469 // com.google.protobuf.DynamicMessage.Builder> and 522 // com.google.protobuf.DynamicMessage.Builder> and
470 // com.google.protobuf.AbstractMessage.Builder< 523 // com.google.protobuf.AbstractMessage.Builder<
471 // com.google.protobuf.DynamicMessage.Builder> are incompatible; both 524 // com.google.protobuf.DynamicMessage.Builder> are incompatible; both
472 // define mergeFrom(com.google.protobuf.ByteString), but with unrelated 525 // define mergeFrom(com.google.protobuf.ByteString), but with unrelated
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 596 }
544 597
545 @Override 598 @Override
546 public boolean mergeDelimitedFrom( 599 public boolean mergeDelimitedFrom(
547 final InputStream input, 600 final InputStream input,
548 final ExtensionRegistryLite extensionRegistry) 601 final ExtensionRegistryLite extensionRegistry)
549 throws IOException { 602 throws IOException {
550 return super.mergeDelimitedFrom(input, extensionRegistry); 603 return super.mergeDelimitedFrom(input, extensionRegistry);
551 } 604 }
552 } 605 }
606
607 /**
608 * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
609 * generated code.
610 */
611 @Deprecated
612 protected static int hashLong(long n) {
613 return (int) (n ^ (n >>> 32));
614 }
615 //
616 /**
617 * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
618 * generated code.
619 */
620 @Deprecated
621 protected static int hashBoolean(boolean b) {
622 return b ? 1231 : 1237;
623 }
624 //
625 /**
626 * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
627 * generated code.
628 */
629 @Deprecated
630 protected static int hashEnum(EnumLite e) {
631 return e.getNumber();
632 }
633 //
634 /**
635 * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
636 * generated code.
637 */
638 @Deprecated
639 protected static int hashEnumList(List<? extends EnumLite> list) {
640 int hash = 1;
641 for (EnumLite e : list) {
642 hash = 31 * hash + hashEnum(e);
643 }
644 return hash;
645 }
553 } 646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698