My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
Changes to /trunk/src/google/protobuf/compiler/java/java_string_field.cc
r383 vs. r393 Compare: vs.  Format:
Revision r393
Go to: 
Project members, sign in to write a code review
/trunk/src/google/protobuf/compiler/java/java_string_field.cc   r383 /trunk/src/google/protobuf/compiler/java/java_string_field.cc   r393
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 // http://code.google.com/p/protobuf/ 3 // http://code.google.com/p/protobuf/
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.
11 // * Redistributions in binary form must reproduce the above 11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer 12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the 13 // in the documentation and/or other materials provided with the
14 // distribution. 14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its 15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from 16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission. 17 // this software without specific prior written permission.
18 // 18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 // Author: kenton@google.com (Kenton Varda) 31 // Author: kenton@google.com (Kenton Varda)
32 // Author: jonp@google.com (Jon Perlow) 32 // Author: jonp@google.com (Jon Perlow)
33 // Based on original Protocol Buffers design by 33 // Based on original Protocol Buffers design by
34 // Sanjay Ghemawat, Jeff Dean, and others. 34 // Sanjay Ghemawat, Jeff Dean, and others.
35 35
36 #include <map> 36 #include <map>
37 #include <string> 37 #include <string>
38 38
39 #include <google/protobuf/compiler/java/java_string_field.h> 39 #include <google/protobuf/compiler/java/java_string_field.h>
40 #include <google/protobuf/stubs/common.h> 40 #include <google/protobuf/stubs/common.h>
41 #include <google/protobuf/compiler/java/java_helpers.h> 41 #include <google/protobuf/compiler/java/java_helpers.h>
42 #include <google/protobuf/io/printer.h> 42 #include <google/protobuf/io/printer.h>
43 #include <google/protobuf/wire_format.h> 43 #include <google/protobuf/wire_format.h>
44 #include <google/protobuf/stubs/strutil.h> 44 #include <google/protobuf/stubs/strutil.h>
45 45
46 namespace google { 46 namespace google {
47 namespace protobuf { 47 namespace protobuf {
48 namespace compiler { 48 namespace compiler {
49 namespace java { 49 namespace java {
50 50
51 using internal::WireFormat; 51 using internal::WireFormat;
52 using internal::WireFormatLite; 52 using internal::WireFormatLite;
53 53
54 namespace { 54 namespace {
55 55
56 void SetPrimitiveVariables(const FieldDescriptor* descriptor, 56 void SetPrimitiveVariables(const FieldDescriptor* descriptor,
57 int messageBitIndex, 57 int messageBitIndex,
58 int builderBitIndex, 58 int builderBitIndex,
59 map<string, string>* variables) { 59 map<string, string>* variables) {
60 (*variables)["name"] = 60 (*variables)["name"] =
61 UnderscoresToCamelCase(descriptor); 61 UnderscoresToCamelCase(descriptor);
62 (*variables)["capitalized_name"] = 62 (*variables)["capitalized_name"] =
63 UnderscoresToCapitalizedCamelCase(descriptor); 63 UnderscoresToCapitalizedCamelCase(descriptor);
64 (*variables)["constant_name"] = FieldConstantName(descriptor); 64 (*variables)["constant_name"] = FieldConstantName(descriptor);
65 (*variables)["number"] = SimpleItoa(descriptor->number()); 65 (*variables)["number"] = SimpleItoa(descriptor->number());
66 (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; 66 (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY";
67 67
68 (*variables)["default"] = DefaultValue(descriptor); 68 (*variables)["default"] = DefaultValue(descriptor);
69 (*variables)["default_init"] = ("= " + DefaultValue(descriptor)); 69 (*variables)["default_init"] = ("= " + DefaultValue(descriptor));
70 (*variables)["capitalized_type"] = "String"; 70 (*variables)["capitalized_type"] = "String";
71 (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor)); 71 (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor));
72 (*variables)["tag_size"] = SimpleItoa( 72 (*variables)["tag_size"] = SimpleItoa(
73 WireFormat::TagSize(descriptor->number(), GetType(descriptor))); 73 WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
74 (*variables)["null_check"] = 74 (*variables)["null_check"] =
75 " if (value == null) {\n" 75 " if (value == null) {\n"
76 " throw new NullPointerException();\n" 76 " throw new NullPointerException();\n"
77 " }\n"; 77 " }\n";
78 78
79 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported 79 // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
80 // by the proto compiler 80 // by the proto compiler
81 (*variables)["deprecation"] = descriptor->options().deprecated() 81 (*variables)["deprecation"] = descriptor->options().deprecated()
82 ? "@java.lang.Deprecated " : ""; 82 ? "@java.lang.Deprecated " : "";
83 (*variables)["on_changed"] = 83 (*variables)["on_changed"] =
84 HasDescriptorMethods(descriptor->containing_type()) ? "onChanged();" : ""; 84 HasDescriptorMethods(descriptor->containing_type()) ? "onChanged();" : "";
85 85
86 // For singular messages and builders, one bit is used for the hasField bit. 86 // For singular messages and builders, one bit is used for the hasField bit.
87 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); 87 (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
88 88
89 (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); 89 (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
90 (*variables)["set_has_field_bit_builder"] = GenerateSetBit(builderBitIndex); 90 (*variables)["set_has_field_bit_builder"] = GenerateSetBit(builderBitIndex);
91 (*variables)["clear_has_field_bit_builder"] = 91 (*variables)["clear_has_field_bit_builder"] =
92 GenerateClearBit(builderBitIndex); 92 GenerateClearBit(builderBitIndex);
93 93
94 // For repated builders, one bit is used for whether the array is immutable. 94 // For repated builders, one bit is used for whether the array is immutable.
95 (*variables)["get_mutable_bit_builder"] = GenerateGetBit(builderBitIndex); 95 (*variables)["get_mutable_bit_builder"] = GenerateGetBit(builderBitIndex);
96 (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); 96 (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex);
97 (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); 97 (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex);
98 98
99 (*variables)["get_has_field_bit_from_local"] = 99 (*variables)["get_has_field_bit_from_local"] =
100 GenerateGetBitFromLocal(builderBitIndex); 100 GenerateGetBitFromLocal(builderBitIndex);
101 (*variables)["set_has_field_bit_to_local"] = 101 (*variables)["set_has_field_bit_to_local"] =
102 GenerateSetBitToLocal(messageBitIndex); 102 GenerateSetBitToLocal(messageBitIndex);
103 } 103 }
104 104
105 } // namespace 105 } // namespace
106 106
107 // =================================================================== 107 // ===================================================================
108 108
109 StringFieldGenerator:: 109 StringFieldGenerator::
110 StringFieldGenerator(const FieldDescriptor* descriptor, 110 StringFieldGenerator(const FieldDescriptor* descriptor,
111 int messageBitIndex, 111 int messageBitIndex,
112 int builderBitIndex) 112 int builderBitIndex)
113 : descriptor_(descriptor), messageBitIndex_(messageBitIndex), 113 : descriptor_(descriptor), messageBitIndex_(messageBitIndex),
114 builderBitIndex_(builderBitIndex) { 114 builderBitIndex_(builderBitIndex) {
115 SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, 115 SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
116 &variables_); 116 &variables_);
117 } 117 }
118 118
119 StringFieldGenerator::~StringFieldGenerator() {} 119 StringFieldGenerator::~StringFieldGenerator() {}
120 120
121 int StringFieldGenerator::GetNumBitsForMessage() const { 121 int StringFieldGenerator::GetNumBitsForMessage() const {
122 return 1; 122 return 1;
123 } 123 }
124 124
125 int StringFieldGenerator::GetNumBitsForBuilder() const { 125 int StringFieldGenerator::GetNumBitsForBuilder() const {
126 return 1; 126 return 1;
127 } 127 }
128 128
129 // A note about how strings are handled. This code used to just store a String 129 // A note about how strings are handled. This code used to just store a String
130 // in the Message. This had two issues: 130 // in the Message. This had two issues:
131 // 131 //
132 // 1. It wouldn't roundtrip byte arrays that were not vaid UTF-8 encoded 132 // 1. It wouldn't roundtrip byte arrays that were not vaid UTF-8 encoded
133 // strings, but rather fields that were raw bytes incorrectly marked 133 // strings, but rather fields that were raw bytes incorrectly marked
134 // as strings in the proto file. This is common because in the proto1 134 // as strings in the proto file. This is common because in the proto1
135 // syntax, string was the way to indicate bytes and C++ engineers can 135 // syntax, string was the way to indicate bytes and C++ engineers can
136 // easily make this mistake without affecting the C++ API. By converting to 136 // easily make this mistake without affecting the C++ API. By converting to
137 // strings immediately, some java code might corrupt these byte arrays as 137 // strings immediately, some java code might corrupt these byte arrays as
138 // it passes through a java server even if the field was never accessed by 138 // it passes through a java server even if the field was never accessed by
139 // application code. 139 // application code.
140 // 140 //
141 // 2. There's a performance hit to converting between bytes and strings and 141 // 2. There's a performance hit to converting between bytes and strings and
142 // it many cases, the field is never even read by the application code. This 142 // it many cases, the field is never even read by the application code. This
143 // avoids unnecessary conversions in the common use cases. 143 // avoids unnecessary conversions in the common use cases.
144 // 144 //
145 // So now, the field for String is maintained as an Object reference which can 145 // So now, the field for String is maintained as an Object reference which can
146 // either store a String or a ByteString. The code uses an instanceof check 146 // either store a String or a ByteString. The code uses an instanceof check
147 // to see which one it has and converts to the other one if needed. It remembers 147 // to see which one it has and converts to the other one if needed. It remembers
148 // the last value requested (in a thread safe manner) as this is most likely 148 // the last value requested (in a thread safe manner) as this is most likely
149 // the one needed next. The thread safety is such that if two threads both 149 // the one needed next. The thread safety is such that if two threads both
150 // convert the field because the changes made by each thread were not visible to 150 // convert the field because the changes made by each thread were not visible to
151 // the other, they may cause a conversion to happen more times than would 151 // the other, they may cause a conversion to happen more times than would
152 // otherwise be necessary. This was deemed better than adding synchronization 152 // otherwise be necessary. This was deemed better than adding synchronization
153 // overhead. It will not cause any corruption issues or affect the behavior of 153 // overhead. It will not cause any corruption issues or affect the behavior of
154 // the API. The instanceof check is also highly optimized in the JVM and we 154 // the API. The instanceof check is also highly optimized in the JVM and we
155 // decided it was better to reduce the memory overhead by not having two 155 // decided it was better to reduce the memory overhead by not having two
156 // separate fields but rather use dynamic type checking. 156 // separate fields but rather use dynamic type checking.
157 // 157 //
158 // For single fields, the logic for this is done inside the generated code. For 158 // For single fields, the logic for this is done inside the generated code. For
159 // repeated fields, the logic is done in LazyStringArrayList and 159 // repeated fields, the logic is done in LazyStringArrayList and
160 // UnmodifiableLazyStringList. 160 // UnmodifiableLazyStringList.
161 void StringFieldGenerator:: 161 void StringFieldGenerator::
162 GenerateInterfaceMembers(io::Printer* printer) const { 162 GenerateInterfaceMembers(io::Printer* printer) const {
163 printer->Print(variables_, 163 printer->Print(variables_,
164 "$deprecation$boolean has$capitalized_name$();\n" 164 "$deprecation$boolean has$capitalized_name$();\n"
165 "$deprecation$String get$capitalized_name$();\n"); 165 "$deprecation$java.lang.String get$capitalized_name$();\n");
166 } 166 }
167 167
168 void StringFieldGenerator:: 168 void StringFieldGenerator::
169 GenerateMembers(io::Printer* printer) const { 169 GenerateMembers(io::Printer* printer) const {
170 printer->Print(variables_, 170 printer->Print(variables_,
171 "private java.lang.Object $name$_;\n" 171 "private java.lang.Object $name$_;\n"
172 "$deprecation$public boolean has$capitalized_name$() {\n" 172 "$deprecation$public boolean has$capitalized_name$() {\n"
173 " return $get_has_field_bit_message$;\n" 173 " return $get_has_field_bit_message$;\n"
174 "}\n"); 174 "}\n");
175 175
176 printer->Print(variables_, 176 printer->Print(variables_,
177 "$deprecation$public String get$capitalized_name$() {\n" 177 "$deprecation$public java.lang.String get$capitalized_name$() {\n"
178 " java.lang.Object ref = $name$_;\n" 178 " java.lang.Object ref = $name$_;\n"
179 " if (ref instanceof String) {\n" 179 " if (ref instanceof java.lang.String) {\n"
180 " return (String) ref;\n" 180 " return (java.lang.String) ref;\n"
181 " } else {\n" 181 " } else {\n"
182 " com.google.protobuf.ByteString bs = \n" 182 " com.google.protobuf.ByteString bs = \n"
183 " (com.google.protobuf.ByteString) ref;\n" 183 " (com.google.protobuf.ByteString) ref;\n"
184 " String s = bs.toStringUtf8();\n" 184 " java.lang.String s = bs.toStringUtf8();\n"
185 " if (com.google.protobuf.Internal.isValidUtf8(bs)) {\n" 185 " if (com.google.protobuf.Internal.isValidUtf8(bs)) {\n"
186 " $name$_ = s;\n" 186 " $name$_ = s;\n"
187 " }\n" 187 " }\n"
188 " return s;\n" 188 " return s;\n"
189 " }\n" 189 " }\n"
190 "}\n" 190 "}\n"
191 "private com.google.protobuf.ByteString get$capitalized_name$Bytes() {\n" 191 "private com.google.protobuf.ByteString get$capitalized_name$Bytes() {\n"
192 " java.lang.Object ref = $name$_;\n" 192 " java.lang.Object ref = $name$_;\n"
193 " if (ref instanceof String) {\n" 193 " if (ref instanceof java.lang.String) {\n"
194 " com.google.protobuf.ByteString b = \n" 194 " com.google.protobuf.ByteString b = \n"
195 " com.google.protobuf.ByteString.copyFromUtf8((String) ref);\n" 195 " com.google.protobuf.ByteString.copyFromUtf8(\n"
196 " (java.lang.String) ref);\n"
196 " $name$_ = b;\n" 197 " $name$_ = b;\n"
197 " return b;\n" 198 " return b;\n"
198 " } else {\n" 199 " } else {\n"
199 " return (com.google.protobuf.ByteString) ref;\n" 200 " return (com.google.protobuf.ByteString) ref;\n"
200 " }\n" 201 " }\n"
201 "}\n"); 202 "}\n");
202 } 203 }
203 204
204 void StringFieldGenerator:: 205 void StringFieldGenerator::
205 GenerateBuilderMembers(io::Printer* printer) const { 206 GenerateBuilderMembers(io::Printer* printer) const {
206 printer->Print(variables_, 207 printer->Print(variables_,
207 "private java.lang.Object $name$_ $default_init$;\n" 208 "private java.lang.Object $name$_ $default_init$;\n"
208 "$deprecation$public boolean has$capitalized_name$() {\n" 209 "$deprecation$public boolean has$capitalized_name$() {\n"
209 " return $get_has_field_bit_builder$;\n" 210 " return $get_has_field_bit_builder$;\n"
210 "}\n"); 211 "}\n");
211 212
212 printer->Print(variables_, 213 printer->Print(variables_,
213 "$deprecation$public String get$capitalized_name$() {\n" 214 "$deprecation$public java.lang.String get$capitalized_name$() {\n"
214 " java.lang.Object ref = $name$_;\n" 215 " java.lang.Object ref = $name$_;\n"
215 " if (!(ref instanceof String)) {\n" 216 " if (!(ref instanceof java.lang.String)) {\n"
216 " String s = ((com.google.protobuf.ByteString) ref).toStringUtf8();\n" 217 " java.lang.String s = ((com.google.protobuf.ByteString) ref)\n"
218 " .toStringUtf8();\n"
217 " $name$_ = s;\n" 219 " $name$_ = s;\n"
218 " return s;\n" 220 " return s;\n"
219 " } else {\n" 221 " } else {\n"
220 " return (String) ref;\n" 222 " return (java.lang.String) ref;\n"
221 " }\n" 223 " }\n"
222 "}\n"); 224 "}\n");
223 225
224 printer->Print(variables_, 226 printer->Print(variables_,
225 "$deprecation$public Builder set$capitalized_name$(String value) {\n" 227 "$deprecation$public Builder set$capitalized_name$(\n"
228 " java.lang.String value) {\n"
226 "$null_check$" 229 "$null_check$"
227 " $set_has_field_bit_builder$;\n" 230 " $set_has_field_bit_builder$;\n"
228 " $name$_ = value;\n" 231 " $name$_ = value;\n"
229 " $on_changed$\n" 232 " $on_changed$\n"
230 " return this;\n" 233 " return this;\n"
231 "}\n" 234 "}\n"
232 "$deprecation$public Builder clear$capitalized_name$() {\n" 235 "$deprecation$public Builder clear$capitalized_name$() {\n"
233 " $clear_has_field_bit_builder$;\n"); 236 " $clear_has_field_bit_builder$;\n");
234 // The default value is not a simple literal so we want to avoid executing 237 // The default value is not a simple literal so we want to avoid executing
235 // it multiple times. Instead, get the default out of the default instance. 238 // it multiple times. Instead, get the default out of the default instance.
236 printer->Print(variables_, 239 printer->Print(variables_,
237 " $name$_ = getDefaultInstance().get$capitalized_name$();\n"); 240 " $name$_ = getDefaultInstance().get$capitalized_name$();\n");
238 printer->Print(variables_, 241 printer->Print(variables_,
239 " $on_changed$\n" 242 " $on_changed$\n"
240 " return this;\n" 243 " return this;\n"
241 "}\n"); 244 "}\n");
242 245
243 printer->Print(variables_, 246 printer->Print(variables_,
244 "void set$capitalized_name$(com.google.protobuf.ByteString value) {\n" 247 "void set$capitalized_name$(com.google.protobuf.ByteString value) {\n"
245 " $set_has_field_bit_builder$;\n" 248 " $set_has_field_bit_builder$;\n"
246 " $name$_ = value;\n" 249 " $name$_ = value;\n"
247 " $on_changed$\n" 250 " $on_changed$\n"
248 "}\n"); 251 "}\n");
249 } 252 }
250 253
251 void StringFieldGenerator:: 254 void StringFieldGenerator::
252 GenerateFieldBuilderInitializationCode(io::Printer* printer) const { 255 GenerateFieldBuilderInitializationCode(io::Printer* printer) const {
253 // noop for primitives 256 // noop for primitives
254 } 257 }
255 258
256 void StringFieldGenerator:: 259 void StringFieldGenerator::
257 GenerateInitializationCode(io::Printer* printer) const { 260 GenerateInitializationCode(io::Printer* printer) const {
258 printer->Print(variables_, "$name$_ = $default$;\n"); 261 printer->Print(variables_, "$name$_ = $default$;\n");
259 } 262 }
260 263
261 void StringFieldGenerator:: 264 void StringFieldGenerator::
262 GenerateBuilderClearCode(io::Printer* printer) const { 265 GenerateBuilderClearCode(io::Printer* printer) const {
263 printer->Print(variables_, 266 printer->Print(variables_,
264 "$name$_ = $default$;\n" 267 "$name$_ = $default$;\n"
265 "$clear_has_field_bit_builder$;\n"); 268 "$clear_has_field_bit_builder$;\n");
266 } 269 }
267 270
268 void StringFieldGenerator:: 271 void StringFieldGenerator::
269 GenerateMergingCode(io::Printer* printer) const { 272 GenerateMergingCode(io::Printer* printer) const {
270 printer->Print(variables_, 273 printer->Print(variables_,
271 "if (other.has$capitalized_name$()) {\n" 274 "if (other.has$capitalized_name$()) {\n"
272 " set$capitalized_name$(other.get$capitalized_name$());\n" 275 " set$capitalized_name$(other.get$capitalized_name$());\n"
273 "}\n"); 276 "}\n");
274 } 277 }
275 278
276 void StringFieldGenerator:: 279 void StringFieldGenerator::
277 GenerateBuildingCode(io::Printer* printer) const { 280 GenerateBuildingCode(io::Printer* printer) const {
278 printer->Print(variables_, 281 printer->Print(variables_,
279 "if ($get_has_field_bit_from_local$) {\n" 282 "if ($get_has_field_bit_from_local$) {\n"
280 " $set_has_field_bit_to_local$;\n" 283 " $set_has_field_bit_to_local$;\n"
281 "}\n" 284 "}\n"
282 "result.$name$_ = $name$_;\n"); 285 "result.$name$_ = $name$_;\n");
283 } 286 }
284 287
285 void StringFieldGenerator:: 288 void StringFieldGenerator::
286 GenerateParsingCode(io::Printer* printer) const { 289 GenerateParsingCode(io::Printer* printer) const {
287 printer->Print(variables_, 290 printer->Print(variables_,
288 "$set_has_field_bit_builder$;\n" 291 "$set_has_field_bit_builder$;\n"
289 "$name$_ = input.readBytes();\n"); 292 "$name$_ = input.readBytes();\n");
290 } 293 }
291 294
292 void StringFieldGenerator:: 295 void StringFieldGenerator::
293 GenerateSerializationCode(io::Printer* printer) const { 296 GenerateSerializationCode(io::Printer* printer) const {
294 printer->Print(variables_, 297 printer->Print(variables_,
295 "if ($get_has_field_bit_message$) {\n" 298 "if ($get_has_field_bit_message$) {\n"
296 " output.writeBytes($number$, get$capitalized_name$Bytes());\n" 299 " output.writeBytes($number$, get$capitalized_name$Bytes());\n"
297 "}\n"); 300 "}\n");
298 } 301 }
299 302
300 void StringFieldGenerator:: 303 void StringFieldGenerator::
301 GenerateSerializedSizeCode(io::Printer* printer) const { 304 GenerateSerializedSizeCode(io::Printer* printer) const {
302 printer->Print(variables_, 305 printer->Print(variables_,
303 "if ($get_has_field_bit_message$) {\n" 306 "if ($get_has_field_bit_message$) {\n"
304 " size += com.google.protobuf.CodedOutputStream\n" 307 " size += com.google.protobuf.CodedOutputStream\n"
305 " .computeBytesSize($number$, get$capitalized_name$Bytes());\n" 308 " .computeBytesSize($number$, get$capitalized_name$Bytes());\n"
306 "}\n"); 309 "}\n");
307 } 310 }
308 311
309 void StringFieldGenerator:: 312 void StringFieldGenerator::
310 GenerateEqualsCode(io::Printer* printer) const { 313 GenerateEqualsCode(io::Printer* printer) const {
311 printer->Print(variables_, 314 printer->Print(variables_,
312 "result = result && get$capitalized_name$()\n" 315 "result = result && get$capitalized_name$()\n"
313 " .equals(other.get$capitalized_name$());\n"); 316 " .equals(other.get$capitalized_name$());\n");
314 } 317 }
315 318
316 void StringFieldGenerator:: 319 void StringFieldGenerator::
317 GenerateHashCode(io::Printer* printer) const { 320 GenerateHashCode(io::Printer* printer) const {
318 printer->Print(variables_, 321 printer->Print(variables_,
319 "hash = (37 * hash) + $constant_name$;\n"); 322 "hash = (37 * hash) + $constant_name$;\n");
320 printer->Print(variables_, 323 printer->Print(variables_,
321 "hash = (53 * hash) + get$capitalized_name$().hashCode();\n"); 324 "hash = (53 * hash) + get$capitalized_name$().hashCode();\n");
322 } 325 }
323 326
324 string StringFieldGenerator::GetBoxedType() const { 327 string StringFieldGenerator::GetBoxedType() const {
325 return "String"; 328 return "java.lang.String";
326 } 329 }
327 330
328 331
329 // =================================================================== 332 // ===================================================================
330 333
331 RepeatedStringFieldGenerator:: 334 RepeatedStringFieldGenerator::
332 RepeatedStringFieldGenerator(const FieldDescriptor* descriptor, 335 RepeatedStringFieldGenerator(const FieldDescriptor* descriptor,
333 int messageBitIndex, 336 int messageBitIndex,
334 int builderBitIndex) 337 int builderBitIndex)
335 : descriptor_(descriptor), messageBitIndex_(messageBitIndex), 338 : descriptor_(descriptor), messageBitIndex_(messageBitIndex),
336 builderBitIndex_(builderBitIndex) { 339 builderBitIndex_(builderBitIndex) {
337 SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, 340 SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
338 &variables_); 341 &variables_);
339 } 342 }
340 343
341 RepeatedStringFieldGenerator::~RepeatedStringFieldGenerator() {} 344 RepeatedStringFieldGenerator::~RepeatedStringFieldGenerator() {}
342 345
343 int RepeatedStringFieldGenerator::GetNumBitsForMessage() const { 346 int RepeatedStringFieldGenerator::GetNumBitsForMessage() const {
344 return 0; 347 return 0;
345 } 348 }
346 349
347 int RepeatedStringFieldGenerator::GetNumBitsForBuilder() const { 350 int RepeatedStringFieldGenerator::GetNumBitsForBuilder() const {
348 return 1; 351 return 1;
349 } 352 }
350 353
351 void RepeatedStringFieldGenerator:: 354 void RepeatedStringFieldGenerator::
352 GenerateInterfaceMembers(io::Printer* printer) const { 355 GenerateInterfaceMembers(io::Printer* printer) const {
353 printer->Print(variables_, 356 printer->Print(variables_,
354 "$deprecation$java.util.List<String> get$capitalized_name$List();\n" 357 "$deprecation$java.util.List<java.lang.String>\n"
358 " get$capitalized_name$List();\n"
355 "$deprecation$int get$capitalized_name$Count();\n" 359 "$deprecation$int get$capitalized_name$Count();\n"
356 "$deprecation$String get$capitalized_name$(int index);\n"); 360 "$deprecation$java.lang.String get$capitalized_name$(int index);\n");
357 } 361 }
358 362
359 363
360 void RepeatedStringFieldGenerator:: 364 void RepeatedStringFieldGenerator::
361 GenerateMembers(io::Printer* printer) const { 365 GenerateMembers(io::Printer* printer) const {
362 printer->Print(variables_, 366 printer->Print(variables_,
363 "private com.google.protobuf.LazyStringList $name$_;\n" 367 "private com.google.protobuf.LazyStringList $name$_;\n"
364 "$deprecation$public java.util.List<String>\n" 368 "$deprecation$public java.util.List<java.lang.String>\n"
365 " get$capitalized_name$List() {\n" 369 " get$capitalized_name$List() {\n"
366 " return $name$_;\n" // note: unmodifiable list 370 " return $name$_;\n" // note: unmodifiable list
367 "}\n" 371 "}\n"
368 "$deprecation$public int get$capitalized_name$Count() {\n" 372 "$deprecation$public int get$capitalized_name$Count() {\n"
369 " return $name$_.size();\n" 373 " return $name$_.size();\n"
370 "}\n" 374 "}\n"
371 "$deprecation$public String get$capitalized_name$(int index) {\n" 375 "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n"
372 " return $name$_.get(index);\n" 376 " return $name$_.get(index);\n"
373 "}\n"); 377 "}\n");
374 378
375 if (descriptor_->options().packed() && 379 if (descriptor_->options().packed() &&
376 HasGeneratedMethods(descriptor_->containing_type())) { 380 HasGeneratedMethods(descriptor_->containing_type())) {
377 printer->Print(variables_, 381 printer->Print(variables_,
378 "private int $name$MemoizedSerializedSize = -1;\n"); 382 "private int $name$MemoizedSerializedSize = -1;\n");
379 } 383 }
380 } 384 }
381 385
382 void RepeatedStringFieldGenerator:: 386 void RepeatedStringFieldGenerator::
383 GenerateBuilderMembers(io::Printer* printer) const { 387 GenerateBuilderMembers(io::Printer* printer) const {
384 // One field is the list and the bit field keeps track of whether the 388 // One field is the list and the bit field keeps track of whether the
385 // list is immutable. If it's immutable, the invariant is that it must 389 // list is immutable. If it's immutable, the invariant is that it must
386 // either an instance of Collections.emptyList() or it's an ArrayList 390 // either an instance of Collections.emptyList() or it's an ArrayList
387 // wrapped in a Collections.unmodifiableList() wrapper and nobody else has 391 // wrapped in a Collections.unmodifiableList() wrapper and nobody else has
388 // a refererence to the underlying ArrayList. This invariant allows us to 392 // a refererence to the underlying ArrayList. This invariant allows us to
389 // share instances of lists between protocol buffers avoiding expensive 393 // share instances of lists between protocol buffers avoiding expensive
390 // memory allocations. Note, immutable is a strong guarantee here -- not 394 // memory allocations. Note, immutable is a strong guarantee here -- not
391 // just that the list cannot be modified via the reference but that the 395 // just that the list cannot be modified via the reference but that the
392 // list can never be modified. 396 // list can never be modified.
393 printer->Print(variables_, 397 printer->Print(variables_,
394 "private com.google.protobuf.LazyStringList $name$_ = $empty_list$;\n"); 398 "private com.google.protobuf.LazyStringList $name$_ = $empty_list$;\n");
395 399
396 printer->Print(variables_, 400 printer->Print(variables_,
397 "private void ensure$capitalized_name$IsMutable() {\n" 401 "private void ensure$capitalized_name$IsMutable() {\n"
398 " if (!$get_mutable_bit_builder$) {\n" 402 " if (!$get_mutable_bit_builder$) {\n"
399 " $name$_ = new com.google.protobuf.LazyStringArrayList($name$_);\n" 403 " $name$_ = new com.google.protobuf.LazyStringArrayList($name$_);\n"
400 " $set_mutable_bit_builder$;\n" 404 " $set_mutable_bit_builder$;\n"
401 " }\n" 405 " }\n"
402 "}\n"); 406 "}\n");
403 407
404 // Note: We return an unmodifiable list because otherwise the caller 408 // Note: We return an unmodifiable list because otherwise the caller
405 // could hold on to the returned list and modify it after the message 409 // could hold on to the returned list and modify it after the message
406 // has been built, thus mutating the message which is supposed to be 410 // has been built, thus mutating the message which is supposed to be
407 // immutable. 411 // immutable.
408 printer->Print(variables_, 412 printer->Print(variables_,
409 "$deprecation$public java.util.List<String>\n" 413 "$deprecation$public java.util.List<java.lang.String>\n"
410 " get$capitalized_name$List() {\n" 414 " get$capitalized_name$List() {\n"
411 " return java.util.Collections.unmodifiableList($name$_);\n" 415 " return java.util.Collections.unmodifiableList($name$_);\n"
412 "}\n" 416 "}\n"
413 "$deprecation$public int get$capitalized_name$Count() {\n" 417 "$deprecation$public int get$capitalized_name$Count() {\n"
414 " return $name$_.size();\n" 418 " return $name$_.size();\n"
415 "}\n" 419 "}\n"
416 "$deprecation$public String get$capitalized_name$(int index) {\n" 420 "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n"
417 " return $name$_.get(index);\n" 421 " return $name$_.get(index);\n"
418 "}\n" 422 "}\n"
419 "$deprecation$public Builder set$capitalized_name$(\n" 423 "$deprecation$public Builder set$capitalized_name$(\n"
420 " int index, String value) {\n" 424 " int index, java.lang.String value) {\n"
421 "$null_check$" 425 "$null_check$"
422 " ensure$capitalized_name$IsMutable();\n" 426 " ensure$capitalized_name$IsMutable();\n"
423 " $name$_.set(index, value);\n" 427 " $name$_.set(index, value);\n"
424 " $on_changed$\n" 428 " $on_changed$\n"
425 " return this;\n" 429 " return this;\n"
426 "}\n" 430 "}\n"
427 "$deprecation$public Builder add$capitalized_name$(String value) {\n" 431 "$deprecation$public Builder add$capitalized_name$(\n"
432 " java.lang.String value) {\n"
428 "$null_check$" 433 "$null_check$"
429 " ensure$capitalized_name$IsMutable();\n" 434 " ensure$capitalized_name$IsMutable();\n"
430 " $name$_.add(value);\n" 435 " $name$_.add(value);\n"
431 " $on_changed$\n" 436 " $on_changed$\n"
432 " return this;\n" 437 " return this;\n"
433 "}\n" 438 "}\n"
434 "$deprecation$public Builder addAll$capitalized_name$(\n" 439 "$deprecation$public Builder addAll$capitalized_name$(\n"
435 " java.lang.Iterable<String> values) {\n" 440 " java.lang.Iterable<java.lang.String> values) {\n"
436 " ensure$capitalized_name$IsMutable();\n" 441 " ensure$capitalized_name$IsMutable();\n"
437 " super.addAll(values, $name$_);\n" 442 " super.addAll(values, $name$_);\n"
438 " $on_changed$\n" 443 " $on_changed$\n"
439 " return this;\n" 444 " return this;\n"
440 "}\n" 445 "}\n"
441 "$deprecation$public Builder clear$capitalized_name$() {\n" 446 "$deprecation$public Builder clear$capitalized_name$() {\n"
442 " $name$_ = $empty_list$;\n" 447 " $name$_ = $empty_list$;\n"
443 " $clear_mutable_bit_builder$;\n" 448 " $clear_mutable_bit_builder$;\n"
444 " $on_changed$\n" 449 " $on_changed$\n"
445 " return this;\n" 450 " return this;\n"
446 "}\n"); 451 "}\n");
447 452
448 printer->Print(variables_, 453 printer->Print(variables_,
449 "void add$capitalized_name$(com.google.protobuf.ByteString value) {\n" 454 "void add$capitalized_name$(com.google.protobuf.ByteString value) {\n"
450 " ensure$capitalized_name$IsMutable();\n" 455 " ensure$capitalized_name$IsMutable();\n"
451 " $name$_.add(value);\n" 456 " $name$_.add(value);\n"
452 " $on_changed$\n" 457 " $on_changed$\n"
453 "}\n"); 458 "}\n");
454 } 459 }
455 460
456 void RepeatedStringFieldGenerator:: 461 void RepeatedStringFieldGenerator::
457 GenerateFieldBuilderInitializationCode(io::Printer* printer) const { 462 GenerateFieldBuilderInitializationCode(io::Printer* printer) const {
458 // noop for primitives 463 // noop for primitives
459 } 464 }
460 465
461 void RepeatedStringFieldGenerator:: 466 void RepeatedStringFieldGenerator::
462 GenerateInitializationCode(io::Printer* printer) const { 467 GenerateInitializationCode(io::Printer* printer) const {
463 printer->Print(variables_, "$name$_ = $empty_list$;\n"); 468 printer->Print(variables_, "$name$_ = $empty_list$;\n");
464 } 469 }
465 470
466 void RepeatedStringFieldGenerator:: 471 void RepeatedStringFieldGenerator::
467 GenerateBuilderClearCode(io::Printer* printer) const { 472 GenerateBuilderClearCode(io::Printer* printer) const {
468 printer->Print(variables_, 473 printer->Print(variables_,
469 "$name$_ = $empty_list$;\n" 474 "$name$_ = $empty_list$;\n"
470 "$clear_mutable_bit_builder$;\n"); 475 "$clear_mutable_bit_builder$;\n");
471 } 476 }
472 477
473 void RepeatedStringFieldGenerator:: 478 void RepeatedStringFieldGenerator::
474 GenerateMergingCode(io::Printer* printer) const { 479 GenerateMergingCode(io::Printer* printer) const {
475 // The code below does two optimizations: 480 // The code below does two optimizations:
476 // 1. If the other list is empty, there's nothing to do. This ensures we 481 // 1. If the other list is empty, there's nothing to do. This ensures we
477 // don't allocate a new array if we already have an immutable one. 482 // don't allocate a new array if we already have an immutable one.
478 // 2. If the other list is non-empty and our current list is empty, we can 483 // 2. If the other list is non-empty and our current list is empty, we can
479 // reuse the other list which is guaranteed to be immutable. 484 // reuse the other list which is guaranteed to be immutable.
480 printer->Print(variables_, 485 printer->Print(variables_,
481 "if (!other.$name$_.isEmpty()) {\n" 486 "if (!other.$name$_.isEmpty()) {\n"
482 " if ($name$_.isEmpty()) {\n" 487 " if ($name$_.isEmpty()) {\n"
483 " $name$_ = other.$name$_;\n" 488 " $name$_ = other.$name$_;\n"
484 " $clear_mutable_bit_builder$;\n" 489 " $clear_mutable_bit_builder$;\n"
485 " } else {\n" 490 " } else {\n"
486 " ensure$capitalized_name$IsMutable();\n" 491 " ensure$capitalized_name$IsMutable();\n"
487 " $name$_.addAll(other.$name$_);\n" 492 " $name$_.addAll(other.$name$_);\n"
488 " }\n" 493 " }\n"
489 " $on_changed$\n" 494 " $on_changed$\n"
490 "}\n"); 495 "}\n");
491 } 496 }
492 497
493 void RepeatedStringFieldGenerator:: 498 void RepeatedStringFieldGenerator::
494 GenerateBuildingCode(io::Printer* printer) const { 499 GenerateBuildingCode(io::Printer* printer) const {
495 // The code below ensures that the result has an immutable list. If our 500 // The code below ensures that the result has an immutable list. If our
496 // list is immutable, we can just reuse it. If not, we make it immutable. 501 // list is immutable, we can just reuse it. If not, we make it immutable.
497 502
498 printer->Print(variables_, 503 printer->Print(variables_,
499 "if ($get_mutable_bit_builder$) {\n" 504 "if ($get_mutable_bit_builder$) {\n"
500 " $name$_ = new com.google.protobuf.UnmodifiableLazyStringList(\n" 505 " $name$_ = new com.google.protobuf.UnmodifiableLazyStringList(\n"
501 " $name$_);\n" 506 " $name$_);\n"
502 " $clear_mutable_bit_builder$;\n" 507 " $clear_mutable_bit_builder$;\n"
503 "}\n" 508 "}\n"
504 "result.$name$_ = $name$_;\n"); 509 "result.$name$_ = $name$_;\n");
505 } 510 }
506 511
507 void RepeatedStringFieldGenerator:: 512 void RepeatedStringFieldGenerator::
508 GenerateParsingCode(io::Printer* printer) const { 513 GenerateParsingCode(io::Printer* printer) const {
509 printer->Print(variables_, 514 printer->Print(variables_,
510 "ensure$capitalized_name$IsMutable();\n" 515 "ensure$capitalized_name$IsMutable();\n"
511 "$name$_.add(input.readBytes());\n"); 516 "$name$_.add(input.readBytes());\n");
512 } 517 }
513 518
514 void RepeatedStringFieldGenerator:: 519 void RepeatedStringFieldGenerator::
515 GenerateParsingCodeFromPacked(io::Printer* printer) const { 520 GenerateParsingCodeFromPacked(io::Printer* printer) const {
516 printer->Print(variables_, 521 printer->Print(variables_,
517 "int length = input.readRawVarint32();\n" 522 "int length = input.readRawVarint32();\n"
518 "int limit = input.pushLimit(length);\n" 523 "int limit = input.pushLimit(length);\n"
519 "while (input.getBytesUntilLimit() > 0) {\n" 524 "while (input.getBytesUntilLimit() > 0) {\n"
520 " add$capitalized_name$(input.read$capitalized_type$());\n" 525 " add$capitalized_name$(input.read$capitalized_type$());\n"
521 "}\n" 526 "}\n"
522 "input.popLimit(limit);\n"); 527 "input.popLimit(limit);\n");
523 } 528 }
524 529
525 void RepeatedStringFieldGenerator:: 530 void RepeatedStringFieldGenerator::
526 GenerateSerializationCode(io::Printer* printer) const { 531 GenerateSerializationCode(io::Printer* printer) const {
527 if (descriptor_->options().packed()) { 532 if (descriptor_->options().packed()) {
528 printer->Print(variables_, 533 printer->Print(variables_,
529 "if (get$capitalized_name$List().size() > 0) {\n" 534 "if (get$capitalized_name$List().size() > 0) {\n"
530 " output.writeRawVarint32($tag$);\n" 535 " output.writeRawVarint32($tag$);\n"
531 " output.writeRawVarint32($name$MemoizedSerializedSize);\n" 536 " output.writeRawVarint32($name$MemoizedSerializedSize);\n"
532 "}\n" 537 "}\n"
533 "for (int i = 0; i < $name$_.size(); i++) {\n" 538 "for (int i = 0; i < $name$_.size(); i++) {\n"
534 " output.write$capitalized_type$NoTag($name$_.get(i));\n" 539 " output.write$capitalized_type$NoTag($name$_.get(i));\n"
535 "}\n"); 540 "}\n");
536 } else { 541 } else {
537 printer->Print(variables_, 542 printer->Print(variables_,
538 "for (int i = 0; i < $name$_.size(); i++) {\n" 543 "for (int i = 0; i < $name$_.size(); i++) {\n"
539 " output.writeBytes($number$, $name$_.getByteString(i));\n" 544 " output.writeBytes($number$, $name$_.getByteString(i));\n"
540 "}\n"); 545 "}\n");
541 } 546 }
542 } 547 }
543 548
544 void RepeatedStringFieldGenerator:: 549 void RepeatedStringFieldGenerator::
545 GenerateSerializedSizeCode(io::Printer* printer) const { 550 GenerateSerializedSizeCode(io::Printer* printer) const {
546 printer->Print(variables_, 551 printer->Print(variables_,
547 "{\n" 552 "{\n"
548 " int dataSize = 0;\n"); 553 " int dataSize = 0;\n");
549 printer->Indent(); 554 printer->Indent();
550 555
551 printer->Print(variables_, 556 printer->Print(variables_,
552 "for (int i = 0; i < $name$_.size(); i++) {\n" 557 "for (int i = 0; i < $name$_.size(); i++) {\n"
553 " dataSize += com.google.protobuf.CodedOutputStream\n" 558 " dataSize += com.google.protobuf.CodedOutputStream\n"
554 " .computeBytesSizeNoTag($name$_.getByteString(i));\n" 559 " .computeBytesSizeNoTag($name$_.getByteString(i));\n"
555 "}\n"); 560 "}\n");
556 561
557 printer->Print( 562 printer->Print(
558 "size += dataSize;\n"); 563 "size += dataSize;\n");
559 564
560 if (descriptor_->options().packed()) { 565 if (descriptor_->options().packed()) {
561 printer->Print(variables_, 566 printer->Print(variables_,
562 "if (!get$capitalized_name$List().isEmpty()) {\n" 567 "if (!get$capitalized_name$List().isEmpty()) {\n"
563 " size += $tag_size$;\n" 568 " size += $tag_size$;\n"
564 " size += com.google.protobuf.CodedOutputStream\n" 569 " size += com.google.protobuf.CodedOutputStream\n"
565 " .computeInt32SizeNoTag(dataSize);\n" 570 " .computeInt32SizeNoTag(dataSize);\n"
566 "}\n"); 571 "}\n");
567 } else { 572 } else {
568 printer->Print(variables_, 573 printer->Print(variables_,
569 "size += $tag_size$ * get$capitalized_name$List().size();\n"); 574 "size += $tag_size$ * get$capitalized_name$List().size();\n");
570 } 575 }
571 576
572 // cache the data size for packed fields. 577 // cache the data size for packed fields.
573 if (descriptor_->options().packed()) { 578 if (descriptor_->options().packed()) {
574 printer->Print(variables_, 579 printer->Print(variables_,
575 "$name$MemoizedSerializedSize = dataSize;\n"); 580 "$name$MemoizedSerializedSize = dataSize;\n");
576 } 581 }
577 582
578 printer->Outdent(); 583 printer->Outdent();
579 printer->Print("}\n"); 584 printer->Print("}\n");
580 } 585 }
581 586
582 void RepeatedStringFieldGenerator:: 587 void RepeatedStringFieldGenerator::
583 GenerateEqualsCode(io::Printer* printer) const { 588 GenerateEqualsCode(io::Printer* printer) const {
584 printer->Print(variables_, 589 printer->Print(variables_,
585 "result = result && get$capitalized_name$List()\n" 590 "result = result && get$capitalized_name$List()\n"
586 " .equals(other.get$capitalized_name$List());\n"); 591 " .equals(other.get$capitalized_name$List());\n");
587 } 592 }
588 593
589 void RepeatedStringFieldGenerator:: 594 void RepeatedStringFieldGenerator::
590 GenerateHashCode(io::Printer* printer) const { 595 GenerateHashCode(io::Printer* printer) const {
591 printer->Print(variables_, 596 printer->Print(variables_,
592 "if (get$capitalized_name$Count() > 0) {\n" 597 "if (get$capitalized_name$Count() > 0) {\n"
593 " hash = (37 * hash) + $constant_name$;\n" 598 " hash = (37 * hash) + $constant_name$;\n"
594 " hash = (53 * hash) + get$capitalized_name$List().hashCode();\n" 599 " hash = (53 * hash) + get$capitalized_name$List().hashCode();\n"
595 "}\n"); 600 "}\n");
596 } 601 }
597 602
598 string RepeatedStringFieldGenerator::GetBoxedType() const { 603 string RepeatedStringFieldGenerator::GetBoxedType() const {
599 return "String"; 604 return "String";
600 } 605 }
601 606
602 } // namespace java 607 } // namespace java
603 } // namespace compiler 608 } // namespace compiler
604 } // namespace protobuf 609 } // namespace protobuf
605 } // namespace google 610 } // namespace google
Powered by Google Project Hosting