Unlike other field types, reflection support for map fields can't be implemented based on
+ * generated public API because we need to access a map field as a list in reflection API but
+ * the generated API only allows us to access it as a map. This method returns the underlying
+ * map field directly and thus enables us to access the map field as a list.
*/
@SuppressWarnings({"unused", "rawtypes"})
protected MapField internalGetMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
- throw new RuntimeException(
- "No map fields found in " + getClass().getName());
+ throw new RuntimeException("No map fields found in " + getClass().getName());
}
/** Like {@link #internalGetMapField} but return a mutable version. */
@@ -726,76 +691,57 @@ public abstract class GeneratedMessage extends AbstractMessage
protected MapField internalGetMutableMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
- throw new RuntimeException(
- "No map fields found in " + getClass().getName());
+ throw new RuntimeException("No map fields found in " + getClass().getName());
}
}
// =================================================================
// Extensions-related stuff
- public interface ExtendableMessageOrBuilder<
- MessageType extends ExtendableMessage> extends MessageOrBuilder {
+ public interface ExtendableMessageOrBuilder This class implements type-safe accessors for extensions. They
- * implement all the same operations that you can do with normal fields --
- * e.g. "has", "get", and "getCount" -- but for extensions. The extensions
- * are identified using instances of the class {@link GeneratedExtension};
- * the protocol compiler generates a static instance of this class for every
- * extension in its input. Through the magic of generics, all is made
- * type-safe.
+ * This class implements type-safe accessors for extensions. They implement all the same
+ * operations that you can do with normal fields -- e.g. "has", "get", and "getCount" -- but for
+ * extensions. The extensions are identified using instances of the class {@link
+ * GeneratedExtension}; the protocol compiler generates a static instance of this class for every
+ * extension in its input. Through the magic of generics, all is made type-safe.
*
* For example, imagine you have the {@code .proto} file:
*
@@ -820,10 +766,8 @@ public abstract class GeneratedMessage extends AbstractMessage
*
* See also {@link ExtendableBuilder}.
*/
- public abstract static class ExtendableMessage<
- MessageType extends ExtendableMessage>
- extends GeneratedMessage
- implements ExtendableMessageOrBuilder This class implements type-safe accessors for extensions. They
- * implement all the same operations that you can do with normal fields --
- * e.g. "get", "set", and "add" -- but for extensions. The extensions are
- * identified using instances of the class {@link GeneratedExtension}; the
- * protocol compiler generates a static instance of this class for every
- * extension in its input. Through the magic of generics, all is made
- * type-safe.
+ * This class implements type-safe accessors for extensions. They implement all the same
+ * operations that you can do with normal fields -- e.g. "get", "set", and "add" -- but for
+ * extensions. The extensions are identified using instances of the class {@link
+ * GeneratedExtension}; the protocol compiler generates a static instance of this class for every
+ * extension in its input. Through the magic of generics, all is made type-safe.
*
* For example, imagine you have the {@code .proto} file:
*
@@ -1182,17 +1116,15 @@ public abstract class GeneratedMessage extends AbstractMessage
*/
@SuppressWarnings("unchecked")
public abstract static class ExtendableBuilder<
- MessageType extends ExtendableMessage,
- BuilderType extends ExtendableBuilder After enabling bridge, we can define proto2 extensions (the extended type is a proto2
+ * mutable message) in a proto1 .proto file. For these extensions we should generate proto2
+ * GeneratedExtensions.
*/
public static After enabling bridge, we can define proto2 extensions (the extended type is a proto2
+ * mutable message) in a proto1 .proto file. For these extensions we should generate proto2
+ * GeneratedExtensions.
*/
public static For example, imagine you have the {@code .proto} file:
*
@@ -1747,16 +1670,14 @@ public abstract class GeneratedMessage extends AbstractMessage
* }
*
*
- * Then, {@code MyProto.Foo.bar} has type
- * {@code GeneratedExtension Then, {@code MyProto.Foo.bar} has type {@code GeneratedExtension In general, users should ignore the details of this type, and simply use
- * these static singletons as parameters to the extension accessors defined
- * in {@link ExtendableMessage} and {@link ExtendableBuilder}.
+ * In general, users should ignore the details of this type, and simply use these static
+ * singletons as parameters to the extension accessors defined in {@link ExtendableMessage} and
+ * {@link ExtendableBuilder}.
*/
- public static class GeneratedExtension<
- ContainingType extends Message, Type> extends
- Extension Unlike other field types, reflection support for map fields can't be implemented based on
+ * generated public API because we need to access a map field as a list in reflection API but the
+ * generated API only allows us to access it as a map. This method returns the underlying map
+ * field directly and thus enables us to access the map field as a list.
*/
@SuppressWarnings({"rawtypes", "unused"})
protected MapField internalGetMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
- throw new RuntimeException(
- "No map fields found in " + getClass().getName());
+ throw new RuntimeException("No map fields found in " + getClass().getName());
}
/**
- * Users should ignore this class. This class provides the implementation
- * with access to the fields of a message object using Java reflection.
+ * Users should ignore this class. This class provides the implementation with access to the
+ * fields of a message object using Java reflection.
*/
public static final class FieldAccessorTable {
/**
- * Construct a FieldAccessorTable for a particular message class. Only
- * one FieldAccessorTable should ever be constructed per class.
+ * Construct a FieldAccessorTable for a particular message class. Only one FieldAccessorTable
+ * should ever be constructed per class.
*
- * @param descriptor The type's descriptor.
- * @param camelCaseNames The camelcase names of all fields in the message.
- * These are used to derive the accessor method names.
- * @param messageClass The message type.
- * @param builderClass The builder type.
+ * @param descriptor The type's descriptor.
+ * @param camelCaseNames The camelcase names of all fields in the message. These are used to
+ * derive the accessor method names.
+ * @param messageClass The message type.
+ * @param builderClass The builder type.
*/
public FieldAccessorTable(
final Descriptor descriptor,
@@ -2042,12 +1953,10 @@ public abstract class GeneratedMessage extends AbstractMessage
}
/**
- * Construct a FieldAccessorTable for a particular message class without
- * initializing FieldAccessors.
+ * Construct a FieldAccessorTable for a particular message class without initializing
+ * FieldAccessors.
*/
- public FieldAccessorTable(
- final Descriptor descriptor,
- final String[] camelCaseNames) {
+ public FieldAccessorTable(final Descriptor descriptor, final String[] camelCaseNames) {
this.descriptor = descriptor;
this.camelCaseNames = camelCaseNames;
fields = new FieldAccessor[descriptor.getFields().size()];
@@ -2063,16 +1972,19 @@ public abstract class GeneratedMessage extends AbstractMessage
/**
* Ensures the field accessors are initialized. This method is thread-safe.
*
- * @param messageClass The message type.
- * @param builderClass The builder type.
+ * @param messageClass The message type.
+ * @param builderClass The builder type.
* @return this
*/
public FieldAccessorTable ensureFieldAccessorsInitialized(
- Class extends GeneratedMessage> messageClass,
- Class extends Builder> builderClass) {
- if (initialized) { return this; }
+ Class extends GeneratedMessage> messageClass, Class extends Builder> builderClass) {
+ if (initialized) {
+ return this;
+ }
synchronized (this) {
- if (initialized) { return this; }
+ if (initialized) {
+ return this;
+ }
int fieldsSize = fields.length;
for (int i = 0; i < fieldsSize; i++) {
FieldDescriptor field = descriptor.getFields().get(i);
@@ -2084,45 +1996,63 @@ public abstract class GeneratedMessage extends AbstractMessage
if (field.isRepeated()) {
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
if (field.isMapField() && isMapFieldEnabled(field)) {
- fields[i] = new MapFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass);
+ fields[i] =
+ new MapFieldAccessor(field, camelCaseNames[i], messageClass, builderClass);
} else {
- fields[i] = new RepeatedMessageFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass);
+ fields[i] =
+ new RepeatedMessageFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
}
} else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
- fields[i] = new RepeatedEnumFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass);
+ fields[i] =
+ new RepeatedEnumFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
} else {
- fields[i] = new RepeatedFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass);
+ fields[i] =
+ new RepeatedFieldAccessor(field, camelCaseNames[i], messageClass, builderClass);
}
} else {
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
- fields[i] = new SingularMessageFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass,
- containingOneofCamelCaseName);
+ fields[i] =
+ new SingularMessageFieldAccessor(
+ field,
+ camelCaseNames[i],
+ messageClass,
+ builderClass,
+ containingOneofCamelCaseName);
} else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
- fields[i] = new SingularEnumFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass,
- containingOneofCamelCaseName);
+ fields[i] =
+ new SingularEnumFieldAccessor(
+ field,
+ camelCaseNames[i],
+ messageClass,
+ builderClass,
+ containingOneofCamelCaseName);
} else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) {
- fields[i] = new SingularStringFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass,
- containingOneofCamelCaseName);
+ fields[i] =
+ new SingularStringFieldAccessor(
+ field,
+ camelCaseNames[i],
+ messageClass,
+ builderClass,
+ containingOneofCamelCaseName);
} else {
- fields[i] = new SingularFieldAccessor(
- field, camelCaseNames[i], messageClass, builderClass,
- containingOneofCamelCaseName);
+ fields[i] =
+ new SingularFieldAccessor(
+ field,
+ camelCaseNames[i],
+ messageClass,
+ builderClass,
+ containingOneofCamelCaseName);
}
}
}
int oneofsSize = oneofs.length;
for (int i = 0; i < oneofsSize; i++) {
- oneofs[i] = new OneofAccessor(
- descriptor, camelCaseNames[i + fieldsSize],
- messageClass, builderClass);
+ oneofs[i] =
+ new OneofAccessor(
+ descriptor, camelCaseNames[i + fieldsSize], messageClass, builderClass);
}
initialized = true;
camelCaseNames = null;
@@ -2139,13 +2069,11 @@ public abstract class GeneratedMessage extends AbstractMessage
/** Get the FieldAccessor for a particular field. */
private FieldAccessor getField(final FieldDescriptor field) {
if (field.getContainingType() != descriptor) {
- throw new IllegalArgumentException(
- "FieldDescriptor does not match message type.");
+ throw new IllegalArgumentException("FieldDescriptor does not match message type.");
} else if (field.isExtension()) {
// If this type had extensions, it would subclass ExtendableMessage,
// which overrides the reflection interface to handle extensions.
- throw new IllegalArgumentException(
- "This type does not have extensions.");
+ throw new IllegalArgumentException("This type does not have extensions.");
}
return fields[field.getIndex()];
}
@@ -2153,51 +2081,65 @@ public abstract class GeneratedMessage extends AbstractMessage
/** Get the OneofAccessor for a particular oneof. */
private OneofAccessor getOneof(final OneofDescriptor oneof) {
if (oneof.getContainingType() != descriptor) {
- throw new IllegalArgumentException(
- "OneofDescriptor does not match message type.");
+ throw new IllegalArgumentException("OneofDescriptor does not match message type.");
}
return oneofs[oneof.getIndex()];
}
/**
- * Abstract interface that provides access to a single field. This is
- * implemented differently depending on the field type and cardinality.
+ * Abstract interface that provides access to a single field. This is implemented differently
+ * depending on the field type and cardinality.
*/
private interface FieldAccessor {
Object get(GeneratedMessage message);
+
Object get(GeneratedMessage.Builder builder);
+
Object getRaw(GeneratedMessage message);
+
Object getRaw(GeneratedMessage.Builder builder);
+
void set(Builder builder, Object value);
+
Object getRepeated(GeneratedMessage message, int index);
+
Object getRepeated(GeneratedMessage.Builder builder, int index);
+
Object getRepeatedRaw(GeneratedMessage message, int index);
+
Object getRepeatedRaw(GeneratedMessage.Builder builder, int index);
- void setRepeated(Builder builder,
- int index, Object value);
+
+ void setRepeated(Builder builder, int index, Object value);
+
void addRepeated(Builder builder, Object value);
+
boolean has(GeneratedMessage message);
+
boolean has(GeneratedMessage.Builder builder);
+
int getRepeatedCount(GeneratedMessage message);
+
int getRepeatedCount(GeneratedMessage.Builder builder);
+
void clear(Builder builder);
+
Message.Builder newBuilder();
+
Message.Builder getBuilder(GeneratedMessage.Builder builder);
- Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder,
- int index);
+
+ Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index);
}
/** OneofAccessor provides access to a single oneof. */
private static class OneofAccessor {
OneofAccessor(
- final Descriptor descriptor, final String camelCaseName,
+ final Descriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass) {
this.descriptor = descriptor;
- caseMethod =
- getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
- caseMethodBuilder =
- getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
+ caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
+ caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
}
@@ -2249,27 +2191,32 @@ public abstract class GeneratedMessage extends AbstractMessage
private static class SingularFieldAccessor implements FieldAccessor {
SingularFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass,
final String containingOneofCamelCaseName) {
field = descriptor;
isOneofField = descriptor.getContainingOneof() != null;
- hasHasMethod = supportFieldPresence(descriptor.getFile())
- || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
+ hasHasMethod =
+ supportFieldPresence(descriptor.getFile())
+ || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
getMethod = getMethodOrDie(messageClass, "get" + camelCaseName);
getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName);
type = getMethod.getReturnType();
setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type);
- hasMethod =
- hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null;
+ hasMethod = hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null;
hasMethodBuilder =
hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null;
clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
- caseMethod = isOneofField ? getMethodOrDie(
- messageClass, "get" + containingOneofCamelCaseName + "Case") : null;
- caseMethodBuilder = isOneofField ? getMethodOrDie(
- builderClass, "get" + containingOneofCamelCaseName + "Case") : null;
+ caseMethod =
+ isOneofField
+ ? getMethodOrDie(messageClass, "get" + containingOneofCamelCaseName + "Case")
+ : null;
+ caseMethodBuilder =
+ isOneofField
+ ? getMethodOrDie(builderClass, "get" + containingOneofCamelCaseName + "Case")
+ : null;
}
// Note: We use Java reflection to call public methods rather than
@@ -2300,52 +2247,59 @@ public abstract class GeneratedMessage extends AbstractMessage
public Object get(final GeneratedMessage message) {
return invokeOrDie(getMethod, message);
}
+
@Override
public Object get(GeneratedMessage.Builder builder) {
return invokeOrDie(getMethodBuilder, builder);
}
+
@Override
public Object getRaw(final GeneratedMessage message) {
return get(message);
}
+
@Override
public Object getRaw(GeneratedMessage.Builder builder) {
return get(builder);
}
+
@Override
public void set(final Builder builder, final Object value) {
invokeOrDie(setMethod, builder, value);
}
+
@Override
public Object getRepeated(final GeneratedMessage message, final int index) {
- throw new UnsupportedOperationException(
- "getRepeatedField() called on a singular field.");
+ throw new UnsupportedOperationException("getRepeatedField() called on a singular field.");
}
+
@Override
public Object getRepeatedRaw(final GeneratedMessage message, final int index) {
throw new UnsupportedOperationException(
- "getRepeatedFieldRaw() called on a singular field.");
+ "getRepeatedFieldRaw() called on a singular field.");
}
+
@Override
public Object getRepeated(GeneratedMessage.Builder builder, int index) {
- throw new UnsupportedOperationException(
- "getRepeatedField() called on a singular field.");
+ throw new UnsupportedOperationException("getRepeatedField() called on a singular field.");
}
+
@Override
public Object getRepeatedRaw(GeneratedMessage.Builder builder, int index) {
throw new UnsupportedOperationException(
- "getRepeatedFieldRaw() called on a singular field.");
+ "getRepeatedFieldRaw() called on a singular field.");
}
+
@Override
public void setRepeated(final Builder builder, final int index, final Object value) {
- throw new UnsupportedOperationException(
- "setRepeatedField() called on a singular field.");
+ throw new UnsupportedOperationException("setRepeatedField() called on a singular field.");
}
+
@Override
public void addRepeated(final Builder builder, final Object value) {
- throw new UnsupportedOperationException(
- "addRepeatedField() called on a singular field.");
+ throw new UnsupportedOperationException("addRepeatedField() called on a singular field.");
}
+
@Override
public boolean has(final GeneratedMessage message) {
if (!hasHasMethod) {
@@ -2356,6 +2310,7 @@ public abstract class GeneratedMessage extends AbstractMessage
}
return (Boolean) invokeOrDie(hasMethod, message);
}
+
@Override
public boolean has(GeneratedMessage.Builder builder) {
if (!hasHasMethod) {
@@ -2366,34 +2321,39 @@ public abstract class GeneratedMessage extends AbstractMessage
}
return (Boolean) invokeOrDie(hasMethodBuilder, builder);
}
+
@Override
public int getRepeatedCount(final GeneratedMessage message) {
throw new UnsupportedOperationException(
- "getRepeatedFieldSize() called on a singular field.");
+ "getRepeatedFieldSize() called on a singular field.");
}
+
@Override
public int getRepeatedCount(GeneratedMessage.Builder builder) {
throw new UnsupportedOperationException(
- "getRepeatedFieldSize() called on a singular field.");
+ "getRepeatedFieldSize() called on a singular field.");
}
+
@Override
public void clear(final Builder builder) {
invokeOrDie(clearMethod, builder);
}
+
@Override
public Message.Builder newBuilder() {
throw new UnsupportedOperationException(
- "newBuilderForField() called on a non-Message type.");
+ "newBuilderForField() called on a non-Message type.");
}
+
@Override
public Message.Builder getBuilder(GeneratedMessage.Builder builder) {
- throw new UnsupportedOperationException(
- "getFieldBuilder() called on a non-Message type.");
+ throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type.");
}
+
@Override
public Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index) {
throw new UnsupportedOperationException(
- "getRepeatedFieldBuilder() called on a non-Message type.");
+ "getRepeatedFieldBuilder() called on a non-Message type.");
}
}
@@ -2410,27 +2370,20 @@ public abstract class GeneratedMessage extends AbstractMessage
protected final Method clearMethod;
RepeatedFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass) {
- getMethod = getMethodOrDie(messageClass,
- "get" + camelCaseName + "List");
- getMethodBuilder = getMethodOrDie(builderClass,
- "get" + camelCaseName + "List");
- getRepeatedMethod =
- getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE);
+ getMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "List");
+ getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "List");
+ getRepeatedMethod = getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE);
getRepeatedMethodBuilder =
getMethodOrDie(builderClass, "get" + camelCaseName, Integer.TYPE);
type = getRepeatedMethod.getReturnType();
- setRepeatedMethod =
- getMethodOrDie(builderClass, "set" + camelCaseName,
- Integer.TYPE, type);
- addRepeatedMethod =
- getMethodOrDie(builderClass, "add" + camelCaseName, type);
- getCountMethod =
- getMethodOrDie(messageClass, "get" + camelCaseName + "Count");
- getCountMethodBuilder =
- getMethodOrDie(builderClass, "get" + camelCaseName + "Count");
+ setRepeatedMethod = getMethodOrDie(builderClass, "set" + camelCaseName, Integer.TYPE, type);
+ addRepeatedMethod = getMethodOrDie(builderClass, "add" + camelCaseName, type);
+ getCountMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Count");
+ getCountMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Count");
clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
}
@@ -2439,18 +2392,22 @@ public abstract class GeneratedMessage extends AbstractMessage
public Object get(final GeneratedMessage message) {
return invokeOrDie(getMethod, message);
}
+
@Override
public Object get(GeneratedMessage.Builder builder) {
return invokeOrDie(getMethodBuilder, builder);
}
+
@Override
public Object getRaw(final GeneratedMessage message) {
return get(message);
}
+
@Override
public Object getRaw(GeneratedMessage.Builder builder) {
return get(builder);
}
+
@Override
public void set(final Builder builder, final Object value) {
// Add all the elements individually. This serves two purposes:
@@ -2462,81 +2419,91 @@ public abstract class GeneratedMessage extends AbstractMessage
addRepeated(builder, element);
}
}
+
@Override
public Object getRepeated(final GeneratedMessage message, final int index) {
return invokeOrDie(getRepeatedMethod, message, index);
}
+
@Override
public Object getRepeated(GeneratedMessage.Builder builder, int index) {
return invokeOrDie(getRepeatedMethodBuilder, builder, index);
}
+
@Override
public Object getRepeatedRaw(GeneratedMessage message, int index) {
return getRepeated(message, index);
}
+
@Override
public Object getRepeatedRaw(GeneratedMessage.Builder builder, int index) {
return getRepeated(builder, index);
}
+
@Override
public void setRepeated(final Builder builder, final int index, final Object value) {
invokeOrDie(setRepeatedMethod, builder, index, value);
}
+
@Override
public void addRepeated(final Builder builder, final Object value) {
invokeOrDie(addRepeatedMethod, builder, value);
}
+
@Override
public boolean has(final GeneratedMessage message) {
- throw new UnsupportedOperationException(
- "hasField() called on a repeated field.");
+ throw new UnsupportedOperationException("hasField() called on a repeated field.");
}
+
@Override
public boolean has(GeneratedMessage.Builder builder) {
- throw new UnsupportedOperationException(
- "hasField() called on a repeated field.");
+ throw new UnsupportedOperationException("hasField() called on a repeated field.");
}
+
@Override
public int getRepeatedCount(final GeneratedMessage message) {
return (Integer) invokeOrDie(getCountMethod, message);
}
+
@Override
public int getRepeatedCount(GeneratedMessage.Builder builder) {
return (Integer) invokeOrDie(getCountMethodBuilder, builder);
}
+
@Override
public void clear(final Builder builder) {
invokeOrDie(clearMethod, builder);
}
+
@Override
public Message.Builder newBuilder() {
throw new UnsupportedOperationException(
- "newBuilderForField() called on a non-Message type.");
+ "newBuilderForField() called on a non-Message type.");
}
+
@Override
public Message.Builder getBuilder(GeneratedMessage.Builder builder) {
- throw new UnsupportedOperationException(
- "getFieldBuilder() called on a non-Message type.");
+ throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type.");
}
+
@Override
public Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index) {
throw new UnsupportedOperationException(
- "getRepeatedFieldBuilder() called on a non-Message type.");
+ "getRepeatedFieldBuilder() called on a non-Message type.");
}
}
private static class MapFieldAccessor implements FieldAccessor {
MapFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass) {
field = descriptor;
- Method getDefaultInstanceMethod =
- getMethodOrDie(messageClass, "getDefaultInstance");
- MapField defaultMapField = getMapField(
- (GeneratedMessage) invokeOrDie(getDefaultInstanceMethod, null));
- mapEntryMessageDefaultInstance =
- defaultMapField.getMapEntryMessageDefaultInstance();
+ Method getDefaultInstanceMethod = getMethodOrDie(messageClass, "getDefaultInstance");
+ MapField defaultMapField =
+ getMapField((GeneratedMessage) invokeOrDie(getDefaultInstanceMethod, null));
+ mapEntryMessageDefaultInstance = defaultMapField.getMapEntryMessageDefaultInstance();
}
private final FieldDescriptor field;
@@ -2550,10 +2517,8 @@ public abstract class GeneratedMessage extends AbstractMessage
return (MapField, ?>) builder.internalGetMapField(field.getNumber());
}
- private MapField, ?> getMutableMapField(
- GeneratedMessage.Builder builder) {
- return (MapField, ?>) builder.internalGetMutableMapField(
- field.getNumber());
+ private MapField, ?> getMutableMapField(GeneratedMessage.Builder builder) {
+ return (MapField, ?>) builder.internalGetMutableMapField(field.getNumber());
}
@Override
@@ -2626,14 +2591,12 @@ public abstract class GeneratedMessage extends AbstractMessage
@Override
public boolean has(GeneratedMessage message) {
- throw new UnsupportedOperationException(
- "hasField() is not supported for repeated fields.");
+ throw new UnsupportedOperationException("hasField() is not supported for repeated fields.");
}
@Override
public boolean has(Builder builder) {
- throw new UnsupportedOperationException(
- "hasField() is not supported for repeated fields.");
+ throw new UnsupportedOperationException("hasField() is not supported for repeated fields.");
}
@Override
@@ -2658,23 +2621,21 @@ public abstract class GeneratedMessage extends AbstractMessage
@Override
public com.google.protobuf.Message.Builder getBuilder(Builder builder) {
- throw new UnsupportedOperationException(
- "Nested builder not supported for map fields.");
+ throw new UnsupportedOperationException("Nested builder not supported for map fields.");
}
@Override
public com.google.protobuf.Message.Builder getRepeatedBuilder(Builder builder, int index) {
- throw new UnsupportedOperationException(
- "Nested builder not supported for map fields.");
+ throw new UnsupportedOperationException("Nested builder not supported for map fields.");
}
}
// ---------------------------------------------------------------
- private static final class SingularEnumFieldAccessor
- extends SingularFieldAccessor {
+ private static final class SingularEnumFieldAccessor extends SingularFieldAccessor {
SingularEnumFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass,
final String containingOneofCamelCaseName) {
@@ -2682,19 +2643,14 @@ public abstract class GeneratedMessage extends AbstractMessage
enumDescriptor = descriptor.getEnumType();
- valueOfMethod = getMethodOrDie(type, "valueOf",
- EnumValueDescriptor.class);
- getValueDescriptorMethod =
- getMethodOrDie(type, "getValueDescriptor");
+ valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class);
+ getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor");
supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
if (supportUnknownEnumValue) {
- getValueMethod =
- getMethodOrDie(messageClass, "get" + camelCaseName + "Value");
- getValueMethodBuilder =
- getMethodOrDie(builderClass, "get" + camelCaseName + "Value");
- setValueMethod =
- getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class);
+ getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value");
+ getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value");
+ setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class);
}
}
@@ -2729,28 +2685,25 @@ public abstract class GeneratedMessage extends AbstractMessage
@Override
public void set(final Builder builder, final Object value) {
if (supportUnknownEnumValue) {
- invokeOrDie(setValueMethod, builder,
- ((EnumValueDescriptor) value).getNumber());
+ invokeOrDie(setValueMethod, builder, ((EnumValueDescriptor) value).getNumber());
return;
}
super.set(builder, invokeOrDie(valueOfMethod, null, value));
}
}
- private static final class RepeatedEnumFieldAccessor
- extends RepeatedFieldAccessor {
+ private static final class RepeatedEnumFieldAccessor extends RepeatedFieldAccessor {
RepeatedEnumFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass) {
super(descriptor, camelCaseName, messageClass, builderClass);
enumDescriptor = descriptor.getEnumType();
- valueOfMethod = getMethodOrDie(type, "valueOf",
- EnumValueDescriptor.class);
- getValueDescriptorMethod =
- getMethodOrDie(type, "getValueDescriptor");
+ valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class);
+ getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor");
supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
if (supportUnknownEnumValue) {
@@ -2764,6 +2717,7 @@ public abstract class GeneratedMessage extends AbstractMessage
getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class);
}
}
+
private EnumDescriptor enumDescriptor;
private final Method valueOfMethod;
@@ -2798,41 +2752,37 @@ public abstract class GeneratedMessage extends AbstractMessage
}
@Override
- public Object getRepeated(final GeneratedMessage message,
- final int index) {
+ public Object getRepeated(final GeneratedMessage message, final int index) {
if (supportUnknownEnumValue) {
int value = (Integer) invokeOrDie(getRepeatedValueMethod, message, index);
return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
}
- return invokeOrDie(getValueDescriptorMethod,
- super.getRepeated(message, index));
+ return invokeOrDie(getValueDescriptorMethod, super.getRepeated(message, index));
}
+
@Override
- public Object getRepeated(final GeneratedMessage.Builder builder,
- final int index) {
+ public Object getRepeated(final GeneratedMessage.Builder builder, final int index) {
if (supportUnknownEnumValue) {
int value = (Integer) invokeOrDie(getRepeatedValueMethodBuilder, builder, index);
return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
}
- return invokeOrDie(getValueDescriptorMethod,
- super.getRepeated(builder, index));
+ return invokeOrDie(getValueDescriptorMethod, super.getRepeated(builder, index));
}
+
@Override
- public void setRepeated(final Builder builder,
- final int index, final Object value) {
+ public void setRepeated(final Builder builder, final int index, final Object value) {
if (supportUnknownEnumValue) {
- invokeOrDie(setRepeatedValueMethod, builder, index,
- ((EnumValueDescriptor) value).getNumber());
+ invokeOrDie(
+ setRepeatedValueMethod, builder, index, ((EnumValueDescriptor) value).getNumber());
return;
}
- super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null,
- value));
+ super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, value));
}
+
@Override
public void addRepeated(final Builder builder, final Object value) {
if (supportUnknownEnumValue) {
- invokeOrDie(addRepeatedValueMethod, builder,
- ((EnumValueDescriptor) value).getNumber());
+ invokeOrDie(addRepeatedValueMethod, builder, ((EnumValueDescriptor) value).getNumber());
return;
}
super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value));
@@ -2844,29 +2794,25 @@ public abstract class GeneratedMessage extends AbstractMessage
/**
* Field accessor for string fields.
*
- * This class makes getFooBytes() and setFooBytes() available for
- * reflection API so that reflection based serialize/parse functions can
- * access the raw bytes of the field to preserve non-UTF8 bytes in the
- * string.
+ * This class makes getFooBytes() and setFooBytes() available for reflection API so that
+ * reflection based serialize/parse functions can access the raw bytes of the field to preserve
+ * non-UTF8 bytes in the string.
*
- * This ensures the serialize/parse round-trip safety, which is important
- * for servers which forward messages.
+ * This ensures the serialize/parse round-trip safety, which is important for servers which
+ * forward messages.
*/
- private static final class SingularStringFieldAccessor
- extends SingularFieldAccessor {
+ private static final class SingularStringFieldAccessor extends SingularFieldAccessor {
SingularStringFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass,
final String containingOneofCamelCaseName) {
- super(descriptor, camelCaseName, messageClass, builderClass,
- containingOneofCamelCaseName);
- getBytesMethod = getMethodOrDie(messageClass,
- "get" + camelCaseName + "Bytes");
- getBytesMethodBuilder = getMethodOrDie(builderClass,
- "get" + camelCaseName + "Bytes");
- setBytesMethodBuilder = getMethodOrDie(builderClass,
- "set" + camelCaseName + "Bytes", ByteString.class);
+ super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName);
+ getBytesMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Bytes");
+ getBytesMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Bytes");
+ setBytesMethodBuilder =
+ getMethodOrDie(builderClass, "set" + camelCaseName + "Bytes", ByteString.class);
}
private final Method getBytesMethod;
@@ -2895,19 +2841,17 @@ public abstract class GeneratedMessage extends AbstractMessage
// ---------------------------------------------------------------
- private static final class SingularMessageFieldAccessor
- extends SingularFieldAccessor {
+ private static final class SingularMessageFieldAccessor extends SingularFieldAccessor {
SingularMessageFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass,
final String containingOneofCamelCaseName) {
- super(descriptor, camelCaseName, messageClass, builderClass,
- containingOneofCamelCaseName);
+ super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName);
newBuilderMethod = getMethodOrDie(type, "newBuilder");
- getBuilderMethodBuilder =
- getMethodOrDie(builderClass, "get" + camelCaseName + "Builder");
+ getBuilderMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Builder");
}
private final Method newBuilderMethod;
@@ -2922,7 +2866,8 @@ public abstract class GeneratedMessage extends AbstractMessage
// DynamicMessage -- we should accept it. In this case we can make
// a copy of the message.
return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
- .mergeFrom((Message) value).buildPartial();
+ .mergeFrom((Message) value)
+ .buildPartial();
}
}
@@ -2930,27 +2875,29 @@ public abstract class GeneratedMessage extends AbstractMessage
public void set(final Builder builder, final Object value) {
super.set(builder, coerceType(value));
}
+
@Override
public Message.Builder newBuilder() {
return (Message.Builder) invokeOrDie(newBuilderMethod, null);
}
+
@Override
public Message.Builder getBuilder(GeneratedMessage.Builder builder) {
return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder);
}
}
- private static final class RepeatedMessageFieldAccessor
- extends RepeatedFieldAccessor {
+ private static final class RepeatedMessageFieldAccessor extends RepeatedFieldAccessor {
RepeatedMessageFieldAccessor(
- final FieldDescriptor descriptor, final String camelCaseName,
+ final FieldDescriptor descriptor,
+ final String camelCaseName,
final Class extends GeneratedMessage> messageClass,
final Class extends Builder> builderClass) {
super(descriptor, camelCaseName, messageClass, builderClass);
newBuilderMethod = getMethodOrDie(type, "newBuilder");
- getBuilderMethodBuilder = getMethodOrDie(builderClass,
- "get" + camelCaseName + "Builder", Integer.TYPE);
+ getBuilderMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Builder", Integer.TYPE);
}
private final Method newBuilderMethod;
@@ -2965,36 +2912,39 @@ public abstract class GeneratedMessage extends AbstractMessage
// DynamicMessage -- we should accept it. In this case we can make
// a copy of the message.
return ((Message.Builder) invokeOrDie(newBuilderMethod, null))
- .mergeFrom((Message) value).build();
+ .mergeFrom((Message) value)
+ .build();
}
}
@Override
- public void setRepeated(final Builder builder,
- final int index, final Object value) {
+ public void setRepeated(final Builder builder, final int index, final Object value) {
super.setRepeated(builder, index, coerceType(value));
}
+
@Override
public void addRepeated(final Builder builder, final Object value) {
super.addRepeated(builder, coerceType(value));
}
+
@Override
public Message.Builder newBuilder() {
return (Message.Builder) invokeOrDie(newBuilderMethod, null);
}
+
@Override
public Message.Builder getRepeatedBuilder(
final GeneratedMessage.Builder builder, final int index) {
- return (Message.Builder) invokeOrDie(
- getBuilderMethodBuilder, builder, index);
+ return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder, index);
}
}
}
/**
- * Replaces this object in the output stream with a serialized form.
- * Part of Java's serialization magic. Generated sub-classes must override
- * this method by calling {@code return super.writeReplace();}
+ * Replaces this object in the output stream with a serialized form. Part of Java's serialization
+ * magic. Generated sub-classes must override this method by calling {@code return
+ * super.writeReplace();}
+ *
* @return a SerializedForm of this message
*/
protected Object writeReplace() throws ObjectStreamException {
@@ -3002,12 +2952,10 @@ public abstract class GeneratedMessage extends AbstractMessage
}
/**
- * Checks that the {@link Extension} is non-Lite and returns it as a
- * {@link GeneratedExtension}.
+ * Checks that the {@link Extension} is non-Lite and returns it as a {@link GeneratedExtension}.
*/
private static This can have a number of significant side affects that have spooky-action-at-a-distance-like
+ * This can have a number of significant side effects that have spooky-action-at-a-distance-like
* behavior. In particular, if the bytes value changes out from under a Protocol Buffer:
*
*
diff --git a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
index 9f36494a71..55e3079f93 100644
--- a/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
+++ b/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
@@ -101,9 +101,8 @@ public final class FieldMaskUtil {
/**
* Constructs a FieldMask for a list of field paths in a certain type.
*
- * @throws IllegalArgumentException if any of the field path is not valid.
+ * @throws IllegalArgumentException if any of the field path is not valid
*/
- // TODO(xiaofeng): Consider renaming fromStrings()
public static FieldMask fromStringList(Class extends Message> type, Iterable