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 std::map<string, string>* variables) { | 65 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"] = | 74 (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor)); |
75 SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor))); | |
76 (*variables)["tag_size"] = SimpleItoa( | 75 (*variables)["tag_size"] = SimpleItoa( |
77 WireFormat::TagSize(descriptor->number(), GetType(descriptor))); | 76 WireFormat::TagSize(descriptor->number(), GetType(descriptor))); |
78 (*variables)["null_check"] = | 77 (*variables)["null_check"] = |
79 " if (value == null) {\n" | 78 " if (value == null) {\n" |
80 " throw new NullPointerException();\n" | 79 " throw new NullPointerException();\n" |
81 " }\n"; | 80 " }\n"; |
82 (*variables)["writeString"] = | 81 (*variables)["writeString"] = |
83 "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + | 82 "com.google.protobuf.GeneratedMessage.writeString"; |
84 ".writeString"; | |
85 (*variables)["computeStringSize"] = | 83 (*variables)["computeStringSize"] = |
86 "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + | 84 "com.google.protobuf.GeneratedMessage.computeStringSize"; |
87 ".computeStringSize"; | |
88 | 85 |
89 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported | 86 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported |
90 // by the proto compiler | 87 // by the proto compiler |
91 (*variables)["deprecation"] = descriptor->options().deprecated() | 88 (*variables)["deprecation"] = descriptor->options().deprecated() |
92 ? "@java.lang.Deprecated " : ""; | 89 ? "@java.lang.Deprecated " : ""; |
93 (*variables)["on_changed"] = "onChanged();"; | 90 (*variables)["on_changed"] = "onChanged();"; |
94 | 91 |
95 if (SupportFieldPresence(descriptor->file())) { | 92 if (SupportFieldPresence(descriptor->file())) { |
96 // For singular messages and builders, one bit is used for the hasField bit. | 93 // For singular messages and builders, one bit is used for the hasField bit. |
97 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); | 94 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 } | 705 } |
709 | 706 |
710 int RepeatedImmutableStringFieldGenerator::GetNumBitsForBuilder() const { | 707 int RepeatedImmutableStringFieldGenerator::GetNumBitsForBuilder() const { |
711 return 1; | 708 return 1; |
712 } | 709 } |
713 | 710 |
714 void RepeatedImmutableStringFieldGenerator:: | 711 void RepeatedImmutableStringFieldGenerator:: |
715 GenerateInterfaceMembers(io::Printer* printer) const { | 712 GenerateInterfaceMembers(io::Printer* printer) const { |
716 WriteFieldDocComment(printer, descriptor_); | 713 WriteFieldDocComment(printer, descriptor_); |
717 printer->Print(variables_, | 714 printer->Print(variables_, |
718 // NOTE: the same method in the implementation class actually returns | 715 "$deprecation$com.google.protobuf.ProtocolStringList\n" |
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" | |
725 " get$capitalized_name$List();\n"); | 716 " get$capitalized_name$List();\n"); |
726 WriteFieldDocComment(printer, descriptor_); | 717 WriteFieldDocComment(printer, descriptor_); |
727 printer->Print(variables_, | 718 printer->Print(variables_, |
728 "$deprecation$int get$capitalized_name$Count();\n"); | 719 "$deprecation$int get$capitalized_name$Count();\n"); |
729 WriteFieldDocComment(printer, descriptor_); | 720 WriteFieldDocComment(printer, descriptor_); |
730 printer->Print(variables_, | 721 printer->Print(variables_, |
731 "$deprecation$java.lang.String get$capitalized_name$(int index);\n"); | 722 "$deprecation$java.lang.String get$capitalized_name$(int index);\n"); |
732 WriteFieldDocComment(printer, descriptor_); | 723 WriteFieldDocComment(printer, descriptor_); |
733 printer->Print(variables_, | 724 printer->Print(variables_, |
734 "$deprecation$com.google.protobuf.ByteString\n" | 725 "$deprecation$com.google.protobuf.ByteString\n" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 } | 988 } |
998 | 989 |
999 string RepeatedImmutableStringFieldGenerator::GetBoxedType() const { | 990 string RepeatedImmutableStringFieldGenerator::GetBoxedType() const { |
1000 return "String"; | 991 return "String"; |
1001 } | 992 } |
1002 | 993 |
1003 } // namespace java | 994 } // namespace java |
1004 } // namespace compiler | 995 } // namespace compiler |
1005 } // namespace protobuf | 996 } // namespace protobuf |
1006 } // namespace google | 997 } // namespace google |
OLD | NEW |