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

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

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 } 864 }
865 865
866 /** See {@link FileDescriptor#setProto}. */ 866 /** See {@link FileDescriptor#setProto}. */
867 private void setProto(final DescriptorProto proto) { 867 private void setProto(final DescriptorProto proto) {
868 this.proto = proto; 868 this.proto = proto;
869 869
870 for (int i = 0; i < nestedTypes.length; i++) { 870 for (int i = 0; i < nestedTypes.length; i++) {
871 nestedTypes[i].setProto(proto.getNestedType(i)); 871 nestedTypes[i].setProto(proto.getNestedType(i));
872 } 872 }
873 873
874 for (int i = 0; i < oneofs.length; i++) {
875 oneofs[i].setProto(proto.getOneofDecl(i));
876 }
877
878 for (int i = 0; i < enumTypes.length; i++) { 874 for (int i = 0; i < enumTypes.length; i++) {
879 enumTypes[i].setProto(proto.getEnumType(i)); 875 enumTypes[i].setProto(proto.getEnumType(i));
880 } 876 }
881 877
882 for (int i = 0; i < fields.length; i++) { 878 for (int i = 0; i < fields.length; i++) {
883 fields[i].setProto(proto.getField(i)); 879 fields[i].setProto(proto.getField(i));
884 } 880 }
885 881
886 for (int i = 0; i < extensions.length; i++) { 882 for (int i = 0; i < extensions.length; i++) {
887 extensions[i].setProto(proto.getExtension(i)); 883 extensions[i].setProto(proto.getExtension(i));
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 this.defaultDefault = defaultDefault; 1201 this.defaultDefault = defaultDefault;
1206 } 1202 }
1207 1203
1208 /** 1204 /**
1209 * The default default value for fields of this type, if it's a primitive 1205 * The default default value for fields of this type, if it's a primitive
1210 * type. This is meant for use inside this file only, hence is private. 1206 * type. This is meant for use inside this file only, hence is private.
1211 */ 1207 */
1212 private final Object defaultDefault; 1208 private final Object defaultDefault;
1213 } 1209 }
1214 1210
1215 // This method should match exactly with the ToJsonName() function in C++ 1211 // TODO(xiaofeng): Implement it consistently across different languages. See b/24751348.
1216 // descriptor.cc. 1212 private static String fieldNameToLowerCamelCase(String name) {
1217 private static String fieldNameToJsonName(String name) {
1218 StringBuilder result = new StringBuilder(name.length()); 1213 StringBuilder result = new StringBuilder(name.length());
1219 boolean isNextUpperCase = false; 1214 boolean isNextUpperCase = false;
1220 for (int i = 0; i < name.length(); i++) { 1215 for (int i = 0; i < name.length(); i++) {
1221 Character ch = name.charAt(i); 1216 Character ch = name.charAt(i);
1222 if (ch == '_') { 1217 if (Character.isLowerCase(ch)) {
1223 isNextUpperCase = true; 1218 if (isNextUpperCase) {
1224 } else if (isNextUpperCase) { 1219 result.append(Character.toUpperCase(ch));
1225 result.append(Character.toUpperCase(ch)); 1220 } else {
1221 result.append(ch);
1222 }
1223 isNextUpperCase = false;
1224 } else if (Character.isUpperCase(ch)) {
1225 if (i == 0) {
1226 // Force first letter to lower-case.
1227 result.append(Character.toLowerCase(ch));
1228 } else {
1229 // Capital letters after the first are left as-is.
1230 result.append(ch);
1231 }
1232 isNextUpperCase = false;
1233 } else if (Character.isDigit(ch)) {
1234 result.append(ch);
1226 isNextUpperCase = false; 1235 isNextUpperCase = false;
1227 } else { 1236 } else {
1228 result.append(ch); 1237 isNextUpperCase = true;
1229 } 1238 }
1230 } 1239 }
1231 return result.toString(); 1240 return result.toString();
1232 } 1241 }
1233 1242
1234 private FieldDescriptor(final FieldDescriptorProto proto, 1243 private FieldDescriptor(final FieldDescriptorProto proto,
1235 final FileDescriptor file, 1244 final FileDescriptor file,
1236 final Descriptor parent, 1245 final Descriptor parent,
1237 final int index, 1246 final int index,
1238 final boolean isExtension) 1247 final boolean isExtension)
1239 throws DescriptorValidationException { 1248 throws DescriptorValidationException {
1240 this.index = index; 1249 this.index = index;
1241 this.proto = proto; 1250 this.proto = proto;
1242 fullName = computeFullName(file, parent, proto.getName()); 1251 fullName = computeFullName(file, parent, proto.getName());
1243 this.file = file; 1252 this.file = file;
1244 if (proto.hasJsonName()) { 1253 if (proto.hasJsonName()) {
1245 jsonName = proto.getJsonName(); 1254 jsonName = proto.getJsonName();
1246 } else { 1255 } else {
1247 jsonName = fieldNameToJsonName(proto.getName()); 1256 jsonName = fieldNameToLowerCamelCase(proto.getName());
1248 } 1257 }
1249 1258
1250 if (proto.hasType()) { 1259 if (proto.hasType()) {
1251 type = Type.valueOf(proto.getType()); 1260 type = Type.valueOf(proto.getType());
1252 } 1261 }
1253 1262
1254 if (getNumber() <= 0) { 1263 if (getNumber() <= 0) {
1255 throw new DescriptorValidationException(this, 1264 throw new DescriptorValidationException(this,
1256 "Field numbers must be positive integers."); 1265 "Field numbers must be positive integers.");
1257 } 1266 }
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 importPublicDependencies(dependencies[i]); 2125 importPublicDependencies(dependencies[i]);
2117 } 2126 }
2118 2127
2119 for (final FileDescriptor dependency : this.dependencies) { 2128 for (final FileDescriptor dependency : this.dependencies) {
2120 try { 2129 try {
2121 addPackage(dependency.getPackage(), dependency); 2130 addPackage(dependency.getPackage(), dependency);
2122 } catch (DescriptorValidationException e) { 2131 } catch (DescriptorValidationException e) {
2123 // Can't happen, because addPackage() only fails when the name 2132 // Can't happen, because addPackage() only fails when the name
2124 // conflicts with a non-package, but we have not yet added any 2133 // conflicts with a non-package, but we have not yet added any
2125 // non-packages at this point. 2134 // non-packages at this point.
2126 throw new AssertionError(e); 2135 assert false;
2127 } 2136 }
2128 } 2137 }
2129 } 2138 }
2130 2139
2131 /** Find and put public dependencies of the file into dependencies set.*/ 2140 /** Find and put public dependencies of the file into dependencies set.*/
2132 private void importPublicDependencies(final FileDescriptor file) { 2141 private void importPublicDependencies(final FileDescriptor file) {
2133 for (FileDescriptor dependency : file.getPublicDependencies()) { 2142 for (FileDescriptor dependency : file.getPublicDependencies()) {
2134 if (dependencies.add(dependency)) { 2143 if (dependencies.add(dependency)) {
2135 importPublicDependencies(dependency); 2144 importPublicDependencies(dependency);
2136 } 2145 }
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
2497 public String getName() { return proto.getName(); } 2506 public String getName() { return proto.getName(); }
2498 2507
2499 public FileDescriptor getFile() { return file; } 2508 public FileDescriptor getFile() { return file; }
2500 2509
2501 public String getFullName() { return fullName; } 2510 public String getFullName() { return fullName; }
2502 2511
2503 public Descriptor getContainingType() { return containingType; } 2512 public Descriptor getContainingType() { return containingType; }
2504 2513
2505 public int getFieldCount() { return fieldCount; } 2514 public int getFieldCount() { return fieldCount; }
2506 2515
2507 public OneofOptions getOptions() {
2508 return proto.getOptions();
2509 }
2510
2511 /** Get a list of this message type's fields. */ 2516 /** Get a list of this message type's fields. */
2512 public List<FieldDescriptor> getFields() { 2517 public List<FieldDescriptor> getFields() {
2513 return Collections.unmodifiableList(Arrays.asList(fields)); 2518 return Collections.unmodifiableList(Arrays.asList(fields));
2514 } 2519 }
2515 2520
2516 public FieldDescriptor getField(int index) { 2521 public FieldDescriptor getField(int index) {
2517 return fields[index]; 2522 return fields[index];
2518 } 2523 }
2519 2524
2520 private void setProto(final OneofDescriptorProto proto) {
2521 this.proto = proto;
2522 }
2523
2524 private OneofDescriptor(final OneofDescriptorProto proto, 2525 private OneofDescriptor(final OneofDescriptorProto proto,
2525 final FileDescriptor file, 2526 final FileDescriptor file,
2526 final Descriptor parent, 2527 final Descriptor parent,
2527 final int index) 2528 final int index)
2528 throws DescriptorValidationException { 2529 throws DescriptorValidationException {
2529 this.proto = proto; 2530 this.proto = proto;
2530 fullName = computeFullName(file, parent, proto.getName()); 2531 fullName = computeFullName(file, parent, proto.getName());
2531 this.file = file; 2532 this.file = file;
2532 this.index = index; 2533 this.index = index;
2533 2534
2534 containingType = parent; 2535 containingType = parent;
2535 fieldCount = 0; 2536 fieldCount = 0;
2536 } 2537 }
2537 2538
2538 private final int index; 2539 private final int index;
2539 private OneofDescriptorProto proto; 2540 private OneofDescriptorProto proto;
2540 private final String fullName; 2541 private final String fullName;
2541 private final FileDescriptor file; 2542 private final FileDescriptor file;
2542 2543
2543 private Descriptor containingType; 2544 private Descriptor containingType;
2544 private int fieldCount; 2545 private int fieldCount;
2545 private FieldDescriptor[] fields; 2546 private FieldDescriptor[] fields;
2546 } 2547 }
2547 } 2548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698