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