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