| 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 | 79 |
| 79 if (SupportFieldPresence(descriptor->file())) { | 80 if (SupportFieldPresence(descriptor->file())) { |
| 80 // 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. |
| 81 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); | 82 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 "}\n"); | 252 "}\n"); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void ImmutableEnumFieldLiteGenerator:: | 255 void ImmutableEnumFieldLiteGenerator:: |
| 255 GenerateFieldBuilderInitializationCode(io::Printer* printer) const { | 256 GenerateFieldBuilderInitializationCode(io::Printer* printer) const { |
| 256 // noop for enums | 257 // noop for enums |
| 257 } | 258 } |
| 258 | 259 |
| 259 void ImmutableEnumFieldLiteGenerator:: | 260 void ImmutableEnumFieldLiteGenerator:: |
| 260 GenerateInitializationCode(io::Printer* printer) const { | 261 GenerateInitializationCode(io::Printer* printer) const { |
| 261 printer->Print(variables_, "$name$_ = $default_number$;\n"); | 262 if (!IsDefaultValueJavaDefault(descriptor_)) { |
| 263 printer->Print(variables_, "$name$_ = $default_number$;\n"); |
| 264 } |
| 262 } | 265 } |
| 263 | 266 |
| 264 void ImmutableEnumFieldLiteGenerator:: | 267 void ImmutableEnumFieldLiteGenerator:: |
| 265 GenerateVisitCode(io::Printer* printer) const { | 268 GenerateVisitCode(io::Printer* printer) const { |
| 266 if (SupportFieldPresence(descriptor_->file())) { | 269 if (SupportFieldPresence(descriptor_->file())) { |
| 267 printer->Print(variables_, | 270 printer->Print(variables_, |
| 268 "$name$_ = visitor.visitInt(has$capitalized_name$(), $name$_,\n" | 271 "$name$_ = visitor.visitInt(has$capitalized_name$(), $name$_,\n" |
| 269 " other.has$capitalized_name$(), other.$name$_);\n"); | 272 " other.has$capitalized_name$(), other.$name$_);\n"); |
| 270 } else if (SupportUnknownEnumValue(descriptor_->file())) { | 273 } else if (SupportUnknownEnumValue(descriptor_->file())) { |
| 271 printer->Print(variables_, | 274 printer->Print(variables_, |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 "if ($is_mutable$) {\n" | 881 "if ($is_mutable$) {\n" |
| 879 " $name$_.makeImmutable();\n" | 882 " $name$_.makeImmutable();\n" |
| 880 "}\n"); | 883 "}\n"); |
| 881 } | 884 } |
| 882 | 885 |
| 883 void RepeatedImmutableEnumFieldLiteGenerator:: | 886 void RepeatedImmutableEnumFieldLiteGenerator:: |
| 884 GenerateSerializationCode(io::Printer* printer) const { | 887 GenerateSerializationCode(io::Printer* printer) const { |
| 885 if (descriptor_->options().packed()) { | 888 if (descriptor_->options().packed()) { |
| 886 printer->Print(variables_, | 889 printer->Print(variables_, |
| 887 "if (get$capitalized_name$List().size() > 0) {\n" | 890 "if (get$capitalized_name$List().size() > 0) {\n" |
| 888 " output.writeRawVarint32($tag$);\n" | 891 " output.writeUInt32NoTag($tag$);\n" |
| 889 " output.writeRawVarint32($name$MemoizedSerializedSize);\n" | 892 " output.writeUInt32NoTag($name$MemoizedSerializedSize);\n" |
| 890 "}\n" | 893 "}\n" |
| 891 "for (int i = 0; i < $name$_.size(); i++) {\n" | 894 "for (int i = 0; i < $name$_.size(); i++) {\n" |
| 892 " output.writeEnumNoTag($name$_.getInt(i));\n" | 895 " output.writeEnumNoTag($name$_.getInt(i));\n" |
| 893 "}\n"); | 896 "}\n"); |
| 894 } else { | 897 } else { |
| 895 printer->Print(variables_, | 898 printer->Print(variables_, |
| 896 "for (int i = 0; i < $name$_.size(); i++) {\n" | 899 "for (int i = 0; i < $name$_.size(); i++) {\n" |
| 897 " output.writeEnum($number$, $name$_.getInt(i));\n" | 900 " output.writeEnum($number$, $name$_.getInt(i));\n" |
| 898 "}\n"); | 901 "}\n"); |
| 899 } | 902 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 911 " dataSize += com.google.protobuf.CodedOutputStream\n" | 914 " dataSize += com.google.protobuf.CodedOutputStream\n" |
| 912 " .computeEnumSizeNoTag($name$_.getInt(i));\n" | 915 " .computeEnumSizeNoTag($name$_.getInt(i));\n" |
| 913 "}\n"); | 916 "}\n"); |
| 914 printer->Print( | 917 printer->Print( |
| 915 "size += dataSize;\n"); | 918 "size += dataSize;\n"); |
| 916 if (descriptor_->options().packed()) { | 919 if (descriptor_->options().packed()) { |
| 917 printer->Print(variables_, | 920 printer->Print(variables_, |
| 918 "if (!get$capitalized_name$List().isEmpty()) {" | 921 "if (!get$capitalized_name$List().isEmpty()) {" |
| 919 " size += $tag_size$;\n" | 922 " size += $tag_size$;\n" |
| 920 " size += com.google.protobuf.CodedOutputStream\n" | 923 " size += com.google.protobuf.CodedOutputStream\n" |
| 921 " .computeRawVarint32Size(dataSize);\n" | 924 " .computeUInt32SizeNoTag(dataSize);\n" |
| 922 "}"); | 925 "}"); |
| 923 } else { | 926 } else { |
| 924 printer->Print(variables_, | 927 printer->Print(variables_, |
| 925 "size += $tag_size$ * $name$_.size();\n"); | 928 "size += $tag_size$ * $name$_.size();\n"); |
| 926 } | 929 } |
| 927 | 930 |
| 928 // cache the data size for packed fields. | 931 // cache the data size for packed fields. |
| 929 if (descriptor_->options().packed()) { | 932 if (descriptor_->options().packed()) { |
| 930 printer->Print(variables_, | 933 printer->Print(variables_, |
| 931 "$name$MemoizedSerializedSize = dataSize;\n"); | 934 "$name$MemoizedSerializedSize = dataSize;\n"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 951 } | 954 } |
| 952 | 955 |
| 953 string RepeatedImmutableEnumFieldLiteGenerator::GetBoxedType() const { | 956 string RepeatedImmutableEnumFieldLiteGenerator::GetBoxedType() const { |
| 954 return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); | 957 return name_resolver_->GetImmutableClassName(descriptor_->enum_type()); |
| 955 } | 958 } |
| 956 | 959 |
| 957 } // namespace java | 960 } // namespace java |
| 958 } // namespace compiler | 961 } // namespace compiler |
| 959 } // namespace protobuf | 962 } // namespace protobuf |
| 960 } // namespace google | 963 } // namespace google |
| OLD | NEW |