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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 using internal::WireFormat; | 55 using internal::WireFormat; |
56 using internal::WireFormatLite; | 56 using internal::WireFormatLite; |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
60 void SetPrimitiveVariables(const FieldDescriptor* descriptor, | 60 void SetPrimitiveVariables(const FieldDescriptor* descriptor, |
61 int messageBitIndex, | 61 int messageBitIndex, |
62 int builderBitIndex, | 62 int builderBitIndex, |
63 const FieldGeneratorInfo* info, | 63 const FieldGeneratorInfo* info, |
64 ClassNameResolver* name_resolver, | 64 ClassNameResolver* name_resolver, |
65 map<string, string>* variables) { | 65 std::map<string, string>* variables) { |
66 SetCommonFieldVariables(descriptor, info, variables); | 66 SetCommonFieldVariables(descriptor, info, variables); |
67 | 67 |
68 (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; | 68 (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; |
69 | 69 |
70 (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); | 70 (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); |
71 (*variables)["default_init"] = | 71 (*variables)["default_init"] = |
72 "= " + ImmutableDefaultValue(descriptor, name_resolver); | 72 "= " + ImmutableDefaultValue(descriptor, name_resolver); |
73 (*variables)["capitalized_type"] = "String"; | 73 (*variables)["capitalized_type"] = "String"; |
74 (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor)); | 74 (*variables)["tag"] = |
| 75 SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor))); |
75 (*variables)["tag_size"] = SimpleItoa( | 76 (*variables)["tag_size"] = SimpleItoa( |
76 WireFormat::TagSize(descriptor->number(), GetType(descriptor))); | 77 WireFormat::TagSize(descriptor->number(), GetType(descriptor))); |
77 (*variables)["null_check"] = | 78 (*variables)["null_check"] = |
78 " if (value == null) {\n" | 79 " if (value == null) {\n" |
79 " throw new NullPointerException();\n" | 80 " throw new NullPointerException();\n" |
80 " }\n"; | 81 " }\n"; |
81 (*variables)["writeString"] = | 82 (*variables)["writeString"] = |
82 "com.google.protobuf.GeneratedMessage.writeString"; | 83 "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + |
| 84 ".writeString"; |
83 (*variables)["computeStringSize"] = | 85 (*variables)["computeStringSize"] = |
84 "com.google.protobuf.GeneratedMessage.computeStringSize"; | 86 "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + |
| 87 ".computeStringSize"; |
85 | 88 |
86 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported | 89 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported |
87 // by the proto compiler | 90 // by the proto compiler |
88 (*variables)["deprecation"] = descriptor->options().deprecated() | 91 (*variables)["deprecation"] = descriptor->options().deprecated() |
89 ? "@java.lang.Deprecated " : ""; | 92 ? "@java.lang.Deprecated " : ""; |
90 (*variables)["on_changed"] = "onChanged();"; | 93 (*variables)["on_changed"] = "onChanged();"; |
91 | 94 |
92 if (SupportFieldPresence(descriptor->file())) { | 95 if (SupportFieldPresence(descriptor->file())) { |
93 // For singular messages and builders, one bit is used for the hasField bit. | 96 // For singular messages and builders, one bit is used for the hasField bit. |
94 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); | 97 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 708 } |
706 | 709 |
707 int RepeatedImmutableStringFieldGenerator::GetNumBitsForBuilder() const { | 710 int RepeatedImmutableStringFieldGenerator::GetNumBitsForBuilder() const { |
708 return 1; | 711 return 1; |
709 } | 712 } |
710 | 713 |
711 void RepeatedImmutableStringFieldGenerator:: | 714 void RepeatedImmutableStringFieldGenerator:: |
712 GenerateInterfaceMembers(io::Printer* printer) const { | 715 GenerateInterfaceMembers(io::Printer* printer) const { |
713 WriteFieldDocComment(printer, descriptor_); | 716 WriteFieldDocComment(printer, descriptor_); |
714 printer->Print(variables_, | 717 printer->Print(variables_, |
715 "$deprecation$com.google.protobuf.ProtocolStringList\n" | 718 // NOTE: the same method in the implementation class actually returns |
| 719 // com.google.protobuf.ProtocolStringList (a subclass of List). It's |
| 720 // changed between protobuf 2.5.0 release and protobuf 2.6.1 release. |
| 721 // To retain binary compatibility with both 2.5.0 and 2.6.1 generated |
| 722 // code, we make this interface method return List so both methods |
| 723 // with different return types exist in the compiled byte code. |
| 724 "$deprecation$java.util.List<java.lang.String>\n" |
716 " get$capitalized_name$List();\n"); | 725 " get$capitalized_name$List();\n"); |
717 WriteFieldDocComment(printer, descriptor_); | 726 WriteFieldDocComment(printer, descriptor_); |
718 printer->Print(variables_, | 727 printer->Print(variables_, |
719 "$deprecation$int get$capitalized_name$Count();\n"); | 728 "$deprecation$int get$capitalized_name$Count();\n"); |
720 WriteFieldDocComment(printer, descriptor_); | 729 WriteFieldDocComment(printer, descriptor_); |
721 printer->Print(variables_, | 730 printer->Print(variables_, |
722 "$deprecation$java.lang.String get$capitalized_name$(int index);\n"); | 731 "$deprecation$java.lang.String get$capitalized_name$(int index);\n"); |
723 WriteFieldDocComment(printer, descriptor_); | 732 WriteFieldDocComment(printer, descriptor_); |
724 printer->Print(variables_, | 733 printer->Print(variables_, |
725 "$deprecation$com.google.protobuf.ByteString\n" | 734 "$deprecation$com.google.protobuf.ByteString\n" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 } | 997 } |
989 | 998 |
990 string RepeatedImmutableStringFieldGenerator::GetBoxedType() const { | 999 string RepeatedImmutableStringFieldGenerator::GetBoxedType() const { |
991 return "String"; | 1000 return "String"; |
992 } | 1001 } |
993 | 1002 |
994 } // namespace java | 1003 } // namespace java |
995 } // namespace compiler | 1004 } // namespace compiler |
996 } // namespace protobuf | 1005 } // namespace protobuf |
997 } // namespace google | 1006 } // namespace google |
OLD | NEW |