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

Unified Diff: third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java
index e00ea342ea0c3f2c59fbd80126b4e71d149b4c0d..38346f1559fb2192c7b32b278d49f73dd8fe0132 100644
--- a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java
@@ -871,6 +871,10 @@ public final class Descriptors {
nestedTypes[i].setProto(proto.getNestedType(i));
}
+ for (int i = 0; i < oneofs.length; i++) {
+ oneofs[i].setProto(proto.getOneofDecl(i));
+ }
+
for (int i = 0; i < enumTypes.length; i++) {
enumTypes[i].setProto(proto.getEnumType(i));
}
@@ -1208,33 +1212,20 @@ public final class Descriptors {
private final Object defaultDefault;
}
- // TODO(xiaofeng): Implement it consistently across different languages. See b/24751348.
- private static String fieldNameToLowerCamelCase(String name) {
+ // This method should match exactly with the ToJsonName() function in C++
+ // descriptor.cc.
+ private static String fieldNameToJsonName(String name) {
StringBuilder result = new StringBuilder(name.length());
boolean isNextUpperCase = false;
for (int i = 0; i < name.length(); i++) {
Character ch = name.charAt(i);
- if (Character.isLowerCase(ch)) {
- if (isNextUpperCase) {
- result.append(Character.toUpperCase(ch));
- } else {
- result.append(ch);
- }
- isNextUpperCase = false;
- } else if (Character.isUpperCase(ch)) {
- if (i == 0) {
- // Force first letter to lower-case.
- result.append(Character.toLowerCase(ch));
- } else {
- // Capital letters after the first are left as-is.
- result.append(ch);
- }
- isNextUpperCase = false;
- } else if (Character.isDigit(ch)) {
- result.append(ch);
+ if (ch == '_') {
+ isNextUpperCase = true;
+ } else if (isNextUpperCase) {
+ result.append(Character.toUpperCase(ch));
isNextUpperCase = false;
} else {
- isNextUpperCase = true;
+ result.append(ch);
}
}
return result.toString();
@@ -1253,7 +1244,7 @@ public final class Descriptors {
if (proto.hasJsonName()) {
jsonName = proto.getJsonName();
} else {
- jsonName = fieldNameToLowerCamelCase(proto.getName());
+ jsonName = fieldNameToJsonName(proto.getName());
}
if (proto.hasType()) {
@@ -2132,7 +2123,7 @@ public final class Descriptors {
// Can't happen, because addPackage() only fails when the name
// conflicts with a non-package, but we have not yet added any
// non-packages at this point.
- assert false;
+ throw new AssertionError(e);
}
}
}
@@ -2513,6 +2504,10 @@ public final class Descriptors {
public int getFieldCount() { return fieldCount; }
+ public OneofOptions getOptions() {
+ return proto.getOptions();
+ }
+
/** Get a list of this message type's fields. */
public List<FieldDescriptor> getFields() {
return Collections.unmodifiableList(Arrays.asList(fields));
@@ -2522,6 +2517,10 @@ public final class Descriptors {
return fields[index];
}
+ private void setProto(final OneofDescriptorProto proto) {
+ this.proto = proto;
+ }
+
private OneofDescriptor(final OneofDescriptorProto proto,
final FileDescriptor file,
final Descriptor parent,

Powered by Google App Engine
This is Rietveld 408576698