PageRenderTime 121ms CodeModel.GetById 67ms app.highlight 48ms RepoModel.GetById 2ms app.codeStats 0ms

/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/compiler/java/java_string_field.cc

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