diff options
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java')
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java | 387 |
1 files changed, 260 insertions, 127 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index f885b01e..df01547e 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -31,9 +31,9 @@ package com.google.protobuf; import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; -import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException; import com.google.protobuf.Internal.BooleanList; import com.google.protobuf.Internal.DoubleList; +import com.google.protobuf.Internal.EnumLiteMap; import com.google.protobuf.Internal.FloatList; import com.google.protobuf.Internal.IntList; import com.google.protobuf.Internal.LongList; @@ -45,11 +45,13 @@ import java.io.ObjectStreamException; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Lite version of {@link GeneratedMessage}. @@ -60,6 +62,12 @@ public abstract class GeneratedMessageLite< MessageType extends GeneratedMessageLite<MessageType, BuilderType>, BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> extends AbstractMessageLite<MessageType, BuilderType> { + // BEGIN REGULAR + static final boolean ENABLE_EXPERIMENTAL_RUNTIME_AT_BUILD_TIME = false; + // END REGULAR + // BEGIN EXPERIMENTAL + // static final boolean ENABLE_EXPERIMENTAL_RUNTIME_AT_BUILD_TIME = true; + // END EXPERIMENTAL /** For use by generated code only. Lazily initialized to reduce allocations. */ protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultInstance(); @@ -105,14 +113,22 @@ public abstract class GeneratedMessageLite< @SuppressWarnings("unchecked") // Guaranteed by runtime @Override public int hashCode() { - if (memoizedHashCode == 0) { - HashCodeVisitor visitor = new HashCodeVisitor(); - visit(visitor, (MessageType) this); - memoizedHashCode = visitor.hashCode; - } + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + // BEGIN EXPERIMENTAL + // memoizedHashCode = Protobuf.getInstance().schemaFor(this).hashCode(this); + // return memoizedHashCode; + // END EXPERIMENTAL + // BEGIN REGULAR + HashCodeVisitor visitor = new HashCodeVisitor(); + visit(visitor, (MessageType) this); + memoizedHashCode = visitor.hashCode; return memoizedHashCode; + // END REGULAR } + // BEGIN REGULAR @SuppressWarnings("unchecked") // Guaranteed by runtime int hashCode(HashCodeVisitor visitor) { if (memoizedHashCode == 0) { @@ -124,6 +140,7 @@ public abstract class GeneratedMessageLite< } return memoizedHashCode; } + // END REGULAR @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime @Override @@ -136,17 +153,22 @@ public abstract class GeneratedMessageLite< return false; } + // BEGIN EXPERIMENTAL + // return Protobuf.getInstance().schemaFor(this).equals(this, (MessageType) other); + // END EXPERIMENTAL + // BEGIN REGULAR + try { visit(EqualsVisitor.INSTANCE, (MessageType) other); - } catch (NotEqualsException e) { + } catch (EqualsVisitor.NotEqualsException e) { return false; } return true; + // END REGULAR } - /** - * Same as {@link #equals(Object)} but throws {@code NotEqualsException}. - */ + // BEGIN REGULAR + /** Same as {@link #equals(Object)} but throws {@code NotEqualsException}. */ @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime boolean equals(EqualsVisitor visitor, MessageLite other) { if (this == other) { @@ -160,14 +182,13 @@ public abstract class GeneratedMessageLite< visit(visitor, (MessageType) other); return true; } + // END REGULAR // The general strategy for unknown fields is to use an UnknownFieldSetLite that is treated as // mutable during the parsing constructor and immutable after. This allows us to avoid // any unnecessary intermediary allocations while reducing the generated code size. - /** - * Lazily initializes unknown fields. - */ + /** Lazily initializes unknown fields. */ private final void ensureUnknownFieldsInitialized() { if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { unknownFields = UnknownFieldSetLite.newInstance(); @@ -209,17 +230,36 @@ public abstract class GeneratedMessageLite< * Called by subclasses to complete parsing. For use by generated code only. */ protected void makeImmutable() { + // BEGIN REGULAR dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); - unknownFields.makeImmutable(); + // END REGULAR + // BEGIN EXPERIMENTAL + // Protobuf.getInstance().schemaFor(this).makeImmutable(this); + // END EXPERIMENTAL + } + + protected final < + MessageType extends GeneratedMessageLite<MessageType, BuilderType>, + BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> + BuilderType createBuilder() { + return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); + } + + protected final < + MessageType extends GeneratedMessageLite<MessageType, BuilderType>, + BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> + BuilderType createBuilder(MessageType prototype) { + return ((BuilderType) createBuilder()).mergeFrom(prototype); } @Override public final boolean isInitialized() { - return dynamicMethod(MethodToInvoke.IS_INITIALIZED, Boolean.TRUE) != null; + return isInitialized((MessageType) this, Boolean.TRUE); } @Override + @SuppressWarnings("unchecked") public final BuilderType toBuilder() { BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); builder.mergeFrom((MessageType) this); @@ -233,11 +273,15 @@ public abstract class GeneratedMessageLite< * For use by generated code only. */ public static enum MethodToInvoke { - // Rely on/modify instance state + // BEGIN REGULAR IS_INITIALIZED, VISIT, MERGE_FROM_STREAM, MAKE_IMMUTABLE, + // END REGULAR + // Rely on/modify instance state + GET_MEMOIZED_IS_INITIALIZED, + SET_MEMOIZED_IS_INITIALIZED, // Rely on static state NEW_MUTABLE_INSTANCE, @@ -251,25 +295,30 @@ public abstract class GeneratedMessageLite< * Theses different kinds of operations are required to implement message-level operations for * builders in the runtime. This method bundles those operations to reduce the generated methods * count. + * * <ul> - * <li>{@code MERGE_FROM_STREAM} is parameterized with an {@link CodedInputStream} and - * {@link ExtensionRegistryLite}. It consumes the input stream, parsing the contents into the - * returned protocol buffer. If parsing throws an {@link InvalidProtocolBufferException}, the - * implementation wraps it in a RuntimeException. - * <li>{@code NEW_INSTANCE} returns a new instance of the protocol buffer that has not yet been - * made immutable. See {@code MAKE_IMMUTABLE}. - * <li>{@code IS_INITIALIZED} is parameterized with a {@code Boolean} detailing whether to - * memoize. It returns {@code null} for false and the default instance for true. We optionally - * memoize to support the Builder case, where memoization is not desired. - * <li>{@code NEW_BUILDER} returns a {@code BuilderType} instance. - * <li>{@code VISIT} is parameterized with a {@code Visitor} and a {@code MessageType} and - * recursively iterates through the fields side by side between this and the instance. - * <li>{@code MAKE_IMMUTABLE} sets all internal fields to an immutable state. + * <li>{@code MERGE_FROM_STREAM} is parameterized with an {@link CodedInputStream} and {@link + * ExtensionRegistryLite}. It consumes the input stream, parsing the contents into the + * returned protocol buffer. If parsing throws an {@link InvalidProtocolBufferException}, + * the implementation wraps it in a RuntimeException. + * <li>{@code NEW_INSTANCE} returns a new instance of the protocol buffer that has not yet been + * made immutable. See {@code MAKE_IMMUTABLE}. + * <li>{@code IS_INITIALIZED} returns {@code null} for false and the default instance for true. + * It doesn't use or modify any memoized value. + * <li>{@code GET_MEMOIZED_IS_INITIALIZED} returns the memoized {@code isInitialized} byte + * value. + * <li>{@code SET_MEMOIZED_IS_INITIALIZED} sets the memoized {@code isInitilaized} byte value to + * 1 if the first parameter is not null, or to 0 if the first parameter is null. + * <li>{@code NEW_BUILDER} returns a {@code BuilderType} instance. + * <li>{@code VISIT} is parameterized with a {@code Visitor} and a {@code MessageType} and + * recursively iterates through the fields side by side between this and the instance. + * <li>{@code MAKE_IMMUTABLE} sets all internal fields to an immutable state. * </ul> + * * This method, plus the implementation of the Builder, enables the Builder class to be proguarded * away entirely on Android. - * <p> - * For use by generated code only. + * + * <p>For use by generated code only. */ protected abstract Object dynamicMethod(MethodToInvoke method, Object arg0, Object arg1); @@ -287,14 +336,27 @@ public abstract class GeneratedMessageLite< return dynamicMethod(method, null, null); } + // BEGIN REGULAR void visit(Visitor visitor, MessageType other) { dynamicMethod(MethodToInvoke.VISIT, visitor, other); unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownFields); } + // END REGULAR + + @Override + int getMemoizedSerializedSize() { + return memoizedSerializedSize; + } + + @Override + void setMemoizedSerializedSize(int size) { + memoizedSerializedSize = size; + } + + /** - * Merge some unknown fields into the {@link UnknownFieldSetLite} for this - * message. + * Merge some unknown fields into the {@link UnknownFieldSetLite} for this message. * * <p>For use by generated code only. */ @@ -327,7 +389,7 @@ public abstract class GeneratedMessageLite< if (isBuilt) { MessageType newInstance = (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); - newInstance.visit(MergeFromVisitor.INSTANCE, instance); + mergeFromInstance(newInstance, instance); instance = newInstance; isBuilt = false; } @@ -382,23 +444,60 @@ public abstract class GeneratedMessageLite< /** All subclasses implement this. */ public BuilderType mergeFrom(MessageType message) { copyOnWrite(); - instance.visit(MergeFromVisitor.INSTANCE, message); + mergeFromInstance(instance, message); return (BuilderType) this; } + private void mergeFromInstance(MessageType dest, MessageType src) { + // BEGIN EXPERIMENTAL + // Protobuf.getInstance().schemaFor(dest).mergeFrom(dest, src); + // END EXPERIMENTAL + // BEGIN REGULAR + dest.visit(MergeFromVisitor.INSTANCE, src); + // END REGULAR + } + @Override public MessageType getDefaultInstanceForType() { return defaultInstance; } @Override + public BuilderType mergeFrom(byte[] input, int offset, int length) + throws InvalidProtocolBufferException { + // BEGIN REGULAR + return super.mergeFrom(input, offset, length); + // END REGULAR + // BEGIN EXPERIMENTAL + // copyOnWrite(); + // try { + // Protobuf.getInstance().schemaFor(instance).mergeFrom( + // instance, input, offset, offset + length, new ArrayDecoders.Registers()); + // } catch (InvalidProtocolBufferException e) { + // throw e; + // } catch (IndexOutOfBoundsException e) { + // throw InvalidProtocolBufferException.truncatedMessage(); + // } catch (IOException e) { + // throw new RuntimeException("Reading from byte array should not throw IOException.", e); + // } + // return (BuilderType) this; + // END EXPERIMENTAL + } + + @Override public BuilderType mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws IOException { copyOnWrite(); try { + // BEGIN REGULAR instance.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionRegistry); + // END REGULAR + // BEGIN EXPERIMENTAL + // Protobuf.getInstance().schemaFor(instance).mergeFrom( + // instance, CodedInputStreamReader.forCodedInput(input), extensionRegistry); + // END EXPERIMENTAL } catch (RuntimeException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); @@ -447,12 +546,10 @@ public abstract class GeneratedMessageLite< extends GeneratedMessageLite<MessageType, BuilderType> implements ExtendableMessageOrBuilder<MessageType, BuilderType> { - /** - * Represents the set of extensions on this message. For use by generated - * code only. - */ - protected FieldSet<ExtensionDescriptor> extensions = FieldSet.newFieldSet(); + /** Represents the set of extensions on this message. For use by generated code only. */ + protected FieldSet<ExtensionDescriptor> extensions = FieldSet.emptySet(); + @SuppressWarnings("unchecked") protected final void mergeExtensionFields(final MessageType other) { if (extensions.isImmutable()) { extensions = extensions.clone(); @@ -460,11 +557,13 @@ public abstract class GeneratedMessageLite< extensions.mergeFrom(((ExtendableMessage) other).extensions); } + // BEGIN REGULAR @Override final void visit(Visitor visitor, MessageType other) { super.visit(visitor, other); extensions = visitor.visitExtensions(extensions, other.extensions); } + // END REGULAR /** * Parse an unknown field or an extension. For use by generated code only. @@ -477,7 +576,8 @@ public abstract class GeneratedMessageLite< MessageType defaultInstance, CodedInputStream input, ExtensionRegistryLite extensionRegistry, - int tag) throws IOException { + int tag) + throws IOException { int fieldNumber = WireFormat.getTagFieldNumber(tag); // TODO(dweis): How much bytecode would be saved by not requiring the generated code to @@ -517,7 +617,9 @@ public abstract class GeneratedMessageLite< if (unknown) { // Unknown field or wrong wire type. Skip. return parseUnknownField(tag, input); } - + + ensureExtensionsAreMutable(); + if (packed) { int length = input.readRawVarint32(); int limit = input.pushLimit(length); @@ -732,10 +834,18 @@ public abstract class GeneratedMessageLite< if (subBuilder == null) { subBuilder = extension.getMessageDefaultInstance().newBuilderForType(); } - rawBytes.newCodedInput().readMessage(subBuilder, extensionRegistry); + subBuilder.mergeFrom(rawBytes, extensionRegistry); MessageLite value = subBuilder.build(); - extensions.setField(extension.descriptor, extension.singularToFieldSetType(value)); + ensureExtensionsAreMutable().setField( + extension.descriptor, extension.singularToFieldSetType(value)); + } + + private FieldSet<ExtensionDescriptor> ensureExtensionsAreMutable() { + if (extensions.isImmutable()) { + extensions = extensions.clone(); + } + return extensions; } private void verifyExtensionContainingType( @@ -807,10 +917,12 @@ public abstract class GeneratedMessageLite< @Override protected final void makeImmutable() { super.makeImmutable(); - + // BEGIN REGULAR extensions.makeImmutable(); + // END REGULAR } + /** * Used by subclasses to serialize extensions. Extension ranges may be * interleaved with field numbers, but we must write them in canonical @@ -881,12 +993,6 @@ public abstract class GeneratedMessageLite< implements ExtendableMessageOrBuilder<MessageType, BuilderType> { protected ExtendableBuilder(MessageType defaultInstance) { super(defaultInstance); - - // TODO(dweis): This is kind of an unnecessary clone since we construct a - // new instance in the parent constructor which makes the extensions - // immutable. This extra allocation shouldn't matter in practice - // though. - instance.extensions = instance.extensions.clone(); } // For immutable message conversion. @@ -905,6 +1011,15 @@ public abstract class GeneratedMessageLite< instance.extensions = instance.extensions.clone(); } + private FieldSet<ExtensionDescriptor> ensureExtensionsAreMutable() { + FieldSet<ExtensionDescriptor> extensions = instance.extensions; + if (extensions.isImmutable()) { + extensions = extensions.clone(); + instance.extensions = extensions; + } + return extensions; + } + @Override public final MessageType buildPartial() { if (isBuilt) { @@ -963,7 +1078,8 @@ public abstract class GeneratedMessageLite< verifyExtensionContainingType(extensionLite); copyOnWrite(); - instance.extensions.setField(extensionLite.descriptor, extensionLite.toFieldSetType(value)); + ensureExtensionsAreMutable() + .setField(extensionLite.descriptor, extensionLite.toFieldSetType(value)); return (BuilderType) this; } @@ -976,8 +1092,9 @@ public abstract class GeneratedMessageLite< verifyExtensionContainingType(extensionLite); copyOnWrite(); - instance.extensions.setRepeatedField( - extensionLite.descriptor, index, extensionLite.singularToFieldSetType(value)); + ensureExtensionsAreMutable() + .setRepeatedField( + extensionLite.descriptor, index, extensionLite.singularToFieldSetType(value)); return (BuilderType) this; } @@ -990,8 +1107,8 @@ public abstract class GeneratedMessageLite< verifyExtensionContainingType(extensionLite); copyOnWrite(); - instance.extensions.addRepeatedField( - extensionLite.descriptor, extensionLite.singularToFieldSetType(value)); + ensureExtensionsAreMutable() + .addRepeatedField(extensionLite.descriptor, extensionLite.singularToFieldSetType(value)); return (BuilderType) this; } @@ -1002,7 +1119,7 @@ public abstract class GeneratedMessageLite< verifyExtensionContainingType(extensionLite); copyOnWrite(); - instance.extensions.clearField(extensionLite.descriptor); + ensureExtensionsAreMutable().clearField(extensionLite.descriptor); return (BuilderType) this; } } @@ -1152,6 +1269,7 @@ public abstract class GeneratedMessageLite< } } + /** * Lite equivalent to {@link GeneratedMessage.GeneratedExtension}. * @@ -1392,11 +1510,26 @@ public abstract class GeneratedMessageLite< */ protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitialized( T message, boolean shouldMemoize) { - return message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, shouldMemoize) != null; - } - - protected static final <T extends GeneratedMessageLite<T, ?>> void makeImmutable(T message) { - message.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE); + byte memoizedIsInitialized = + (Byte) message.dynamicMethod(MethodToInvoke.GET_MEMOIZED_IS_INITIALIZED); + if (memoizedIsInitialized == 1) { + return true; + } + if (memoizedIsInitialized == 0) { + return false; + } + // BEGIN EXPERIMENTAL + // boolean isInitialized = Protobuf.getInstance().schemaFor(message).isInitialized(message); + // END EXPERIMENTAL + // BEGIN REGULAR + boolean isInitialized = + message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, Boolean.FALSE) != null; + // END REGULAR + if (shouldMemoize) { + message.dynamicMethod( + MethodToInvoke.SET_MEMOIZED_IS_INITIALIZED, isInitialized ? message : null); + } + return isInitialized; } protected static IntList emptyIntList() { @@ -1478,6 +1611,11 @@ public abstract class GeneratedMessageLite< throws InvalidProtocolBufferException { return GeneratedMessageLite.parsePartialFrom(defaultInstance, input, extensionRegistry); } + + @Override + public T parsePartialFrom(byte[] input) throws InvalidProtocolBufferException { + return GeneratedMessageLite.parsePartialFrom(defaultInstance, input); + } } /** @@ -1491,8 +1629,21 @@ public abstract class GeneratedMessageLite< @SuppressWarnings("unchecked") // Guaranteed by protoc T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); try { + // BEGIN REGULAR result.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionRegistry); + // END REGULAR + // BEGIN EXPERIMENTAL + // Protobuf.getInstance().schemaFor(result).mergeFrom( + // result, CodedInputStreamReader.forCodedInput(input), extensionRegistry); + // END EXPERIMENTAL result.makeImmutable(); + // BEGIN EXPERIMENTAL + // } catch (IOException e) { + // if (e.getCause() instanceof InvalidProtocolBufferException) { + // throw (InvalidProtocolBufferException) e.getCause(); + // } + // throw new InvalidProtocolBufferException(e.getMessage()).setUnfinishedMessage(result); + // END EXPERIMENTAL } catch (RuntimeException e) { if (e.getCause() instanceof InvalidProtocolBufferException) { throw (InvalidProtocolBufferException) e.getCause(); @@ -1502,6 +1653,34 @@ public abstract class GeneratedMessageLite< return result; } + /** A static helper method for parsing a partial from byte array. */ + static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(T instance, byte[] input) + throws InvalidProtocolBufferException { + // BEGIN REGULAR + return parsePartialFrom(instance, input, ExtensionRegistryLite.getEmptyRegistry()); + // END REGULAR + // BEGIN EXPERIMENTAL + // @SuppressWarnings("unchecked") // Guaranteed by protoc + // T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE); + // try { + // Protobuf.getInstance().schemaFor(result).mergeFrom( + // result, input, 0, input.length, new ArrayDecoders.Registers()); + // result.makeImmutable(); + // if (result.memoizedHashCode != 0) { + // throw new RuntimeException(); + // } + // } catch (IOException e) { + // if (e.getCause() instanceof InvalidProtocolBufferException) { + // throw (InvalidProtocolBufferException) e.getCause(); + // } + // throw new InvalidProtocolBufferException(e.getMessage()).setUnfinishedMessage(result); + // } catch (IndexOutOfBoundsException e) { + // throw InvalidProtocolBufferException.truncatedMessage().setUnfinishedMessage(result); + // } + // return result; + // END EXPERIMENTAL + } + protected static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom( T defaultInstance, CodedInputStream input) @@ -1527,6 +1706,20 @@ public abstract class GeneratedMessageLite< // Validates last tag. protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom( + T defaultInstance, ByteBuffer data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parseFrom(defaultInstance, CodedInputStream.newInstance(data), extensionRegistry)); + } + + // Validates last tag. + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom( + T defaultInstance, ByteBuffer data) throws InvalidProtocolBufferException { + return parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry()); + } + + // Validates last tag. + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom( T defaultInstance, ByteString data) throws InvalidProtocolBufferException { return checkMessageInitialized( @@ -1584,8 +1777,7 @@ public abstract class GeneratedMessageLite< protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom( T defaultInstance, byte[] data) throws InvalidProtocolBufferException { - return checkMessageInitialized( - parsePartialFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry())); + return checkMessageInitialized(parsePartialFrom(defaultInstance, data)); } // Validates last tag. @@ -1670,6 +1862,7 @@ public abstract class GeneratedMessageLite< return message; } + // BEGIN REGULAR /** * An abstract visitor that the generated code calls into that we use to implement various * features. Fields that are not members of oneofs are always visited. Members of a oneof are only @@ -1693,7 +1886,6 @@ public abstract class GeneratedMessageLite< Object visitOneofLong(boolean minePresent, Object mine, Object other); Object visitOneofString(boolean minePresent, Object mine, Object other); Object visitOneofByteString(boolean minePresent, Object mine, Object other); - Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other); Object visitOneofMessage(boolean minePresent, Object mine, Object other); void visitOneofNotSet(boolean minePresent); @@ -1701,7 +1893,6 @@ public abstract class GeneratedMessageLite< * Message fields use null sentinals. */ <T extends MessageLite> T visitMessage(T mine, T other); - LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other); <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other); BooleanList visitBooleanList(BooleanList mine, BooleanList other); @@ -1845,14 +2036,6 @@ public abstract class GeneratedMessageLite< } @Override - public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) { - if (minePresent && mine.equals(other)) { - return mine; - } - throw NOT_EQUALS; - } - - @Override public Object visitOneofMessage(boolean minePresent, Object mine, Object other) { if (minePresent && ((GeneratedMessageLite<?, ?>) mine).equals(this, (MessageLite) other)) { return mine; @@ -1883,21 +2066,6 @@ public abstract class GeneratedMessageLite< } @Override - public LazyFieldLite visitLazyMessage( - LazyFieldLite mine, LazyFieldLite other) { - if (mine == null && other == null) { - return null; - } - if (mine == null || other == null) { - throw NOT_EQUALS; - } - if (mine.equals(other)) { - return mine; - } - throw NOT_EQUALS; - } - - @Override public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) { if (!mine.equals(other)) { throw NOT_EQUALS; @@ -1977,13 +2145,13 @@ public abstract class GeneratedMessageLite< /** * Implements hashCode by accumulating state. */ - private static class HashCodeVisitor implements Visitor { + static class HashCodeVisitor implements Visitor { // The caller must ensure that the visitor is invoked parameterized with this and this such that // other is this. This is required due to how oneof cases are handled. See the class comment // on Visitor for more information. - private int hashCode = 0; + int hashCode = 0; @Override public boolean visitBoolean( @@ -2074,12 +2242,6 @@ public abstract class GeneratedMessageLite< } @Override - public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) { - hashCode = (53 * hashCode) + mine.hashCode(); - return mine; - } - - @Override public Object visitOneofMessage(boolean minePresent, Object mine, Object other) { return visitMessage((MessageLite) mine, (MessageLite) other); } @@ -2108,18 +2270,6 @@ public abstract class GeneratedMessageLite< } @Override - public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other) { - final int protoHash; - if (mine != null) { - protoHash = mine.hashCode(); - } else { - protoHash = 37; - } - hashCode = (53 * hashCode) + protoHash; - return mine; - } - - @Override public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) { hashCode = (53 * hashCode) + mine.hashCode(); return mine; @@ -2262,13 +2412,6 @@ public abstract class GeneratedMessageLite< } @Override - public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) { - LazyFieldLite lazy = minePresent ? (LazyFieldLite) mine : new LazyFieldLite(); - lazy.merge((LazyFieldLite) other); - return lazy; - } - - @Override public Object visitOneofMessage(boolean minePresent, Object mine, Object other) { if (minePresent) { return visitMessage((MessageLite) mine, (MessageLite) other); @@ -2292,17 +2435,6 @@ public abstract class GeneratedMessageLite< } @Override - public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other) { - if (other != null) { - if (mine == null) { - mine = new LazyFieldLite(); - } - mine.merge(other); - } - return mine; - } - - @Override public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) { int size = mine.size(); int otherSize = other.size(); @@ -2416,4 +2548,5 @@ public abstract class GeneratedMessageLite< return mine; } } + // END REGULAR } |