Breaking Change: The base class for generated messages will be

GeneratedMessage, not GeneratedMessageV3.

Please rerun protoc on your .proto files to regenerate the binding code.
https://protobuf.dev/news/2023-12-05/
https://protobuf.dev/support/cross-version-runtime-guarantee/

To fix source compatibility with surrounding code make these replacements:
GeneratedMessageV3 --> GeneratedMessage
SingleFieldBuilderV3 --> SingleFieldBuilder
RepeatedFieldBuilderV3 --> RepeatedFieldBuilder

PiperOrigin-RevId: 597642289
pull/15362/head
Protobuf Team Bot 11 months ago committed by Copybara-Service
parent 81e5433f5c
commit 5df0387224
  1. 4
      java/core/BUILD.bazel
  2. 6
      java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
  3. 4
      java/core/src/main/java/com/google/protobuf/ExtensionSchemaFull.java
  4. 2014
      java/core/src/main/java/com/google/protobuf/GeneratedMessage.java
  5. 3421
      java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
  6. 4
      java/core/src/main/java/com/google/protobuf/NewInstanceSchemaFull.java
  7. 647
      java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
  8. 6
      java/core/src/main/java/com/google/protobuf/SchemaUtil.java
  9. 210
      java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
  10. 8
      java/core/src/main/java/com/google/protobuf/UnknownFieldSetSchema.java
  11. 8
      java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java
  12. 26
      java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java
  13. 20
      java/core/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java
  14. 14
      java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt
  15. 4
      java/lite/pom.xml
  16. 4
      src/google/protobuf/compiler/java/helpers.h
  17. 4
      src/google/protobuf/compiler/java/map_field.cc
  18. 70
      src/google/protobuf/compiler/java/message.cc
  19. 26
      src/google/protobuf/compiler/java/message_builder.cc
  20. 21
      src/google/protobuf/compiler/java/message_field.cc
  21. 9
      src/google/protobuf/compiler/java/string_field.cc

@ -486,10 +486,10 @@ LITE_TEST_EXCLUSIONS = [
"src/test/java/com/google/protobuf/Proto2ExtensionLookupSchemaTest.java", "src/test/java/com/google/protobuf/Proto2ExtensionLookupSchemaTest.java",
"src/test/java/com/google/protobuf/Proto2SchemaTest.java", "src/test/java/com/google/protobuf/Proto2SchemaTest.java",
"src/test/java/com/google/protobuf/Proto2UnknownEnumValueTest.java", "src/test/java/com/google/protobuf/Proto2UnknownEnumValueTest.java",
"src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java", "src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java",
"src/test/java/com/google/protobuf/RuntimeVersionTest.java", "src/test/java/com/google/protobuf/RuntimeVersionTest.java",
"src/test/java/com/google/protobuf/ServiceTest.java", "src/test/java/com/google/protobuf/ServiceTest.java",
"src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java", "src/test/java/com/google/protobuf/SingleFieldBuilderTest.java",
"src/test/java/com/google/protobuf/TestBadIdentifiers.java", "src/test/java/com/google/protobuf/TestBadIdentifiers.java",
"src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java", "src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java",
"src/test/java/com/google/protobuf/TextFormatParseLocationTest.java", "src/test/java/com/google/protobuf/TextFormatParseLocationTest.java",

@ -34,7 +34,7 @@ import java.util.Set;
import java.util.Stack; import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** A factory for message info based on protobuf descriptors for a {@link GeneratedMessageV3}. */ /** A factory for message info based on protobuf descriptors for a {@link GeneratedMessage}. */
@ExperimentalApi @ExperimentalApi
final class DescriptorMessageInfoFactory implements MessageInfoFactory { final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance"; private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
@ -74,12 +74,12 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
@Override @Override
public boolean isSupported(Class<?> messageType) { public boolean isSupported(Class<?> messageType) {
return GeneratedMessageV3.class.isAssignableFrom(messageType); return GeneratedMessage.class.isAssignableFrom(messageType);
} }
@Override @Override
public MessageInfo messageInfoFor(Class<?> messageType) { public MessageInfo messageInfoFor(Class<?> messageType) {
if (!GeneratedMessageV3.class.isAssignableFrom(messageType)) { if (!GeneratedMessage.class.isAssignableFrom(messageType)) {
throw new IllegalArgumentException("Unsupported message type: " + messageType.getName()); throw new IllegalArgumentException("Unsupported message type: " + messageType.getName());
} }

@ -23,7 +23,7 @@ final class ExtensionSchemaFull extends ExtensionSchema<FieldDescriptor> {
private static <T> long getExtensionsFieldOffset() { private static <T> long getExtensionsFieldOffset() {
try { try {
Field field = GeneratedMessageV3.ExtendableMessage.class.getDeclaredField("extensions"); Field field = GeneratedMessage.ExtendableMessage.class.getDeclaredField("extensions");
return UnsafeUtil.objectFieldOffset(field); return UnsafeUtil.objectFieldOffset(field);
} catch (Throwable e) { } catch (Throwable e) {
throw new IllegalStateException("Unable to lookup extension field offset"); throw new IllegalStateException("Unable to lookup extension field offset");
@ -32,7 +32,7 @@ final class ExtensionSchemaFull extends ExtensionSchema<FieldDescriptor> {
@Override @Override
boolean hasExtensions(MessageLite prototype) { boolean hasExtensions(MessageLite prototype) {
return prototype instanceof GeneratedMessageV3.ExtendableMessage; return prototype instanceof GeneratedMessage.ExtendableMessage;
} }
@Override @Override

@ -10,7 +10,7 @@ package com.google.protobuf;
final class NewInstanceSchemaFull implements NewInstanceSchema { final class NewInstanceSchemaFull implements NewInstanceSchema {
@Override @Override
public Object newInstance(Object defaultInstance) { public Object newInstance(Object defaultInstance) {
return ((GeneratedMessageV3) defaultInstance) return ((GeneratedMessage) defaultInstance)
.newInstance(GeneratedMessageV3.UnusedPrivateParameter.INSTANCE); .newInstance(GeneratedMessage.UnusedPrivateParameter.INSTANCE);
} }
} }

@ -1,647 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.RandomAccess;
/**
* {@code RepeatedFieldBuilderV3} implements a structure that a protocol message uses to hold a
* repeated field of other protocol messages. It supports the classical use case of adding immutable
* {@link Message}'s to the repeated field and is highly optimized around this (no extra memory
* allocations and sharing of immutable arrays). <br>
* It also supports the additional use case of adding a {@link Message.Builder} to the repeated
* field and deferring conversion of that {@code Builder} to an immutable {@code Message}. In this
* way, it's possible to maintain a tree of {@code Builder}'s that acts as a fully read/write data
* structure. <br>
* Logically, one can think of a tree of builders as converting the entire tree to messages when
* build is called on the root or when any method is called that desires a Message instead of a
* Builder. In terms of the implementation, the {@code SingleFieldBuilderV3} and {@code
* RepeatedFieldBuilderV3} classes cache messages that were created so that messages only need to be
* created when some change occurred in its builder or a builder for one of its descendants.
*
* @param <MType> the type of message for the field
* @param <BType> the type of builder for the field
* @param <IType> the common interface for the message and the builder
* @author jonp@google.com (Jon Perlow)
*/
public class RepeatedFieldBuilderV3<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
implements AbstractMessage.BuilderParent {
// Parent to send changes to.
private AbstractMessage.BuilderParent parent;
// List of messages. Never null. It may be immutable, in which case
// isMessagesListMutable will be false. See note below.
private List<MType> messages;
// Whether messages is an mutable array that can be modified.
private boolean isMessagesListMutable;
// List of builders. May be null, in which case, no nested builders were
// created. If not null, entries represent the builder for that index.
private List<SingleFieldBuilderV3<MType, BType, IType>> builders;
// Here are the invariants for messages and builders:
// 1. messages is never null and its count corresponds to the number of items
// in the repeated field.
// 2. If builders is non-null, messages and builders MUST always
// contain the same number of items.
// 3. Entries in either array can be null, but for any index, there MUST be
// either a Message in messages or a builder in builders.
// 4. If the builder at an index is non-null, the builder is
// authoritative. This is the case where a Builder was set on the index.
// Any message in the messages array MUST be ignored.
// t. If the builder at an index is null, the message in the messages
// list is authoritative. This is the case where a Message (not a Builder)
// was set directly for an index.
// Indicates that we've built a message and so we are now obligated
// to dispatch dirty invalidations. See AbstractMessage.BuilderListener.
private boolean isClean;
// A view of this builder that exposes a List interface of messages. This is
// initialized on demand. This is fully backed by this object and all changes
// are reflected in it. Access to any item converts it to a message if it
// was a builder.
private MessageExternalList<MType, BType, IType> externalMessageList;
// A view of this builder that exposes a List interface of builders. This is
// initialized on demand. This is fully backed by this object and all changes
// are reflected in it. Access to any item converts it to a builder if it
// was a message.
private BuilderExternalList<MType, BType, IType> externalBuilderList;
// A view of this builder that exposes a List interface of the interface
// implemented by messages and builders. This is initialized on demand. This
// is fully backed by this object and all changes are reflected in it.
// Access to any item returns either a builder or message depending on
// what is most efficient.
private MessageOrBuilderExternalList<MType, BType, IType> externalMessageOrBuilderList;
/**
* Constructs a new builder with an empty list of messages.
*
* @param messages the current list of messages
* @param isMessagesListMutable Whether the messages list is mutable
* @param parent a listener to notify of changes
* @param isClean whether the builder is initially marked clean
*/
public RepeatedFieldBuilderV3(
List<MType> messages,
boolean isMessagesListMutable,
AbstractMessage.BuilderParent parent,
boolean isClean) {
this.messages = messages;
this.isMessagesListMutable = isMessagesListMutable;
this.parent = parent;
this.isClean = isClean;
}
public void dispose() {
// Null out parent so we stop sending it invalidations.
parent = null;
}
/**
* Ensures that the list of messages is mutable so it can be updated. If it's immutable, a copy is
* made.
*/
private void ensureMutableMessageList() {
if (!isMessagesListMutable) {
messages = new ArrayList<MType>(messages);
isMessagesListMutable = true;
}
}
/**
* Ensures that the list of builders is not null. If it's null, the list is created and
* initialized to be the same size as the messages list with null entries.
*/
private void ensureBuilders() {
if (this.builders == null) {
this.builders = new ArrayList<SingleFieldBuilderV3<MType, BType, IType>>(messages.size());
for (int i = 0; i < messages.size(); i++) {
builders.add(null);
}
}
}
/**
* Gets the count of items in the list.
*
* @return the count of items in the list.
*/
public int getCount() {
return messages.size();
}
/**
* Gets whether the list is empty.
*
* @return whether the list is empty
*/
public boolean isEmpty() {
return messages.isEmpty();
}
/**
* Get the message at the specified index. If the message is currently stored as a {@code
* Builder}, it is converted to a {@code Message} by calling {@link Message.Builder#buildPartial}
* on it.
*
* @param index the index of the message to get
* @return the message for the specified index
*/
public MType getMessage(int index) {
return getMessage(index, false);
}
/**
* Get the message at the specified index. If the message is currently stored as a {@code
* Builder}, it is converted to a {@code Message} by calling {@link Message.Builder#buildPartial}
* on it.
*
* @param index the index of the message to get
* @param forBuild this is being called for build so we want to make sure we
* SingleFieldBuilderV3.build to send dirty invalidations
* @return the message for the specified index
*/
private MType getMessage(int index, boolean forBuild) {
if (this.builders == null) {
// We don't have any builders -- return the current Message.
// This is the case where no builder was created, so we MUST have a
// Message.
return messages.get(index);
}
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
if (builder == null) {
// We don't have a builder -- return the current message.
// This is the case where no builder was created for the entry at index,
// so we MUST have a message.
return messages.get(index);
} else {
return forBuild ? builder.build() : builder.getMessage();
}
}
/**
* Gets a builder for the specified index. If no builder has been created for that index, a
* builder is created on demand by calling {@link Message#toBuilder}.
*
* @param index the index of the message to get
* @return The builder for that index
*/
public BType getBuilder(int index) {
ensureBuilders();
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
if (builder == null) {
MType message = messages.get(index);
builder = new SingleFieldBuilderV3<MType, BType, IType>(message, this, isClean);
builders.set(index, builder);
}
return builder.getBuilder();
}
/**
* Gets the base class interface for the specified index. This may either be a builder or a
* message. It will return whatever is more efficient.
*
* @param index the index of the message to get
* @return the message or builder for the index as the base class interface
*/
@SuppressWarnings("unchecked")
public IType getMessageOrBuilder(int index) {
if (this.builders == null) {
// We don't have any builders -- return the current Message.
// This is the case where no builder was created, so we MUST have a
// Message.
return (IType) messages.get(index);
}
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
if (builder == null) {
// We don't have a builder -- return the current message.
// This is the case where no builder was created for the entry at index,
// so we MUST have a message.
return (IType) messages.get(index);
} else {
return builder.getMessageOrBuilder();
}
}
/**
* Sets a message at the specified index replacing the existing item at that index.
*
* @param index the index to set.
* @param message the message to set
* @return the builder
*/
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> setMessage(int index, MType message) {
checkNotNull(message);
ensureMutableMessageList();
messages.set(index, message);
if (builders != null) {
SingleFieldBuilderV3<MType, BType, IType> entry = builders.set(index, null);
if (entry != null) {
entry.dispose();
}
}
onChanged();
incrementModCounts();
return this;
}
/**
* Appends the specified element to the end of this list.
*
* @param message the message to add
* @return the builder
*/
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(MType message) {
checkNotNull(message);
ensureMutableMessageList();
messages.add(message);
if (builders != null) {
builders.add(null);
}
onChanged();
incrementModCounts();
return this;
}
/**
* Inserts the specified message at the specified position in this list. Shifts the element
* currently at that position (if any) and any subsequent elements to the right (adds one to their
* indices).
*
* @param index the index at which to insert the message
* @param message the message to add
* @return the builder
*/
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(int index, MType message) {
checkNotNull(message);
ensureMutableMessageList();
messages.add(index, message);
if (builders != null) {
builders.add(index, null);
}
onChanged();
incrementModCounts();
return this;
}
/**
* Appends all of the messages in the specified collection to the end of this list, in the order
* that they are returned by the specified collection's iterator.
*
* @param values the messages to add
* @return the builder
*/
@CanIgnoreReturnValue
public RepeatedFieldBuilderV3<MType, BType, IType> addAllMessages(
Iterable<? extends MType> values) {
for (final MType value : values) {
checkNotNull(value);
}
// If we can inspect the size, we can more efficiently add messages.
int size = -1;
if (values instanceof Collection) {
final Collection<?> collection = (Collection<?>) values;
if (collection.isEmpty()) {
return this;
}
size = collection.size();
}
ensureMutableMessageList();
if (size >= 0 && messages instanceof ArrayList) {
((ArrayList<MType>) messages).ensureCapacity(messages.size() + size);
}
for (MType value : values) {
addMessage(value);
}
onChanged();
incrementModCounts();
return this;
}
/**
* Appends a new builder to the end of this list and returns the builder.
*
* @param message the message to add which is the basis of the builder
* @return the new builder
*/
public BType addBuilder(MType message) {
ensureMutableMessageList();
ensureBuilders();
SingleFieldBuilderV3<MType, BType, IType> builder =
new SingleFieldBuilderV3<MType, BType, IType>(message, this, isClean);
messages.add(null);
builders.add(builder);
onChanged();
incrementModCounts();
return builder.getBuilder();
}
/**
* Inserts a new builder at the specified position in this list. Shifts the element currently at
* that position (if any) and any subsequent elements to the right (adds one to their indices).
*
* @param index the index at which to insert the builder
* @param message the message to add which is the basis of the builder
* @return the builder
*/
public BType addBuilder(int index, MType message) {
ensureMutableMessageList();
ensureBuilders();
SingleFieldBuilderV3<MType, BType, IType> builder =
new SingleFieldBuilderV3<MType, BType, IType>(message, this, isClean);
messages.add(index, null);
builders.add(index, builder);
onChanged();
incrementModCounts();
return builder.getBuilder();
}
/**
* Removes the element at the specified position in this list. Shifts any subsequent elements to
* the left (subtracts one from their indices).
*
* @param index the index at which to remove the message
*/
public void remove(int index) {
ensureMutableMessageList();
messages.remove(index);
if (builders != null) {
SingleFieldBuilderV3<MType, BType, IType> entry = builders.remove(index);
if (entry != null) {
entry.dispose();
}
}
onChanged();
incrementModCounts();
}
/** Removes all of the elements from this list. The list will be empty after this call returns. */
public void clear() {
messages = Collections.emptyList();
isMessagesListMutable = false;
if (builders != null) {
for (SingleFieldBuilderV3<MType, BType, IType> entry : builders) {
if (entry != null) {
entry.dispose();
}
}
builders = null;
}
onChanged();
incrementModCounts();
}
/**
* Builds the list of messages from the builder and returns them.
*
* @return an immutable list of messages
*/
public List<MType> build() {
// Now that build has been called, we are required to dispatch
// invalidations.
isClean = true;
if (!isMessagesListMutable && builders == null) {
// We still have an immutable list and we never created a builder.
return messages;
}
boolean allMessagesInSync = true;
if (!isMessagesListMutable) {
// We still have an immutable list. Let's see if any of them are out
// of sync with their builders.
for (int i = 0; i < messages.size(); i++) {
Message message = messages.get(i);
SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(i);
if (builder != null) {
if (builder.build() != message) {
allMessagesInSync = false;
break;
}
}
}
if (allMessagesInSync) {
// Immutable list is still in sync.
return messages;
}
}
// Need to make sure messages is up to date
ensureMutableMessageList();
for (int i = 0; i < messages.size(); i++) {
messages.set(i, getMessage(i, true));
}
// We're going to return our list as immutable so we mark that we can
// no longer update it.
messages = Collections.unmodifiableList(messages);
isMessagesListMutable = false;
return messages;
}
/**
* Gets a view of the builder as a list of messages. The returned list is live and will reflect
* any changes to the underlying builder.
*
* @return the messages in the list
*/
public List<MType> getMessageList() {
if (externalMessageList == null) {
externalMessageList = new MessageExternalList<MType, BType, IType>(this);
}
return externalMessageList;
}
/**
* Gets a view of the builder as a list of builders. This returned list is live and will reflect
* any changes to the underlying builder.
*
* @return the builders in the list
*/
public List<BType> getBuilderList() {
if (externalBuilderList == null) {
externalBuilderList = new BuilderExternalList<MType, BType, IType>(this);
}
return externalBuilderList;
}
/**
* Gets a view of the builder as a list of MessageOrBuilders. This returned list is live and will
* reflect any changes to the underlying builder.
*
* @return the builders in the list
*/
public List<IType> getMessageOrBuilderList() {
if (externalMessageOrBuilderList == null) {
externalMessageOrBuilderList = new MessageOrBuilderExternalList<MType, BType, IType>(this);
}
return externalMessageOrBuilderList;
}
/**
* Called when a the builder or one of its nested children has changed and any parent should be
* notified of its invalidation.
*/
private void onChanged() {
if (isClean && parent != null) {
parent.markDirty();
// Don't keep dispatching invalidations until build is called again.
isClean = false;
}
}
@Override
public void markDirty() {
onChanged();
}
/**
* Increments the mod counts so that an ConcurrentModificationException can be thrown if calling
* code tries to modify the builder while its iterating the list.
*/
private void incrementModCounts() {
if (externalMessageList != null) {
externalMessageList.incrementModCount();
}
if (externalBuilderList != null) {
externalBuilderList.incrementModCount();
}
if (externalMessageOrBuilderList != null) {
externalMessageOrBuilderList.incrementModCount();
}
}
/**
* Provides a live view of the builder as a list of messages.
*
* @param <MType> the type of message for the field
* @param <BType> the type of builder for the field
* @param <IType> the common interface for the message and the builder
*/
private static class MessageExternalList<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends AbstractList<MType> implements List<MType>, RandomAccess {
RepeatedFieldBuilderV3<MType, BType, IType> builder;
MessageExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder) {
this.builder = builder;
}
@Override
public int size() {
return this.builder.getCount();
}
@Override
public MType get(int index) {
return builder.getMessage(index);
}
void incrementModCount() {
modCount++;
}
}
/**
* Provides a live view of the builder as a list of builders.
*
* @param <MType> the type of message for the field
* @param <BType> the type of builder for the field
* @param <IType> the common interface for the message and the builder
*/
private static class BuilderExternalList<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends AbstractList<BType> implements List<BType>, RandomAccess {
RepeatedFieldBuilderV3<MType, BType, IType> builder;
BuilderExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder) {
this.builder = builder;
}
@Override
public int size() {
return this.builder.getCount();
}
@Override
public BType get(int index) {
return builder.getBuilder(index);
}
void incrementModCount() {
modCount++;
}
}
/**
* Provides a live view of the builder as a list of builders.
*
* @param <MType> the type of message for the field
* @param <BType> the type of builder for the field
* @param <IType> the common interface for the message and the builder
*/
private static class MessageOrBuilderExternalList<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
extends AbstractList<IType> implements List<IType>, RandomAccess {
RepeatedFieldBuilderV3<MType, BType, IType> builder;
MessageOrBuilderExternalList(RepeatedFieldBuilderV3<MType, BType, IType> builder) {
this.builder = builder;
}
@Override
public int size() {
return this.builder.getCount();
}
@Override
public IType get(int index) {
return builder.getMessageOrBuilder(index);
}
void incrementModCount() {
modCount++;
}
}
}

@ -31,7 +31,7 @@ final class SchemaUtil {
private SchemaUtil() {} private SchemaUtil() {}
/** /**
* Requires that the given message extend {@link com.google.protobuf.GeneratedMessageV3} or {@link * Requires that the given message extend {@link com.google.protobuf.GeneratedMessage} or {@link
* GeneratedMessageLite}. * GeneratedMessageLite}.
*/ */
public static void requireGeneratedMessage(Class<?> messageType) { public static void requireGeneratedMessage(Class<?> messageType) {
@ -41,7 +41,7 @@ final class SchemaUtil {
&& GENERATED_MESSAGE_CLASS != null && GENERATED_MESSAGE_CLASS != null
&& !GENERATED_MESSAGE_CLASS.isAssignableFrom(messageType)) { && !GENERATED_MESSAGE_CLASS.isAssignableFrom(messageType)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Message classes must extend GeneratedMessageV3 or GeneratedMessageLite"); "Message classes must extend GeneratedMessage or GeneratedMessageLite");
} }
} }
@ -784,7 +784,7 @@ final class SchemaUtil {
try { try {
// TODO decide if we're keeping support for Full in schema classes and handle // TODO decide if we're keeping support for Full in schema classes and handle
// this better. // this better.
return Class.forName("com.google.protobuf.GeneratedMessageV3"); return Class.forName("com.google.protobuf.GeneratedMessage");
} catch (Throwable e) { } catch (Throwable e) {
return null; return null;
} }

@ -1,210 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
/**
* {@code SingleFieldBuilderV3} implements a structure that a protocol message uses to hold a single
* field of another protocol message. It supports the classical use case of setting an immutable
* {@link Message} as the value of the field and is highly optimized around this.
*
* <p>It also supports the additional use case of setting a {@link Message.Builder} as the field and
* deferring conversion of that {@code Builder} to an immutable {@code Message}. In this way, it's
* possible to maintain a tree of {@code Builder}'s that acts as a fully read/write data structure.
* <br>
* Logically, one can think of a tree of builders as converting the entire tree to messages when
* build is called on the root or when any method is called that desires a Message instead of a
* Builder. In terms of the implementation, the {@code SingleFieldBuilderV3} and {@code
* RepeatedFieldBuilderV3} classes cache messages that were created so that messages only need to be
* created when some change occurred in its builder or a builder for one of its descendants.
*
* @param <MType> the type of message for the field
* @param <BType> the type of builder for the field
* @param <IType> the common interface for the message and the builder
* @author jonp@google.com (Jon Perlow)
*/
public class SingleFieldBuilderV3<
MType extends AbstractMessage,
BType extends AbstractMessage.Builder,
IType extends MessageOrBuilder>
implements AbstractMessage.BuilderParent {
// Parent to send changes to.
private AbstractMessage.BuilderParent parent;
// Invariant: one of builder or message fields must be non-null.
// If set, this is the case where we are backed by a builder. In this case,
// message field represents a cached message for the builder (or null if
// there is no cached message).
private BType builder;
// If builder is non-null, this represents a cached message from the builder.
// If builder is null, this is the authoritative message for the field.
private MType message;
// Indicates that we've built a message and so we are now obligated
// to dispatch dirty invalidations. See AbstractMessage.BuilderListener.
private boolean isClean;
public SingleFieldBuilderV3(MType message, AbstractMessage.BuilderParent parent, boolean isClean) {
this.message = checkNotNull(message);
this.parent = parent;
this.isClean = isClean;
}
public void dispose() {
// Null out parent so we stop sending it invalidations.
parent = null;
}
/**
* Get the message for the field. If the message is currently stored as a {@code Builder}, it is
* converted to a {@code Message} by calling {@link Message.Builder#buildPartial} on it. If no
* message has been set, returns the default instance of the message.
*
* @return the message for the field
*/
@SuppressWarnings("unchecked")
public MType getMessage() {
if (message == null) {
// If message is null, the invariant is that we must be have a builder.
message = (MType) builder.buildPartial();
}
return message;
}
/**
* Builds the message and returns it.
*
* @return the message
*/
public MType build() {
// Now that build has been called, we are required to dispatch
// invalidations.
isClean = true;
return getMessage();
}
/**
* Gets a builder for the field. If no builder has been created yet, a builder is created on
* demand by calling {@link Message#toBuilder}.
*
* @return The builder for the field
*/
@SuppressWarnings("unchecked")
public BType getBuilder() {
if (builder == null) {
// builder.mergeFrom() on a fresh builder
// does not create any sub-objects with independent clean/dirty states,
// therefore setting the builder itself to clean without actually calling
// build() cannot break any invariants.
builder = (BType) message.newBuilderForType(this);
builder.mergeFrom(message); // no-op if message is the default message
builder.markClean();
}
return builder;
}
/**
* Gets the base class interface for the field. This may either be a builder or a message. It will
* return whatever is more efficient.
*
* @return the message or builder for the field as the base class interface
*/
@SuppressWarnings("unchecked")
public IType getMessageOrBuilder() {
if (builder != null) {
return (IType) builder;
} else {
return (IType) message;
}
}
/**
* Sets a message for the field replacing any existing value.
*
* @param message the message to set
* @return the builder
*/
@CanIgnoreReturnValue
public SingleFieldBuilderV3<MType, BType, IType> setMessage(MType message) {
this.message = checkNotNull(message);
if (builder != null) {
builder.dispose();
builder = null;
}
onChanged();
return this;
}
/**
* Merges the field from another field.
*
* @param value the value to merge from
* @return the builder
*/
@CanIgnoreReturnValue
public SingleFieldBuilderV3<MType, BType, IType> mergeFrom(MType value) {
if (builder == null && message == message.getDefaultInstanceForType()) {
message = value;
} else {
getBuilder().mergeFrom(value);
}
onChanged();
return this;
}
/**
* Clears the value of the field.
*
* @return the builder
*/
@SuppressWarnings("unchecked")
@CanIgnoreReturnValue
public SingleFieldBuilderV3<MType, BType, IType> clear() {
message =
(MType)
(message != null
? message.getDefaultInstanceForType()
: builder.getDefaultInstanceForType());
if (builder != null) {
builder.dispose();
builder = null;
}
onChanged();
// After clearing, parent is dirty, but this field builder is now clean and any changes should
// trickle up.
isClean = true;
return this;
}
/**
* Called when a the builder or one of its nested children has changed and any parent should be
* notified of its invalidation.
*/
private void onChanged() {
// If builder is null, this is the case where onChanged is being called
// from setMessage or clear.
if (builder != null) {
message = null;
}
if (isClean && parent != null) {
parent.markDirty();
// Don't keep dispatching invalidations until build is called again.
isClean = false;
}
}
@Override
public void markDirty() {
onChanged();
}
}

@ -65,22 +65,22 @@ class UnknownFieldSetSchema extends UnknownFieldSchema<UnknownFieldSet, UnknownF
@Override @Override
UnknownFieldSet getFromMessage(Object message) { UnknownFieldSet getFromMessage(Object message) {
return ((GeneratedMessageV3) message).unknownFields; return ((GeneratedMessage) message).unknownFields;
} }
@Override @Override
void setToMessage(Object message, UnknownFieldSet fields) { void setToMessage(Object message, UnknownFieldSet fields) {
((GeneratedMessageV3) message).unknownFields = fields; ((GeneratedMessage) message).unknownFields = fields;
} }
@Override @Override
UnknownFieldSet.Builder getBuilderFromMessage(Object message) { UnknownFieldSet.Builder getBuilderFromMessage(Object message) {
return ((GeneratedMessageV3) message).unknownFields.toBuilder(); return ((GeneratedMessage) message).unknownFields.toBuilder();
} }
@Override @Override
void setBuilderToMessage(Object message, UnknownFieldSet.Builder builder) { void setBuilderToMessage(Object message, UnknownFieldSet.Builder builder) {
((GeneratedMessageV3) message).unknownFields = builder.build(); ((GeneratedMessage) message).unknownFields = builder.build();
} }
@Override @Override

@ -82,7 +82,7 @@ public class GeneratedMessageTest {
@After @After
public void tearDown() { public void tearDown() {
GeneratedMessageV3.setAlwaysUseFieldBuildersForTesting(false); GeneratedMessage.setAlwaysUseFieldBuildersForTesting(false);
} }
@Test @Test
@ -1102,7 +1102,7 @@ public class GeneratedMessageTest {
@Test @Test
public void testInvalidations() throws Exception { public void testInvalidations() throws Exception {
GeneratedMessageV3.setAlwaysUseFieldBuildersForTesting(true); GeneratedMessage.setAlwaysUseFieldBuildersForTesting(true);
TestAllTypes.NestedMessage nestedMessage1 = TestAllTypes.NestedMessage.newBuilder().build(); TestAllTypes.NestedMessage nestedMessage1 = TestAllTypes.NestedMessage.newBuilder().build();
TestAllTypes.NestedMessage nestedMessage2 = TestAllTypes.NestedMessage.newBuilder().build(); TestAllTypes.NestedMessage nestedMessage2 = TestAllTypes.NestedMessage.newBuilder().build();
@ -1845,10 +1845,10 @@ public class GeneratedMessageTest {
UnittestProto.getDescriptor().findExtensionByName("repeated_nested_message_extension"); UnittestProto.getDescriptor().findExtensionByName("repeated_nested_message_extension");
// A compile-time check that TestAllExtensions.Builder does in fact extend // A compile-time check that TestAllExtensions.Builder does in fact extend
// GeneratedMessageV3.ExtendableBuilder. The tests below assume that it does. // GeneratedMessage.ExtendableBuilder. The tests below assume that it does.
static { static {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Class<? extends GeneratedMessageV3.ExtendableBuilder<?, ?>> ignored = Class<? extends GeneratedMessage.ExtendableBuilder<?, ?>> ignored =
TestAllExtensions.Builder.class; TestAllExtensions.Builder.class;
} }

@ -19,17 +19,17 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
/** /**
* Tests for {@link RepeatedFieldBuilderV3}. This tests basic functionality. More extensive testing is * Tests for {@link RepeatedFieldBuilder}. This tests basic functionality. More extensive testing is
* provided via other tests that exercise the builder. * provided via other tests that exercise the builder.
*/ */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class RepeatedFieldBuilderV3Test { public class RepeatedFieldBuilderTest {
@Test @Test
public void testBasicUse() { public void testBasicUse() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = RepeatedFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
newRepeatedFieldBuilderV3(mockParent); newRepeatedFieldBuilder(mockParent);
builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build()); builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build()); builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
assertThat(builder.getMessage(0).getOptionalInt32()).isEqualTo(0); assertThat(builder.getMessage(0).getOptionalInt32()).isEqualTo(0);
@ -50,8 +50,8 @@ public class RepeatedFieldBuilderV3Test {
@Test @Test
public void testGoingBackAndForth() { public void testGoingBackAndForth() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = RepeatedFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
newRepeatedFieldBuilderV3(mockParent); newRepeatedFieldBuilder(mockParent);
builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build()); builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build()); builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
assertThat(builder.getMessage(0).getOptionalInt32()).isEqualTo(0); assertThat(builder.getMessage(0).getOptionalInt32()).isEqualTo(0);
@ -80,8 +80,8 @@ public class RepeatedFieldBuilderV3Test {
@Test @Test
public void testVariousMethods() { public void testVariousMethods() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = RepeatedFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
newRepeatedFieldBuilderV3(mockParent); newRepeatedFieldBuilder(mockParent);
builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build()); builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(2).build()); builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(2).build());
builder.addBuilder(0, TestAllTypes.getDefaultInstance()).setOptionalInt32(0); builder.addBuilder(0, TestAllTypes.getDefaultInstance()).setOptionalInt32(0);
@ -122,8 +122,8 @@ public class RepeatedFieldBuilderV3Test {
@Test @Test
public void testLists() { public void testLists() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = RepeatedFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
newRepeatedFieldBuilderV3(mockParent); newRepeatedFieldBuilder(mockParent);
builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build()); builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
builder.addMessage(0, TestAllTypes.newBuilder().setOptionalInt32(0).build()); builder.addMessage(0, TestAllTypes.newBuilder().setOptionalInt32(0).build());
assertThat(builder.getMessage(0).getOptionalInt32()).isEqualTo(0); assertThat(builder.getMessage(0).getOptionalInt32()).isEqualTo(0);
@ -160,9 +160,9 @@ public class RepeatedFieldBuilderV3Test {
} }
} }
private RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> private RepeatedFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder>
newRepeatedFieldBuilderV3(AbstractMessage.BuilderParent parent) { newRepeatedFieldBuilder(GeneratedMessage.BuilderParent parent) {
return new RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder>( return new RepeatedFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder>(
Collections.<TestAllTypes>emptyList(), false, parent, false); Collections.<TestAllTypes>emptyList(), false, parent, false);
} }
} }

@ -16,17 +16,17 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
/** /**
* Tests for {@link SingleFieldBuilderV3}. This tests basic functionality. More extensive testing is * Tests for {@link SingleFieldBuilder}. This tests basic functionality. More extensive testing is
* provided via other tests that exercise the builder. * provided via other tests that exercise the builder.
*/ */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class SingleFieldBuilderV3Test { public class SingleFieldBuilderTest {
@Test @Test
public void testBasicUseAndInvalidations() { public void testBasicUseAndInvalidations() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = SingleFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false); new SingleFieldBuilder<>(TestAllTypes.getDefaultInstance(), mockParent, false);
assertThat(builder.getMessage()).isSameInstanceAs(TestAllTypes.getDefaultInstance()); assertThat(builder.getMessage()).isSameInstanceAs(TestAllTypes.getDefaultInstance());
assertThat(builder.getBuilder().buildPartial()).isEqualTo(TestAllTypes.getDefaultInstance()); assertThat(builder.getBuilder().buildPartial()).isEqualTo(TestAllTypes.getDefaultInstance());
assertThat(mockParent.getInvalidationCount()).isEqualTo(0); assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
@ -49,8 +49,8 @@ public class SingleFieldBuilderV3Test {
@Test @Test
public void testSetMessage() { public void testSetMessage() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = SingleFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false); new SingleFieldBuilder<>(TestAllTypes.getDefaultInstance(), mockParent, false);
builder.setMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build()); builder.setMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(0); assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(0);
@ -71,8 +71,8 @@ public class SingleFieldBuilderV3Test {
@Test @Test
public void testClear() { public void testClear() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = SingleFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false); new SingleFieldBuilder<>(TestAllTypes.getDefaultInstance(), mockParent, false);
builder.setMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build()); builder.setMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
assertThat(TestAllTypes.getDefaultInstance()).isNotSameInstanceAs(builder.getMessage()); assertThat(TestAllTypes.getDefaultInstance()).isNotSameInstanceAs(builder.getMessage());
builder.clear(); builder.clear();
@ -87,8 +87,8 @@ public class SingleFieldBuilderV3Test {
@Test @Test
public void testMerge() { public void testMerge() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder = SingleFieldBuilder<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false); new SingleFieldBuilder<>(TestAllTypes.getDefaultInstance(), mockParent, false);
// Merge into default field. // Merge into default field.
builder.mergeFrom(TestAllTypes.getDefaultInstance()); builder.mergeFrom(TestAllTypes.getDefaultInstance());

@ -31,25 +31,25 @@
package com.google.protobuf.kotlin package com.google.protobuf.kotlin
import com.google.protobuf.ExtensionLite import com.google.protobuf.ExtensionLite
import com.google.protobuf.GeneratedMessageV3 import com.google.protobuf.GeneratedMessage
/** Sets the current value of the proto extension in this builder. */ /** Sets the current value of the proto extension in this builder. */
operator fun < operator fun <
M : GeneratedMessageV3.ExtendableMessage<M>, M : GeneratedMessage.ExtendableMessage<M>,
B : GeneratedMessageV3.ExtendableBuilder<M, B>, B : GeneratedMessage.ExtendableBuilder<M, B>,
T : Any> B.set(extension: ExtensionLite<M, T>, value: T) { T : Any> B.set(extension: ExtensionLite<M, T>, value: T) {
setExtension(extension, value) setExtension(extension, value)
} }
/** Gets the current value of the proto extension. */ /** Gets the current value of the proto extension. */
operator fun < operator fun <
M : GeneratedMessageV3.ExtendableMessage<M>, M : GeneratedMessage.ExtendableMessage<M>,
MorBT : GeneratedMessageV3.ExtendableMessageOrBuilder<M>, MorBT : GeneratedMessage.ExtendableMessageOrBuilder<M>,
T : Any> MorBT.get(extension: ExtensionLite<M, T>): T = getExtension(extension) T : Any> MorBT.get(extension: ExtensionLite<M, T>): T = getExtension(extension)
/** Returns true if the specified extension is set on this builder. */ /** Returns true if the specified extension is set on this builder. */
operator fun < operator fun <
M : GeneratedMessageV3.ExtendableMessage<M>, M : GeneratedMessage.ExtendableMessage<M>,
MorBT : GeneratedMessageV3.ExtendableMessageOrBuilder<M>> MorBT.contains( MorBT : GeneratedMessage.ExtendableMessageOrBuilder<M>> MorBT.contains(
extension: ExtensionLite<M, *> extension: ExtensionLite<M, *>
): Boolean = hasExtension(extension) ): Boolean = hasExtension(extension)

@ -224,10 +224,10 @@
<exclude>Proto2ExtensionLookupSchemaTest.java</exclude> <exclude>Proto2ExtensionLookupSchemaTest.java</exclude>
<exclude>Proto2SchemaTest.java</exclude> <exclude>Proto2SchemaTest.java</exclude>
<exclude>Proto2UnknownEnumValueTest.java</exclude> <exclude>Proto2UnknownEnumValueTest.java</exclude>
<exclude>RepeatedFieldBuilderV3Test.java</exclude> <exclude>RepeatedFieldBuilderTest.java</exclude>
<exclude>RuntimeVersionTest.java</exclude> <exclude>RuntimeVersionTest.java</exclude>
<exclude>ServiceTest.java</exclude> <exclude>ServiceTest.java</exclude>
<exclude>SingleFieldBuilderV3Test.java</exclude> <exclude>SingleFieldBuilderTest.java</exclude>
<exclude>TestBadIdentifiers.java</exclude> <exclude>TestBadIdentifiers.java</exclude>
<exclude>TextFormatParseInfoTreeTest.java</exclude> <exclude>TextFormatParseInfoTreeTest.java</exclude>
<exclude>TextFormatParseLocationTest.java</exclude> <exclude>TextFormatParseLocationTest.java</exclude>

@ -386,10 +386,6 @@ inline bool CheckUtf8(const FieldDescriptor* descriptor) {
descriptor->file()->options().java_string_check_utf8(); descriptor->file()->options().java_string_check_utf8();
} }
inline std::string GeneratedCodeVersionSuffix() {
return "V3";
}
void WriteUInt32ToUtf16CharSequence(uint32_t number, void WriteUInt32ToUtf16CharSequence(uint32_t number,
std::vector<uint16_t>* output); std::vector<uint16_t>* output);

@ -184,8 +184,6 @@ void ImmutableMapFieldGenerator::SetMessageVariables(
variables_["descriptor"] = absl::StrCat( variables_["descriptor"] = absl::StrCat(
name_resolver->GetImmutableClassName(descriptor_->file()), ".internal_", name_resolver->GetImmutableClassName(descriptor_->file()), ".internal_",
UniqueFileScopeIdentifier(descriptor_->message_type()), "_descriptor, "); UniqueFileScopeIdentifier(descriptor_->message_type()), "_descriptor, ");
variables_["ver"] = GeneratedCodeVersionSuffix();
variables_["get_has_field_bit_builder"] = GenerateGetBit(builder_bit_index_); variables_["get_has_field_bit_builder"] = GenerateGetBit(builder_bit_index_);
variables_["get_has_field_bit_from_local"] = variables_["get_has_field_bit_from_local"] =
GenerateGetBitFromLocal(builder_bit_index_); GenerateGetBitFromLocal(builder_bit_index_);
@ -1132,7 +1130,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderParsingCode(
void ImmutableMapFieldGenerator::GenerateSerializationCode( void ImmutableMapFieldGenerator::GenerateSerializationCode(
io::Printer* printer) const { io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"com.google.protobuf.GeneratedMessage$ver$\n" "com.google.protobuf.GeneratedMessage\n"
" .serialize$short_key_type$MapTo(\n" " .serialize$short_key_type$MapTo(\n"
" output,\n" " output,\n"
" internalGet$capitalized_name$(),\n" " internalGet$capitalized_name$(),\n"

@ -187,12 +187,10 @@ void ImmutableMessageGenerator::GenerateFieldAccessorTable(
} else { } else {
vars["final"] = ""; vars["final"] = "";
} }
vars["ver"] = GeneratedCodeVersionSuffix(); printer->Print(vars,
printer->Print( "$private$static $final$\n"
vars, " com.google.protobuf.GeneratedMessage.FieldAccessorTable\n"
"$private$static $final$\n" " internal_$identifier$_fieldAccessorTable;\n");
" com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n"
" internal_$identifier$_fieldAccessorTable;\n");
// The following bytecode_estimate calculation logic must stay in sync with // The following bytecode_estimate calculation logic must stay in sync with
// the similar logic in the GenerateFieldAccessorTableInitializer method below // the similar logic in the GenerateFieldAccessorTableInitializer method below
@ -209,11 +207,10 @@ int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer(
int bytecode_estimate = 10; int bytecode_estimate = 10;
printer->Print( printer->Print(
"internal_$identifier$_fieldAccessorTable = new\n" "internal_$identifier$_fieldAccessorTable = new\n"
" com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable(\n" " com.google.protobuf.GeneratedMessage.FieldAccessorTable(\n"
" internal_$identifier$_descriptor,\n" " internal_$identifier$_descriptor,\n"
" new java.lang.String[] { ", " new java.lang.String[] { ",
"identifier", UniqueFileScopeIdentifier(descriptor_), "ver", "identifier", UniqueFileScopeIdentifier(descriptor_));
GeneratedCodeVersionSuffix());
// All the bytecode_estimate calculation logic in this method must stay in // All the bytecode_estimate calculation logic in this method must stay in
// sync with the similar logic in the GenerateFieldAccessorTable method // sync with the similar logic in the GenerateFieldAccessorTable method
// above. See the corresponding comment in GenerateFieldAccessorTable for // above. See the corresponding comment in GenerateFieldAccessorTable for
@ -247,13 +244,12 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
printer->Print( printer->Print(
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessage$ver$.\n" " com.google.protobuf.GeneratedMessage.\n"
" ExtendableMessageOrBuilder<$classname$> {\n", " ExtendableMessageOrBuilder<$classname$> {\n",
"deprecation", "deprecation",
descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(), "{", "", "}", "", "ver", "classname", descriptor_->name(), "{", "", "}", "");
GeneratedCodeVersionSuffix());
} else { } else {
printer->Print( printer->Print(
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
@ -296,7 +292,6 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
variables["static"] = is_own_file ? "" : "static "; variables["static"] = is_own_file ? "" : "static ";
variables["classname"] = descriptor_->name(); variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
variables["ver"] = GeneratedCodeVersionSuffix();
variables["deprecation"] = variables["deprecation"] =
descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "";
@ -316,26 +311,23 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
printer->Annotate("classname", descriptor_); printer->Annotate("classname", descriptor_);
printer->Print( printer->Print(
variables, variables,
" com.google.protobuf.GeneratedMessage$ver$.ExtendableMessage<\n" " com.google.protobuf.GeneratedMessage.ExtendableMessage<\n"
" $classname$> implements\n" " $classname$> implements\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" $classname$OrBuilder {\n"); " $classname$OrBuilder {\n");
builder_type = absl::Substitute( builder_type = absl::Substitute(
"com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>", "com.google.protobuf.GeneratedMessage.ExtendableBuilder<$0, ?>",
name_resolver_->GetImmutableClassName(descriptor_), name_resolver_->GetImmutableClassName(descriptor_));
GeneratedCodeVersionSuffix());
} else { } else {
printer->Print( printer->Print(
variables, variables,
"$deprecation$public $static$final class $classname$ extends\n"); "$deprecation$public $static$final class $classname$ extends\n");
printer->Annotate("classname", descriptor_); printer->Annotate("classname", descriptor_);
printer->Print(variables, printer->Print(variables,
" com.google.protobuf.GeneratedMessage$ver$ implements\n" " com.google.protobuf.GeneratedMessage implements\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" $classname$OrBuilder {\n"); " $classname$OrBuilder {\n");
builder_type = builder_type = "com.google.protobuf.GeneratedMessage.Builder<?>";
absl::Substitute("com.google.protobuf.GeneratedMessage$0.Builder<?>",
GeneratedCodeVersionSuffix());
} }
printer->Print("private static final long serialVersionUID = 0L;\n"); printer->Print("private static final long serialVersionUID = 0L;\n");
@ -596,18 +588,16 @@ void ImmutableMessageGenerator::GenerateMessageSerializationMethods(
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
if (descriptor_->options().message_set_wire_format()) { if (descriptor_->options().message_set_wire_format()) {
printer->Print( printer->Print(
"com.google.protobuf.GeneratedMessage$ver$\n" "com.google.protobuf.GeneratedMessage\n"
" .ExtendableMessage<$classname$>.ExtensionWriter\n" " .ExtendableMessage<$classname$>.ExtensionWriter\n"
" extensionWriter = newMessageSetExtensionWriter();\n", " extensionWriter = newMessageSetExtensionWriter();\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "classname", name_resolver_->GetImmutableClassName(descriptor_));
"ver", GeneratedCodeVersionSuffix());
} else { } else {
printer->Print( printer->Print(
"com.google.protobuf.GeneratedMessage$ver$\n" "com.google.protobuf.GeneratedMessage\n"
" .ExtendableMessage<$classname$>.ExtensionWriter\n" " .ExtendableMessage<$classname$>.ExtensionWriter\n"
" extensionWriter = newExtensionWriter();\n", " extensionWriter = newExtensionWriter();\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "classname", name_resolver_->GetImmutableClassName(descriptor_));
"ver", GeneratedCodeVersionSuffix());
} }
} }
@ -701,21 +691,21 @@ void ImmutableMessageGenerator::GenerateParseFromMethods(io::Printer* printer) {
"}\n" "}\n"
"public static $classname$ parseFrom(java.io.InputStream input)\n" "public static $classname$ parseFrom(java.io.InputStream input)\n"
" throws java.io.IOException {\n" " throws java.io.IOException {\n"
" return com.google.protobuf.GeneratedMessage$ver$\n" " return com.google.protobuf.GeneratedMessage\n"
" .parseWithIOException(PARSER, input);\n" " .parseWithIOException(PARSER, input);\n"
"}\n" "}\n"
"public static $classname$ parseFrom(\n" "public static $classname$ parseFrom(\n"
" java.io.InputStream input,\n" " java.io.InputStream input,\n"
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
" throws java.io.IOException {\n" " throws java.io.IOException {\n"
" return com.google.protobuf.GeneratedMessage$ver$\n" " return com.google.protobuf.GeneratedMessage\n"
" .parseWithIOException(PARSER, input, extensionRegistry);\n" " .parseWithIOException(PARSER, input, extensionRegistry);\n"
"}\n" "}\n"
"$parsedelimitedreturnannotation$\n" "$parsedelimitedreturnannotation$\n"
"public static $classname$ parseDelimitedFrom(java.io.InputStream " "public static $classname$ parseDelimitedFrom(java.io.InputStream "
"input)\n" "input)\n"
" throws java.io.IOException {\n" " throws java.io.IOException {\n"
" return com.google.protobuf.GeneratedMessage$ver$\n" " return com.google.protobuf.GeneratedMessage\n"
" .parseDelimitedWithIOException(PARSER, input);\n" " .parseDelimitedWithIOException(PARSER, input);\n"
"}\n" "}\n"
"$parsedelimitedreturnannotation$\n" "$parsedelimitedreturnannotation$\n"
@ -723,26 +713,26 @@ void ImmutableMessageGenerator::GenerateParseFromMethods(io::Printer* printer) {
" java.io.InputStream input,\n" " java.io.InputStream input,\n"
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
" throws java.io.IOException {\n" " throws java.io.IOException {\n"
" return com.google.protobuf.GeneratedMessage$ver$\n" " return com.google.protobuf.GeneratedMessage\n"
" .parseDelimitedWithIOException(PARSER, input, " " .parseDelimitedWithIOException(PARSER, input, "
"extensionRegistry);\n" "extensionRegistry);\n"
"}\n" "}\n"
"public static $classname$ parseFrom(\n" "public static $classname$ parseFrom(\n"
" com.google.protobuf.CodedInputStream input)\n" " com.google.protobuf.CodedInputStream input)\n"
" throws java.io.IOException {\n" " throws java.io.IOException {\n"
" return com.google.protobuf.GeneratedMessage$ver$\n" " return com.google.protobuf.GeneratedMessage\n"
" .parseWithIOException(PARSER, input);\n" " .parseWithIOException(PARSER, input);\n"
"}\n" "}\n"
"public static $classname$ parseFrom(\n" "public static $classname$ parseFrom(\n"
" com.google.protobuf.CodedInputStream input,\n" " com.google.protobuf.CodedInputStream input,\n"
" com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
" throws java.io.IOException {\n" " throws java.io.IOException {\n"
" return com.google.protobuf.GeneratedMessage$ver$\n" " return com.google.protobuf.GeneratedMessage\n"
" .parseWithIOException(PARSER, input, extensionRegistry);\n" " .parseWithIOException(PARSER, input, extensionRegistry);\n"
"}\n" "}\n"
"\n", "\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "ver", "classname", name_resolver_->GetImmutableClassName(descriptor_),
GeneratedCodeVersionSuffix(), "parsedelimitedreturnannotation", "parsedelimitedreturnannotation",
context_->options().opensource_runtime context_->options().opensource_runtime
? "" ? ""
: "@com.google.protobuf.Internal.ProtoMethodMayReturnNull"); : "@com.google.protobuf.Internal.ProtoMethodMayReturnNull");
@ -774,11 +764,10 @@ void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) {
printer->Print( printer->Print(
"@java.lang.Override\n" "@java.lang.Override\n"
"protected Builder newBuilderForType(\n" "protected Builder newBuilderForType(\n"
" com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n" " com.google.protobuf.GeneratedMessage.BuilderParent parent) {\n"
" Builder builder = new Builder(parent);\n" " Builder builder = new Builder(parent);\n"
" return builder;\n" " return builder;\n"
"}\n", "}\n");
"ver", GeneratedCodeVersionSuffix());
MessageBuilderGenerator builderGenerator(descriptor_, context_); MessageBuilderGenerator builderGenerator(descriptor_, context_);
builderGenerator.Generate(printer); builderGenerator.Generate(printer);
@ -835,7 +824,7 @@ void ImmutableMessageGenerator::GenerateDescriptorMethods(
} }
printer->Print( printer->Print(
"@java.lang.Override\n" "@java.lang.Override\n"
"protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" "protected com.google.protobuf.GeneratedMessage.FieldAccessorTable\n"
" internalGetFieldAccessorTable() {\n" " internalGetFieldAccessorTable() {\n"
" return $fileclass$.internal_$identifier$_fieldAccessorTable\n" " return $fileclass$.internal_$identifier$_fieldAccessorTable\n"
" .ensureFieldAccessorsInitialized(\n" " .ensureFieldAccessorsInitialized(\n"
@ -844,8 +833,7 @@ void ImmutableMessageGenerator::GenerateDescriptorMethods(
"\n", "\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "classname", name_resolver_->GetImmutableClassName(descriptor_),
"fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()),
"identifier", UniqueFileScopeIdentifier(descriptor_), "ver", "identifier", UniqueFileScopeIdentifier(descriptor_));
GeneratedCodeVersionSuffix());
} }
// =================================================================== // ===================================================================

@ -95,23 +95,21 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
if (descriptor_->extension_range_count() > 0) { if (descriptor_->extension_range_count() > 0) {
printer->Print( printer->Print(
"public static final class Builder extends\n" "public static final class Builder extends\n"
" com.google.protobuf.GeneratedMessage$ver$.ExtendableBuilder<\n" " com.google.protobuf.GeneratedMessage.ExtendableBuilder<\n"
" $classname$, Builder> implements\n" " $classname$, Builder> implements\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" $classname$OrBuilder {\n", " $classname$OrBuilder {\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "classname", name_resolver_->GetImmutableClassName(descriptor_),
"extra_interfaces", ExtraBuilderInterfaces(descriptor_), "ver", "extra_interfaces", ExtraBuilderInterfaces(descriptor_));
GeneratedCodeVersionSuffix());
} else { } else {
printer->Print( printer->Print(
"public static final class Builder extends\n" "public static final class Builder extends\n"
" com.google.protobuf.GeneratedMessage$ver$.Builder<Builder> " " com.google.protobuf.GeneratedMessage.Builder<Builder> "
"implements\n" "implements\n"
" $extra_interfaces$\n" " $extra_interfaces$\n"
" $classname$OrBuilder {\n", " $classname$OrBuilder {\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "classname", name_resolver_->GetImmutableClassName(descriptor_),
"extra_interfaces", ExtraBuilderInterfaces(descriptor_), "ver", "extra_interfaces", ExtraBuilderInterfaces(descriptor_));
GeneratedCodeVersionSuffix());
} }
printer->Indent(); printer->Indent();
@ -277,7 +275,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) {
} }
printer->Print( printer->Print(
"@java.lang.Override\n" "@java.lang.Override\n"
"protected com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n" "protected com.google.protobuf.GeneratedMessage.FieldAccessorTable\n"
" internalGetFieldAccessorTable() {\n" " internalGetFieldAccessorTable() {\n"
" return $fileclass$.internal_$identifier$_fieldAccessorTable\n" " return $fileclass$.internal_$identifier$_fieldAccessorTable\n"
" .ensureFieldAccessorsInitialized(\n" " .ensureFieldAccessorsInitialized(\n"
@ -286,8 +284,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) {
"\n", "\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "classname", name_resolver_->GetImmutableClassName(descriptor_),
"fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()), "fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()),
"identifier", UniqueFileScopeIdentifier(descriptor_), "ver", "identifier", UniqueFileScopeIdentifier(descriptor_));
GeneratedCodeVersionSuffix());
} }
// =================================================================== // ===================================================================
@ -322,19 +319,18 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
printer->Print( printer->Print(
"private Builder(\n" "private Builder(\n"
" com.google.protobuf.GeneratedMessage$ver$.BuilderParent parent) {\n" " com.google.protobuf.GeneratedMessage.BuilderParent parent) {\n"
" super(parent);\n" " super(parent);\n"
"$force_builder_init$\n" "$force_builder_init$\n"
"}\n", "}\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_), "ver", "classname", name_resolver_->GetImmutableClassName(descriptor_),
GeneratedCodeVersionSuffix(), "force_builder_init", force_builder_init); "force_builder_init", force_builder_init);
if (need_maybe_force_builder_init) { if (need_maybe_force_builder_init) {
printer->Print( printer->Print(
"private void maybeForceBuilderInitialization() {\n" "private void maybeForceBuilderInitialization() {\n"
" if (com.google.protobuf.GeneratedMessage$ver$\n" " if (com.google.protobuf.GeneratedMessage\n"
" .alwaysUseFieldBuilders) {\n", " .alwaysUseFieldBuilders) {\n");
"ver", GeneratedCodeVersionSuffix());
printer->Indent(); printer->Indent();
printer->Indent(); printer->Indent();

@ -60,7 +60,6 @@ void SetMessageVariables(
(*variables)["name"], " is deprecated\") ") (*variables)["name"], " is deprecated\") ")
: ""}); : ""});
(*variables)["on_changed"] = "onChanged();"; (*variables)["on_changed"] = "onChanged();";
(*variables)["ver"] = GeneratedCodeVersionSuffix();
(*variables)["get_parser"] = "parser()"; (*variables)["get_parser"] = "parser()";
if (HasHasbit(descriptor)) { if (HasHasbit(descriptor)) {
@ -232,7 +231,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_, printer->Print(variables_,
// If this builder is non-null, it is used and the other fields // If this builder is non-null, it is used and the other fields
// are ignored. // are ignored.
"private com.google.protobuf.SingleFieldBuilder$ver$<\n" "private com.google.protobuf.SingleFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;" " $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;"
"\n"); "\n");
@ -357,11 +356,11 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
WriteFieldDocComment(printer, descriptor_, context_->options()); WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print( printer->Print(
variables_, variables_,
"private com.google.protobuf.SingleFieldBuilder$ver$<\n" "private com.google.protobuf.SingleFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder> \n" " $type$, $type$.Builder, $type$OrBuilder> \n"
" get$capitalized_name$FieldBuilder() {\n" " get$capitalized_name$FieldBuilder() {\n"
" if ($name$Builder_ == null) {\n" " if ($name$Builder_ == null) {\n"
" $name$Builder_ = new com.google.protobuf.SingleFieldBuilder$ver$<\n" " $name$Builder_ = new com.google.protobuf.SingleFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder>(\n" " $type$, $type$.Builder, $type$OrBuilder>(\n"
" get$capitalized_name$(),\n" " get$capitalized_name$(),\n"
" getParentForChildren(),\n" " getParentForChildren(),\n"
@ -568,7 +567,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
printer->Print(variables_, printer->Print(variables_,
// If this builder is non-null, it is used and the other fields // If this builder is non-null, it is used and the other fields
// are ignored. // are ignored.
"private com.google.protobuf.SingleFieldBuilder$ver$<\n" "private com.google.protobuf.SingleFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;" " $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;"
"\n"); "\n");
@ -709,14 +708,14 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
WriteFieldDocComment(printer, descriptor_, context_->options()); WriteFieldDocComment(printer, descriptor_, context_->options());
printer->Print( printer->Print(
variables_, variables_,
"private com.google.protobuf.SingleFieldBuilder$ver$<\n" "private com.google.protobuf.SingleFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder> \n" " $type$, $type$.Builder, $type$OrBuilder> \n"
" ${$get$capitalized_name$FieldBuilder$}$() {\n" " ${$get$capitalized_name$FieldBuilder$}$() {\n"
" if ($name$Builder_ == null) {\n" " if ($name$Builder_ == null) {\n"
" if (!($has_oneof_case_message$)) {\n" " if (!($has_oneof_case_message$)) {\n"
" $oneof_name$_ = $type$.getDefaultInstance();\n" " $oneof_name$_ = $type$.getDefaultInstance();\n"
" }\n" " }\n"
" $name$Builder_ = new com.google.protobuf.SingleFieldBuilder$ver$<\n" " $name$Builder_ = new com.google.protobuf.SingleFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder>(\n" " $type$, $type$.Builder, $type$OrBuilder>(\n"
" ($type$) $oneof_name$_,\n" " ($type$) $oneof_name$_,\n"
" getParentForChildren(),\n" " getParentForChildren(),\n"
@ -958,7 +957,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
variables_, variables_,
// If this builder is non-null, it is used and the other fields are // If this builder is non-null, it is used and the other fields are
// ignored. // ignored.
"private com.google.protobuf.RepeatedFieldBuilder$ver$<\n" "private com.google.protobuf.RepeatedFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;\n" " $type$, $type$.Builder, $type$OrBuilder> $name$Builder_;\n"
"\n"); "\n");
@ -1204,12 +1203,12 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
" ${$get$capitalized_name$BuilderList$}$() {\n" " ${$get$capitalized_name$BuilderList$}$() {\n"
" return get$capitalized_name$FieldBuilder().getBuilderList();\n" " return get$capitalized_name$FieldBuilder().getBuilderList();\n"
"}\n" "}\n"
"private com.google.protobuf.RepeatedFieldBuilder$ver$<\n" "private com.google.protobuf.RepeatedFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder> \n" " $type$, $type$.Builder, $type$OrBuilder> \n"
" get$capitalized_name$FieldBuilder() {\n" " get$capitalized_name$FieldBuilder() {\n"
" if ($name$Builder_ == null) {\n" " if ($name$Builder_ == null) {\n"
" $name$Builder_ = new " " $name$Builder_ = new "
"com.google.protobuf.RepeatedFieldBuilder$ver$<\n" "com.google.protobuf.RepeatedFieldBuilder<\n"
" $type$, $type$.Builder, $type$OrBuilder>(\n" " $type$, $type$.Builder, $type$OrBuilder>(\n"
" $name$_,\n" " $name$_,\n"
" $get_mutable_bit_builder$,\n" " $get_mutable_bit_builder$,\n"
@ -1270,7 +1269,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMergingCode(
" $name$_ = other.$name$_;\n" " $name$_ = other.$name$_;\n"
" $clear_mutable_bit_builder$;\n" " $clear_mutable_bit_builder$;\n"
" $name$Builder_ = \n" " $name$Builder_ = \n"
" com.google.protobuf.GeneratedMessage$ver$.alwaysUseFieldBuilders " " com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders "
"?\n" "?\n"
" get$capitalized_name$FieldBuilder() : null;\n" " get$capitalized_name$FieldBuilder() : null;\n"
" } else {\n" " } else {\n"

@ -59,14 +59,11 @@ void SetPrimitiveVariables(
(*variables)["null_check"] = (*variables)["null_check"] =
"if (value == null) { throw new NullPointerException(); }"; "if (value == null) { throw new NullPointerException(); }";
(*variables)["isStringEmpty"] = (*variables)["isStringEmpty"] =
absl::StrCat("com.google.protobuf.GeneratedMessage", "com.google.protobuf.GeneratedMessage.isStringEmpty";
GeneratedCodeVersionSuffix(), ".isStringEmpty");
(*variables)["writeString"] = (*variables)["writeString"] =
absl::StrCat("com.google.protobuf.GeneratedMessage", "com.google.protobuf.GeneratedMessage.writeString";
GeneratedCodeVersionSuffix(), ".writeString");
(*variables)["computeStringSize"] = (*variables)["computeStringSize"] =
absl::StrCat("com.google.protobuf.GeneratedMessage", "com.google.protobuf.GeneratedMessage.computeStringSize";
GeneratedCodeVersionSuffix(), ".computeStringSize");
// TODO: Add @deprecated javadoc when generating javadoc is supported // TODO: Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler // by the proto compiler

Loading…
Cancel
Save