| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 namespace compiler { | 51 namespace compiler { |
| 52 namespace java { | 52 namespace java { |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 void SetEnumVariables(const FieldDescriptor* descriptor, | 56 void SetEnumVariables(const FieldDescriptor* descriptor, |
| 57 int messageBitIndex, | 57 int messageBitIndex, |
| 58 int builderBitIndex, | 58 int builderBitIndex, |
| 59 const FieldGeneratorInfo* info, | 59 const FieldGeneratorInfo* info, |
| 60 ClassNameResolver* name_resolver, | 60 ClassNameResolver* name_resolver, |
| 61 map<string, string>* variables) { | 61 std::map<string, string>* variables) { |
| 62 SetCommonFieldVariables(descriptor, info, variables); | 62 SetCommonFieldVariables(descriptor, info, variables); |
| 63 | 63 |
| 64 (*variables)["type"] = | 64 (*variables)["type"] = |
| 65 name_resolver->GetImmutableClassName(descriptor->enum_type()); | 65 name_resolver->GetImmutableClassName(descriptor->enum_type()); |
| 66 (*variables)["mutable_type"] = | 66 (*variables)["mutable_type"] = |
| 67 name_resolver->GetMutableClassName(descriptor->enum_type()); | 67 name_resolver->GetMutableClassName(descriptor->enum_type()); |
| 68 (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); | 68 (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); |
| 69 (*variables)["default_number"] = SimpleItoa( | 69 (*variables)["default_number"] = SimpleItoa( |
| 70 descriptor->default_value_enum()->number()); | 70 descriptor->default_value_enum()->number()); |
| 71 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor)); | 71 (*variables)["tag"] = |
| 72 SimpleItoa(static_cast<int32>(internal::WireFormat::MakeTag(descriptor))); |
| 72 (*variables)["tag_size"] = SimpleItoa( | 73 (*variables)["tag_size"] = SimpleItoa( |
| 73 internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); | 74 internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); |
| 74 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported | 75 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported |
| 75 // by the proto compiler | 76 // by the proto compiler |
| 76 (*variables)["deprecation"] = descriptor->options().deprecated() | 77 (*variables)["deprecation"] = descriptor->options().deprecated() |
| 77 ? "@java.lang.Deprecated " : ""; | 78 ? "@java.lang.Deprecated " : ""; |
| 78 (*variables)["on_changed"] = "onChanged();"; | 79 (*variables)["on_changed"] = "onChanged();"; |
| 80 // Use deprecated valueOf() method to be compatible with old generated code |
| 81 // for v2.5.0/v2.6.1. |
| 82 // TODO(xiaofeng): Use "forNumber" when we no longer support compatibility |
| 83 // with v2.5.0/v2.6.1. |
| 84 (*variables)["for_number"] = "valueOf"; |
| 79 | 85 |
| 80 if (SupportFieldPresence(descriptor->file())) { | 86 if (SupportFieldPresence(descriptor->file())) { |
| 81 // For singular messages and builders, one bit is used for the hasField bit. | 87 // For singular messages and builders, one bit is used for the hasField bit. |
| 82 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); | 88 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); |
| 83 (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); | 89 (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); |
| 84 | 90 |
| 85 // Note that these have a trailing ";". | 91 // Note that these have a trailing ";". |
| 86 (*variables)["set_has_field_bit_message"] = | 92 (*variables)["set_has_field_bit_message"] = |
| 87 GenerateSetBit(messageBitIndex) + ";"; | 93 GenerateSetBit(messageBitIndex) + ";"; |
| 88 (*variables)["set_has_field_bit_builder"] = | 94 (*variables)["set_has_field_bit_builder"] = |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (SupportUnknownEnumValue(descriptor_->file())) { | 190 if (SupportUnknownEnumValue(descriptor_->file())) { |
| 185 WriteFieldDocComment(printer, descriptor_); | 191 WriteFieldDocComment(printer, descriptor_); |
| 186 printer->Print(variables_, | 192 printer->Print(variables_, |
| 187 "$deprecation$public int get$capitalized_name$Value() {\n" | 193 "$deprecation$public int get$capitalized_name$Value() {\n" |
| 188 " return $name$_;\n" | 194 " return $name$_;\n" |
| 189 "}\n"); | 195 "}\n"); |
| 190 } | 196 } |
| 191 WriteFieldDocComment(printer, descriptor_); | 197 WriteFieldDocComment(printer, descriptor_); |
| 192 printer->Print(variables_, | 198 printer->Print(variables_, |
| 193 "$deprecation$public $type$ get$capitalized_name$() {\n" | 199 "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 194 " $type$ result = $type$.forNumber($name$_);\n" | 200 " $type$ result = $type$.$for_number$($name$_);\n" |
| 195 " return result == null ? $unknown$ : result;\n" | 201 " return result == null ? $unknown$ : result;\n" |
| 196 "}\n"); | 202 "}\n"); |
| 197 } | 203 } |
| 198 | 204 |
| 199 void ImmutableEnumFieldGenerator:: | 205 void ImmutableEnumFieldGenerator:: |
| 200 GenerateBuilderMembers(io::Printer* printer) const { | 206 GenerateBuilderMembers(io::Printer* printer) const { |
| 201 printer->Print(variables_, | 207 printer->Print(variables_, |
| 202 "private int $name$_ = $default_number$;\n"); | 208 "private int $name$_ = $default_number$;\n"); |
| 203 if (SupportFieldPresence(descriptor_->file())) { | 209 if (SupportFieldPresence(descriptor_->file())) { |
| 204 WriteFieldDocComment(printer, descriptor_); | 210 WriteFieldDocComment(printer, descriptor_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 217 printer->Print(variables_, | 223 printer->Print(variables_, |
| 218 "$deprecation$public Builder set$capitalized_name$Value(int value) {\n" | 224 "$deprecation$public Builder set$capitalized_name$Value(int value) {\n" |
| 219 " $name$_ = value;\n" | 225 " $name$_ = value;\n" |
| 220 " $on_changed$\n" | 226 " $on_changed$\n" |
| 221 " return this;\n" | 227 " return this;\n" |
| 222 "}\n"); | 228 "}\n"); |
| 223 } | 229 } |
| 224 WriteFieldDocComment(printer, descriptor_); | 230 WriteFieldDocComment(printer, descriptor_); |
| 225 printer->Print(variables_, | 231 printer->Print(variables_, |
| 226 "$deprecation$public $type$ get$capitalized_name$() {\n" | 232 "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 227 " $type$ result = $type$.forNumber($name$_);\n" | 233 " $type$ result = $type$.$for_number$($name$_);\n" |
| 228 " return result == null ? $unknown$ : result;\n" | 234 " return result == null ? $unknown$ : result;\n" |
| 229 "}\n"); | 235 "}\n"); |
| 230 WriteFieldDocComment(printer, descriptor_); | 236 WriteFieldDocComment(printer, descriptor_); |
| 231 printer->Print(variables_, | 237 printer->Print(variables_, |
| 232 "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" | 238 "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" |
| 233 " if (value == null) {\n" | 239 " if (value == null) {\n" |
| 234 " throw new NullPointerException();\n" | 240 " throw new NullPointerException();\n" |
| 235 " }\n" | 241 " }\n" |
| 236 " $set_has_field_bit_builder$\n" | 242 " $set_has_field_bit_builder$\n" |
| 237 " $name$_ = value.getNumber();\n" | 243 " $name$_ = value.getNumber();\n" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 void ImmutableEnumFieldGenerator:: | 303 void ImmutableEnumFieldGenerator:: |
| 298 GenerateParsingCode(io::Printer* printer) const { | 304 GenerateParsingCode(io::Printer* printer) const { |
| 299 if (SupportUnknownEnumValue(descriptor_->file())) { | 305 if (SupportUnknownEnumValue(descriptor_->file())) { |
| 300 printer->Print(variables_, | 306 printer->Print(variables_, |
| 301 "int rawValue = input.readEnum();\n" | 307 "int rawValue = input.readEnum();\n" |
| 302 "$set_has_field_bit_message$\n" | 308 "$set_has_field_bit_message$\n" |
| 303 "$name$_ = rawValue;\n"); | 309 "$name$_ = rawValue;\n"); |
| 304 } else { | 310 } else { |
| 305 printer->Print(variables_, | 311 printer->Print(variables_, |
| 306 "int rawValue = input.readEnum();\n" | 312 "int rawValue = input.readEnum();\n" |
| 307 "$type$ value = $type$.forNumber(rawValue);\n" | 313 "$type$ value = $type$.$for_number$(rawValue);\n" |
| 308 "if (value == null) {\n"); | 314 "if (value == null) {\n"); |
| 309 if (PreserveUnknownFields(descriptor_->containing_type())) { | 315 if (PreserveUnknownFields(descriptor_->containing_type())) { |
| 310 printer->Print(variables_, | 316 printer->Print(variables_, |
| 311 " unknownFields.mergeVarintField($number$, rawValue);\n"); | 317 " unknownFields.mergeVarintField($number$, rawValue);\n"); |
| 312 } | 318 } |
| 313 printer->Print(variables_, | 319 printer->Print(variables_, |
| 314 "} else {\n" | 320 "} else {\n" |
| 315 " $set_has_field_bit_message$\n" | 321 " $set_has_field_bit_message$\n" |
| 316 " $name$_ = rawValue;\n" | 322 " $name$_ = rawValue;\n" |
| 317 "}\n"); | 323 "}\n"); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 " if ($has_oneof_case_message$) {\n" | 397 " if ($has_oneof_case_message$) {\n" |
| 392 " return (java.lang.Integer) $oneof_name$_;\n" | 398 " return (java.lang.Integer) $oneof_name$_;\n" |
| 393 " }\n" | 399 " }\n" |
| 394 " return $default_number$;\n" | 400 " return $default_number$;\n" |
| 395 "}\n"); | 401 "}\n"); |
| 396 } | 402 } |
| 397 WriteFieldDocComment(printer, descriptor_); | 403 WriteFieldDocComment(printer, descriptor_); |
| 398 printer->Print(variables_, | 404 printer->Print(variables_, |
| 399 "$deprecation$public $type$ get$capitalized_name$() {\n" | 405 "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 400 " if ($has_oneof_case_message$) {\n" | 406 " if ($has_oneof_case_message$) {\n" |
| 401 " $type$ result = $type$.forNumber((java.lang.Integer) $oneof_name$_);\n" | 407 " $type$ result = $type$.$for_number$(\n" |
| 408 " (java.lang.Integer) $oneof_name$_);\n" |
| 402 " return result == null ? $unknown$ : result;\n" | 409 " return result == null ? $unknown$ : result;\n" |
| 403 " }\n" | 410 " }\n" |
| 404 " return $default$;\n" | 411 " return $default$;\n" |
| 405 "}\n"); | 412 "}\n"); |
| 406 } | 413 } |
| 407 | 414 |
| 408 void ImmutableEnumOneofFieldGenerator:: | 415 void ImmutableEnumOneofFieldGenerator:: |
| 409 GenerateBuilderMembers(io::Printer* printer) const { | 416 GenerateBuilderMembers(io::Printer* printer) const { |
| 410 if (SupportFieldPresence(descriptor_->file())) { | 417 if (SupportFieldPresence(descriptor_->file())) { |
| 411 WriteFieldDocComment(printer, descriptor_); | 418 WriteFieldDocComment(printer, descriptor_); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 429 " $set_oneof_case_message$;\n" | 436 " $set_oneof_case_message$;\n" |
| 430 " $oneof_name$_ = value;\n" | 437 " $oneof_name$_ = value;\n" |
| 431 " $on_changed$\n" | 438 " $on_changed$\n" |
| 432 " return this;\n" | 439 " return this;\n" |
| 433 "}\n"); | 440 "}\n"); |
| 434 } | 441 } |
| 435 WriteFieldDocComment(printer, descriptor_); | 442 WriteFieldDocComment(printer, descriptor_); |
| 436 printer->Print(variables_, | 443 printer->Print(variables_, |
| 437 "$deprecation$public $type$ get$capitalized_name$() {\n" | 444 "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 438 " if ($has_oneof_case_message$) {\n" | 445 " if ($has_oneof_case_message$) {\n" |
| 439 " $type$ result = $type$.forNumber((java.lang.Integer) $oneof_name$_);\n" | 446 " $type$ result = $type$.$for_number$(\n" |
| 447 " (java.lang.Integer) $oneof_name$_);\n" |
| 440 " return result == null ? $unknown$ : result;\n" | 448 " return result == null ? $unknown$ : result;\n" |
| 441 " }\n" | 449 " }\n" |
| 442 " return $default$;\n" | 450 " return $default$;\n" |
| 443 "}\n"); | 451 "}\n"); |
| 444 WriteFieldDocComment(printer, descriptor_); | 452 WriteFieldDocComment(printer, descriptor_); |
| 445 printer->Print(variables_, | 453 printer->Print(variables_, |
| 446 "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" | 454 "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" |
| 447 " if (value == null) {\n" | 455 " if (value == null) {\n" |
| 448 " throw new NullPointerException();\n" | 456 " throw new NullPointerException();\n" |
| 449 " }\n" | 457 " }\n" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 void ImmutableEnumOneofFieldGenerator:: | 494 void ImmutableEnumOneofFieldGenerator:: |
| 487 GenerateParsingCode(io::Printer* printer) const { | 495 GenerateParsingCode(io::Printer* printer) const { |
| 488 if (SupportUnknownEnumValue(descriptor_->file())) { | 496 if (SupportUnknownEnumValue(descriptor_->file())) { |
| 489 printer->Print(variables_, | 497 printer->Print(variables_, |
| 490 "int rawValue = input.readEnum();\n" | 498 "int rawValue = input.readEnum();\n" |
| 491 "$set_oneof_case_message$;\n" | 499 "$set_oneof_case_message$;\n" |
| 492 "$oneof_name$_ = rawValue;\n"); | 500 "$oneof_name$_ = rawValue;\n"); |
| 493 } else { | 501 } else { |
| 494 printer->Print(variables_, | 502 printer->Print(variables_, |
| 495 "int rawValue = input.readEnum();\n" | 503 "int rawValue = input.readEnum();\n" |
| 496 "$type$ value = $type$.forNumber(rawValue);\n" | 504 "$type$ value = $type$.$for_number$(rawValue);\n" |
| 497 "if (value == null) {\n"); | 505 "if (value == null) {\n"); |
| 498 if (PreserveUnknownFields(descriptor_->containing_type())) { | 506 if (PreserveUnknownFields(descriptor_->containing_type())) { |
| 499 printer->Print(variables_, | 507 printer->Print(variables_, |
| 500 " unknownFields.mergeVarintField($number$, rawValue);\n"); | 508 " unknownFields.mergeVarintField($number$, rawValue);\n"); |
| 501 } | 509 } |
| 502 printer->Print(variables_, | 510 printer->Print(variables_, |
| 503 "} else {\n" | 511 "} else {\n" |
| 504 " $set_oneof_case_message$;\n" | 512 " $set_oneof_case_message$;\n" |
| 505 " $oneof_name$_ = rawValue;\n" | 513 " $oneof_name$_ = rawValue;\n" |
| 506 "}\n"); | 514 "}\n"); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 607 |
| 600 void RepeatedImmutableEnumFieldGenerator:: | 608 void RepeatedImmutableEnumFieldGenerator:: |
| 601 GenerateMembers(io::Printer* printer) const { | 609 GenerateMembers(io::Printer* printer) const { |
| 602 printer->Print(variables_, | 610 printer->Print(variables_, |
| 603 "private java.util.List<java.lang.Integer> $name$_;\n" | 611 "private java.util.List<java.lang.Integer> $name$_;\n" |
| 604 "private static final com.google.protobuf.Internal.ListAdapter.Converter<\n" | 612 "private static final com.google.protobuf.Internal.ListAdapter.Converter<\n" |
| 605 " java.lang.Integer, $type$> $name$_converter_ =\n" | 613 " java.lang.Integer, $type$> $name$_converter_ =\n" |
| 606 " new com.google.protobuf.Internal.ListAdapter.Converter<\n" | 614 " new com.google.protobuf.Internal.ListAdapter.Converter<\n" |
| 607 " java.lang.Integer, $type$>() {\n" | 615 " java.lang.Integer, $type$>() {\n" |
| 608 " public $type$ convert(java.lang.Integer from) {\n" | 616 " public $type$ convert(java.lang.Integer from) {\n" |
| 609 " $type$ result = $type$.forNumber(from);\n" | 617 " $type$ result = $type$.$for_number$(from);\n" |
| 610 " return result == null ? $unknown$ : result;\n" | 618 " return result == null ? $unknown$ : result;\n" |
| 611 " }\n" | 619 " }\n" |
| 612 " };\n"); | 620 " };\n"); |
| 613 PrintExtraFieldInfo(variables_, printer); | 621 PrintExtraFieldInfo(variables_, printer); |
| 614 WriteFieldDocComment(printer, descriptor_); | 622 WriteFieldDocComment(printer, descriptor_); |
| 615 printer->Print(variables_, | 623 printer->Print(variables_, |
| 616 "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" | 624 "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" |
| 617 " return new com.google.protobuf.Internal.ListAdapter<\n" | 625 " return new com.google.protobuf.Internal.ListAdapter<\n" |
| 618 " java.lang.Integer, $type$>($name$_, $name$_converter_);\n" | 626 " java.lang.Integer, $type$>($name$_, $name$_converter_);\n" |
| 619 "}\n"); | 627 "}\n"); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 printer->Print(variables_, | 840 printer->Print(variables_, |
| 833 "int rawValue = input.readEnum();\n" | 841 "int rawValue = input.readEnum();\n" |
| 834 "if (!$get_mutable_bit_parser$) {\n" | 842 "if (!$get_mutable_bit_parser$) {\n" |
| 835 " $name$_ = new java.util.ArrayList<java.lang.Integer>();\n" | 843 " $name$_ = new java.util.ArrayList<java.lang.Integer>();\n" |
| 836 " $set_mutable_bit_parser$;\n" | 844 " $set_mutable_bit_parser$;\n" |
| 837 "}\n" | 845 "}\n" |
| 838 "$name$_.add(rawValue);\n"); | 846 "$name$_.add(rawValue);\n"); |
| 839 } else { | 847 } else { |
| 840 printer->Print(variables_, | 848 printer->Print(variables_, |
| 841 "int rawValue = input.readEnum();\n" | 849 "int rawValue = input.readEnum();\n" |
| 842 "$type$ value = $type$.forNumber(rawValue);\n" | 850 "$type$ value = $type$.$for_number$(rawValue);\n" |
| 843 "if (value == null) {\n"); | 851 "if (value == null) {\n"); |
| 844 if (PreserveUnknownFields(descriptor_->containing_type())) { | 852 if (PreserveUnknownFields(descriptor_->containing_type())) { |
| 845 printer->Print(variables_, | 853 printer->Print(variables_, |
| 846 " unknownFields.mergeVarintField($number$, rawValue);\n"); | 854 " unknownFields.mergeVarintField($number$, rawValue);\n"); |
| 847 } | 855 } |
| 848 printer->Print(variables_, | 856 printer->Print(variables_, |
| 849 "} else {\n" | 857 "} else {\n" |
| 850 " if (!$get_mutable_bit_parser$) {\n" | 858 " if (!$get_mutable_bit_parser$) {\n" |
| 851 " $name$_ = new java.util.ArrayList<java.lang.Integer>();\n" | 859 " $name$_ = new java.util.ArrayList<java.lang.Integer>();\n" |
| 852 " $set_mutable_bit_parser$;\n" | 860 " $set_mutable_bit_parser$;\n" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 880 "if ($get_mutable_bit_parser$) {\n" | 888 "if ($get_mutable_bit_parser$) {\n" |
| 881 " $name$_ = java.util.Collections.unmodifiableList($name$_);\n" | 889 " $name$_ = java.util.Collections.unmodifiableList($name$_);\n" |
| 882 "}\n"); | 890 "}\n"); |
| 883 } | 891 } |
| 884 | 892 |
| 885 void RepeatedImmutableEnumFieldGenerator:: | 893 void RepeatedImmutableEnumFieldGenerator:: |
| 886 GenerateSerializationCode(io::Printer* printer) const { | 894 GenerateSerializationCode(io::Printer* printer) const { |
| 887 if (descriptor_->is_packed()) { | 895 if (descriptor_->is_packed()) { |
| 888 printer->Print(variables_, | 896 printer->Print(variables_, |
| 889 "if (get$capitalized_name$List().size() > 0) {\n" | 897 "if (get$capitalized_name$List().size() > 0) {\n" |
| 890 " output.writeRawVarint32($tag$);\n" | 898 " output.writeUInt32NoTag($tag$);\n" |
| 891 " output.writeRawVarint32($name$MemoizedSerializedSize);\n" | 899 " output.writeUInt32NoTag($name$MemoizedSerializedSize);\n" |
| 892 "}\n" | 900 "}\n" |
| 893 "for (int i = 0; i < $name$_.size(); i++) {\n" | 901 "for (int i = 0; i < $name$_.size(); i++) {\n" |
| 894 " output.writeEnumNoTag($name$_.get(i));\n" | 902 " output.writeEnumNoTag($name$_.get(i));\n" |
| 895 "}\n"); | 903 "}\n"); |
| 896 } else { | 904 } else { |
| 897 printer->Print(variables_, | 905 printer->Print(variables_, |
| 898 "for (int i = 0; i < $name$_.size(); i++) {\n" | 906 "for (int i = 0; i < $name$_.size(); i++) {\n" |
| 899 " output.writeEnum($number$, $name$_.get(i));\n" | 907 " output.writeEnum($number$, $name$_.get(i));\n" |
| 900 "}\n"); | 908 "}\n"); |
| 901 } | 909 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 913 " dataSize += com.google.protobuf.CodedOutputStream\n" | 921 " dataSize += com.google.protobuf.CodedOutputStream\n" |
| 914 " .computeEnumSizeNoTag($name$_.get(i));\n" | 922 " .computeEnumSizeNoTag($name$_.get(i));\n" |
| 915 "}\n"); | 923 "}\n"); |
| 916 printer->Print( | 924 printer->Print( |
| 917 "size += dataSize;\n"); | 925 "size += dataSize;\n"); |
| 918 if (descriptor_->is_packed()) { | 926 if (descriptor_->is_packed()) { |
| 919 printer->Print(variables_, | 927 printer->Print(variables_, |
| 920 "if (!get$capitalized_name$List().isEmpty()) {" | 928 "if (!get$capitalized_name$List().isEmpty()) {" |
| 921 " size += $tag_size$;\n" | 929 " size += $tag_size$;\n" |
| 922 " size += com.google.protobuf.CodedOutputStream\n" | 930 " size += com.google.protobuf.CodedOutputStream\n" |
| 923 " .computeRawVarint32Size(dataSize);\n" | 931 " .computeUInt32SizeNoTag(dataSize);\n" |
| 924 "}"); | 932 "}"); |
| 925 } else { | 933 } else { |
| 926 printer->Print(variables_, | 934 printer->Print(variables_, |
| 927 "size += $tag_size$ * $name$_.size();\n"); | 935 "size += $tag_size$ * $name$_.size();\n"); |
| 928 } | 936 } |
| 929 | 937 |
| 930 // cache the data size for packed fields. | 938 // cache the data size for packed fields. |
| 931 if (descriptor_->is_packed()) { | 939 if (descriptor_->is_packed()) { |
| 932 printer->Print(variables_, | 940 printer->Print(variables_, |
| 933 "$name$MemoizedSerializedSize = dataSize;\n"); | 941 "$name$MemoizedSerializedSize = dataSize;\n"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 953 } | 961 } |
| 954 | 962 |
| 955 string RepeatedImmutableEnumFieldGenerator::GetBoxedType() const { | 963 string RepeatedImmutableEnumFieldGenerator::GetBoxedType() const { |
| 956 return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); | 964 return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); |
| 957 } | 965 } |
| 958 | 966 |
| 959 } // namespace java | 967 } // namespace java |
| 960 } // namespace compiler | 968 } // namespace compiler |
| 961 } // namespace protobuf | 969 } // namespace protobuf |
| 962 } // namespace google | 970 } // namespace google |
| OLD | NEW |