Line data Source code
1 : // Protocol Buffers - Google's data interchange format
2 : // Copyright 2008 Google Inc. All rights reserved.
3 : // https://developers.google.com/protocol-buffers/
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: niwasaki@google.com (Naoki Iwasaki)
32 : // Based on original Protocol Buffers design by
33 : // Sanjay Ghemawat, Jeff Dean, and others.
34 :
35 : #include <google/protobuf/compiler/java/java_context.h>
36 : #include <google/protobuf/compiler/java/java_lazy_message_field_lite.h>
37 : #include <google/protobuf/compiler/java/java_doc_comment.h>
38 : #include <google/protobuf/compiler/java/java_helpers.h>
39 : #include <google/protobuf/io/printer.h>
40 :
41 : namespace google {
42 : namespace protobuf {
43 : namespace compiler {
44 : namespace java {
45 :
46 0 : ImmutableLazyMessageFieldLiteGenerator::
47 : ImmutableLazyMessageFieldLiteGenerator(
48 : const FieldDescriptor* descriptor,
49 : int messageBitIndex,
50 : int builderBitIndex,
51 : Context* context)
52 : : ImmutableMessageFieldLiteGenerator(
53 0 : descriptor, messageBitIndex, builderBitIndex, context) {
54 0 : }
55 :
56 0 : ImmutableLazyMessageFieldLiteGenerator::
57 0 : ~ImmutableLazyMessageFieldLiteGenerator() {}
58 :
59 0 : void ImmutableLazyMessageFieldLiteGenerator::
60 : GenerateMembers(io::Printer* printer) const {
61 : printer->Print(variables_,
62 : "private com.google.protobuf.LazyFieldLite $name$_ =\n"
63 0 : " new com.google.protobuf.LazyFieldLite();\n");
64 :
65 0 : PrintExtraFieldInfo(variables_, printer);
66 0 : WriteFieldDocComment(printer, descriptor_);
67 : printer->Print(variables_,
68 : "$deprecation$public boolean has$capitalized_name$() {\n"
69 : " return $get_has_field_bit_message$;\n"
70 0 : "}\n");
71 :
72 0 : WriteFieldDocComment(printer, descriptor_);
73 : printer->Print(variables_,
74 : "$deprecation$public $type$ get$capitalized_name$() {\n"
75 : " return ($type$) $name$_.getValue($type$.getDefaultInstance());\n"
76 0 : "}\n");
77 :
78 : // Field.Builder setField(Field value)
79 0 : WriteFieldDocComment(printer, descriptor_);
80 : printer->Print(variables_,
81 : "private void set$capitalized_name$($type$ value) {\n"
82 : " if (value == null) {\n"
83 : " throw new NullPointerException();\n"
84 : " }\n"
85 : " $name$_.setValue(value);\n"
86 : " $set_has_field_bit_message$;\n"
87 0 : "}\n");
88 :
89 : // Field.Builder setField(Field.Builder builderForValue)
90 0 : WriteFieldDocComment(printer, descriptor_);
91 : printer->Print(variables_,
92 : "private void set$capitalized_name$(\n"
93 : " $type$.Builder builderForValue) {\n"
94 : " $name$_.setValue(builderForValue.build());\n"
95 : " $set_has_field_bit_message$;\n"
96 0 : "}\n");
97 :
98 : // Field.Builder mergeField(Field value)
99 0 : WriteFieldDocComment(printer, descriptor_);
100 : printer->Print(variables_,
101 : "private void merge$capitalized_name$($type$ value) {\n"
102 : " if ($get_has_field_bit_message$ &&\n"
103 : " !$name$_.containsDefaultInstance()) {\n"
104 : " $name$_.setValue(\n"
105 : " $type$.newBuilder(\n"
106 : " get$capitalized_name$()).mergeFrom(value).buildPartial());\n"
107 : " } else {\n"
108 : " $name$_.setValue(value);\n"
109 : " }\n"
110 : " $set_has_field_bit_message$;\n"
111 0 : "}\n");
112 :
113 : // Field.Builder clearField()
114 0 : WriteFieldDocComment(printer, descriptor_);
115 : printer->Print(variables_,
116 : "private void clear$capitalized_name$() {\n"
117 : " $name$_.clear();\n"
118 : " $clear_has_field_bit_message$;\n"
119 0 : "}\n");
120 0 : }
121 :
122 0 : void ImmutableLazyMessageFieldLiteGenerator::
123 : GenerateBuilderMembers(io::Printer* printer) const {
124 : // The comments above the methods below are based on a hypothetical
125 : // field of type "Field" called "Field".
126 :
127 : // boolean hasField()
128 0 : WriteFieldDocComment(printer, descriptor_);
129 : printer->Print(variables_,
130 : "$deprecation$public boolean has$capitalized_name$() {\n"
131 : " return instance.has$capitalized_name$();\n"
132 0 : "}\n");
133 :
134 0 : WriteFieldDocComment(printer, descriptor_);
135 : printer->Print(variables_,
136 : "$deprecation$public $type$ get$capitalized_name$() {\n"
137 : " return instance.get$capitalized_name$();\n"
138 0 : "}\n");
139 :
140 : // Field.Builder setField(Field value)
141 0 : WriteFieldDocComment(printer, descriptor_);
142 : printer->Print(variables_,
143 : "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
144 : " copyOnWrite();\n"
145 : " instance.set$capitalized_name$(value);\n"
146 : " return this;\n"
147 0 : "}\n");
148 :
149 : // Field.Builder setField(Field.Builder builderForValue)
150 0 : WriteFieldDocComment(printer, descriptor_);
151 : printer->Print(variables_,
152 : "$deprecation$public Builder set$capitalized_name$(\n"
153 : " $type$.Builder builderForValue) {\n"
154 : " copyOnWrite();\n"
155 : " instance.set$capitalized_name$(builderForValue);\n"
156 : " return this;\n"
157 0 : "}\n");
158 :
159 : // Field.Builder mergeField(Field value)
160 0 : WriteFieldDocComment(printer, descriptor_);
161 : printer->Print(variables_,
162 : "$deprecation$public Builder merge$capitalized_name$($type$ value) {\n"
163 : " copyOnWrite();\n"
164 : " instance.merge$capitalized_name$(value);\n"
165 : " return this;\n"
166 0 : "}\n");
167 :
168 : // Field.Builder clearField()
169 0 : WriteFieldDocComment(printer, descriptor_);
170 : printer->Print(variables_,
171 : "$deprecation$public Builder clear$capitalized_name$() {\n"
172 : " copyOnWrite();\n"
173 : " instance.clear$capitalized_name$();\n"
174 : " return this;\n"
175 0 : "}\n");
176 0 : }
177 :
178 :
179 0 : void ImmutableLazyMessageFieldLiteGenerator::
180 : GenerateInitializationCode(io::Printer* printer) const {
181 0 : printer->Print(variables_, "$name$_.clear();\n");
182 0 : }
183 :
184 0 : void ImmutableLazyMessageFieldLiteGenerator::
185 : GenerateMergingCode(io::Printer* printer) const {
186 : printer->Print(variables_,
187 : "if (other.has$capitalized_name$()) {\n"
188 : " $name$_.merge(other.$name$_);\n"
189 : " $set_has_field_bit_message$;\n"
190 0 : "}\n");
191 0 : }
192 :
193 0 : void ImmutableLazyMessageFieldLiteGenerator::
194 : GenerateParsingCode(io::Printer* printer) const {
195 : printer->Print(variables_,
196 0 : "$name$_.setByteString(input.readBytes(), extensionRegistry);\n");
197 : printer->Print(variables_,
198 0 : "$set_has_field_bit_message$;\n");
199 0 : }
200 :
201 0 : void ImmutableLazyMessageFieldLiteGenerator::
202 : GenerateSerializationCode(io::Printer* printer) const {
203 : // Do not de-serialize lazy fields.
204 : printer->Print(variables_,
205 : "if ($get_has_field_bit_message$) {\n"
206 : " output.writeBytes($number$, $name$_.toByteString());\n"
207 0 : "}\n");
208 0 : }
209 :
210 0 : void ImmutableLazyMessageFieldLiteGenerator::
211 : GenerateSerializedSizeCode(io::Printer* printer) const {
212 : printer->Print(variables_,
213 : "if ($get_has_field_bit_message$) {\n"
214 : " size += com.google.protobuf.CodedOutputStream\n"
215 : " .computeLazyFieldSize($number$, $name$_);\n"
216 0 : "}\n");
217 0 : }
218 :
219 : // ===================================================================
220 :
221 0 : ImmutableLazyMessageOneofFieldLiteGenerator::
222 0 : ImmutableLazyMessageOneofFieldLiteGenerator(const FieldDescriptor* descriptor,
223 : int messageBitIndex,
224 : int builderBitIndex,
225 : Context* context)
226 : : ImmutableLazyMessageFieldLiteGenerator(
227 0 : descriptor, messageBitIndex, builderBitIndex, context) {
228 : const OneofGeneratorInfo* info =
229 0 : context->GetOneofGeneratorInfo(descriptor->containing_oneof());
230 0 : SetCommonOneofVariables(descriptor, info, &variables_);
231 0 : variables_["lazy_type"] = "com.google.protobuf.LazyFieldLite";
232 0 : }
233 :
234 0 : ImmutableLazyMessageOneofFieldLiteGenerator::
235 0 : ~ImmutableLazyMessageOneofFieldLiteGenerator() {}
236 :
237 0 : void ImmutableLazyMessageOneofFieldLiteGenerator::
238 : GenerateMembers(io::Printer* printer) const {
239 0 : PrintExtraFieldInfo(variables_, printer);
240 0 : WriteFieldDocComment(printer, descriptor_);
241 :
242 : printer->Print(variables_,
243 : "$deprecation$public boolean has$capitalized_name$() {\n"
244 : " return $has_oneof_case_message$;\n"
245 0 : "}\n");
246 0 : WriteFieldDocComment(printer, descriptor_);
247 :
248 : printer->Print(variables_,
249 : "$deprecation$public $type$ get$capitalized_name$() {\n"
250 : " if ($has_oneof_case_message$) {\n"
251 : " return ($type$) (($lazy_type$) $oneof_name$_).getValue(\n"
252 : " $type$.getDefaultInstance());\n"
253 : " }\n"
254 : " return $type$.getDefaultInstance();\n"
255 0 : "}\n");
256 :
257 : // Field.Builder setField(Field value)
258 0 : WriteFieldDocComment(printer, descriptor_);
259 : printer->Print(variables_,
260 : "private void set$capitalized_name$($type$ value) {\n"
261 : " if (value == null) {\n"
262 : " throw new NullPointerException();\n"
263 : " }\n"
264 : " if (!($has_oneof_case_message$)) {\n"
265 : " $oneof_name$_ = new $lazy_type$();\n"
266 : " $set_oneof_case_message$;\n"
267 : " }\n"
268 : " (($lazy_type$) $oneof_name$_).setValue(value);\n"
269 0 : "}\n");
270 :
271 : // Field.Builder setField(Field.Builder builderForValue)
272 0 : WriteFieldDocComment(printer, descriptor_);
273 : printer->Print(variables_,
274 : "private void set$capitalized_name$(\n"
275 : " $type$.Builder builderForValue) {\n"
276 : " if (!($has_oneof_case_message$)) {\n"
277 : " $oneof_name$_ = new $lazy_type$();\n"
278 : " $set_oneof_case_message$;\n"
279 : " }\n"
280 : " (($lazy_type$) $oneof_name$_).setValue(builderForValue.build());\n"
281 0 : "}\n");
282 :
283 : // Field.Builder mergeField(Field value)
284 0 : WriteFieldDocComment(printer, descriptor_);
285 : printer->Print(variables_,
286 : "private void merge$capitalized_name$($type$ value) {\n"
287 : " if ($has_oneof_case_message$ &&\n"
288 : " !(($lazy_type$) $oneof_name$_).containsDefaultInstance()) {\n"
289 : " (($lazy_type$) $oneof_name$_).setValue(\n"
290 : " $type$.newBuilder(\n"
291 : " get$capitalized_name$()).mergeFrom(value).buildPartial());\n"
292 : " } else {\n"
293 : " if (!($has_oneof_case_message$)) {\n"
294 : " $oneof_name$_ = new $lazy_type$();\n"
295 : " $set_oneof_case_message$;\n"
296 : " }\n"
297 : " (($lazy_type$) $oneof_name$_).setValue(value);\n"
298 : " }\n"
299 0 : "}\n");
300 :
301 : // Field.Builder clearField()
302 0 : WriteFieldDocComment(printer, descriptor_);
303 : printer->Print(variables_,
304 : "private void clear$capitalized_name$() {\n"
305 : " if ($has_oneof_case_message$) {\n"
306 : " $clear_oneof_case_message$;\n"
307 : " $oneof_name$_ = null;\n"
308 : " }\n"
309 0 : "}\n");
310 0 : }
311 :
312 0 : void ImmutableLazyMessageOneofFieldLiteGenerator::
313 : GenerateBuilderMembers(io::Printer* printer) const {
314 : // boolean hasField()
315 0 : WriteFieldDocComment(printer, descriptor_);
316 : printer->Print(variables_,
317 : "$deprecation$public boolean has$capitalized_name$() {\n"
318 : " return instance.has$capitalized_name$();\n"
319 0 : "}\n");
320 :
321 : printer->Print(variables_,
322 : "$deprecation$public $type$ get$capitalized_name$() {\n"
323 : " return instance.get$capitalized_name$();\n"
324 0 : "}\n");
325 :
326 : // Field.Builder setField(Field value)
327 0 : WriteFieldDocComment(printer, descriptor_);
328 : printer->Print(variables_,
329 : "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
330 : " copyOnWrite();\n"
331 : " instance.set$capitalized_name$(value);\n"
332 : " return this;\n"
333 0 : "}\n");
334 :
335 : // Field.Builder setField(Field.Builder builderForValue)
336 0 : WriteFieldDocComment(printer, descriptor_);
337 : printer->Print(variables_,
338 : "$deprecation$public Builder set$capitalized_name$(\n"
339 : " $type$.Builder builderForValue) {\n"
340 : " copyOnWrite();\n"
341 : " instance.set$capitalized_name$(builderForValue);\n"
342 : " return this;\n"
343 0 : "}\n");
344 :
345 : // Field.Builder mergeField(Field value)
346 0 : WriteFieldDocComment(printer, descriptor_);
347 : printer->Print(variables_,
348 : "$deprecation$public Builder merge$capitalized_name$($type$ value) {\n"
349 : " copyOnWrite();\n"
350 : " instance.merge$capitalized_name$(value);\n"
351 : " return this;\n"
352 0 : "}\n");
353 :
354 : // Field.Builder clearField()
355 0 : WriteFieldDocComment(printer, descriptor_);
356 : printer->Print(variables_,
357 : "$deprecation$public Builder clear$capitalized_name$() {\n"
358 : " copyOnWrite();\n"
359 : " instance.clear$capitalized_name$();\n"
360 : " return this;\n"
361 0 : "}\n");
362 0 : }
363 :
364 0 : void ImmutableLazyMessageOneofFieldLiteGenerator::
365 : GenerateMergingCode(io::Printer* printer) const {
366 : printer->Print(variables_,
367 : "if (!($has_oneof_case_message$)) {\n"
368 : " $oneof_name$_ = new $lazy_type$();\n"
369 : "}\n"
370 : "(($lazy_type$) $oneof_name$_).merge(\n"
371 : " ($lazy_type$) other.$oneof_name$_);\n"
372 0 : "$set_oneof_case_message$;\n");
373 0 : }
374 :
375 0 : void ImmutableLazyMessageOneofFieldLiteGenerator::
376 : GenerateParsingCode(io::Printer* printer) const {
377 : printer->Print(variables_,
378 : "if (!($has_oneof_case_message$)) {\n"
379 : " $oneof_name$_ = new $lazy_type$();\n"
380 : "}\n"
381 : "(($lazy_type$) $oneof_name$_).setByteString(\n"
382 : " input.readBytes(), extensionRegistry);\n"
383 0 : "$set_oneof_case_message$;\n");
384 0 : }
385 :
386 0 : void ImmutableLazyMessageOneofFieldLiteGenerator::
387 : GenerateSerializationCode(io::Printer* printer) const {
388 : // Do not de-serialize lazy fields.
389 : printer->Print(variables_,
390 : "if ($has_oneof_case_message$) {\n"
391 : " output.writeBytes(\n"
392 : " $number$, (($lazy_type$) $oneof_name$_).toByteString());\n"
393 0 : "}\n");
394 0 : }
395 :
396 0 : void ImmutableLazyMessageOneofFieldLiteGenerator::
397 : GenerateSerializedSizeCode(io::Printer* printer) const {
398 : printer->Print(variables_,
399 : "if ($has_oneof_case_message$) {\n"
400 : " size += com.google.protobuf.CodedOutputStream\n"
401 : " .computeLazyFieldSize($number$, ($lazy_type$) $oneof_name$_);\n"
402 0 : "}\n");
403 0 : }
404 :
405 : // ===================================================================
406 :
407 0 : RepeatedImmutableLazyMessageFieldLiteGenerator::
408 : RepeatedImmutableLazyMessageFieldLiteGenerator(
409 : const FieldDescriptor* descriptor,
410 : int messageBitIndex,
411 : int builderBitIndex,
412 : Context* context)
413 : : RepeatedImmutableMessageFieldLiteGenerator(
414 0 : descriptor, messageBitIndex, builderBitIndex, context) {
415 0 : }
416 :
417 :
418 0 : RepeatedImmutableLazyMessageFieldLiteGenerator::
419 0 : ~RepeatedImmutableLazyMessageFieldLiteGenerator() {}
420 :
421 0 : void RepeatedImmutableLazyMessageFieldLiteGenerator::
422 : GenerateMembers(io::Printer* printer) const {
423 : printer->Print(variables_,
424 : "private com.google.protobuf.Internal.ProtobufList<\n"
425 0 : " com.google.protobuf.LazyFieldLite> $name$_;\n");
426 0 : PrintExtraFieldInfo(variables_, printer);
427 0 : WriteFieldDocComment(printer, descriptor_);
428 : printer->Print(variables_,
429 : "$deprecation$public java.util.List<$type$>\n"
430 : " get$capitalized_name$List() {\n"
431 : " java.util.List<$type$> list =\n"
432 : " new java.util.ArrayList<$type$>($name$_.size());\n"
433 : " for (com.google.protobuf.LazyFieldLite lf : $name$_) {\n"
434 : " list.add(($type$) lf.getValue($type$.getDefaultInstance()));\n"
435 : " }\n"
436 : // TODO(dweis): Make this list immutable?
437 : " return list;\n"
438 0 : "}\n");
439 0 : WriteFieldDocComment(printer, descriptor_);
440 : printer->Print(variables_,
441 : "$deprecation$public java.util.List<? extends $type$OrBuilder>\n"
442 : " get$capitalized_name$OrBuilderList() {\n"
443 : " return get$capitalized_name$List();\n"
444 0 : "}\n");
445 0 : WriteFieldDocComment(printer, descriptor_);
446 : printer->Print(variables_,
447 : "$deprecation$public int get$capitalized_name$Count() {\n"
448 : " return $name$_.size();\n"
449 0 : "}\n");
450 0 : WriteFieldDocComment(printer, descriptor_);
451 : printer->Print(variables_,
452 : "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
453 : " return ($type$)\n"
454 : " $name$_.get(index).getValue($type$.getDefaultInstance());\n"
455 0 : "}\n");
456 0 : WriteFieldDocComment(printer, descriptor_);
457 : printer->Print(variables_,
458 : "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder(\n"
459 : " int index) {\n"
460 : " return ($type$OrBuilder)\n"
461 : " $name$_.get(index).getValue($type$.getDefaultInstance());\n"
462 0 : "}\n");
463 :
464 : printer->Print(variables_,
465 : "private void ensure$capitalized_name$IsMutable() {\n"
466 : " if (!$is_mutable$) {\n"
467 : " $name$_ = newProtobufList($name$_);\n"
468 : " }\n"
469 : "}\n"
470 0 : "\n");
471 :
472 : // Builder setRepeatedField(int index, Field value)
473 0 : WriteFieldDocComment(printer, descriptor_);
474 : printer->Print(variables_,
475 : "private void set$capitalized_name$(\n"
476 : " int index, $type$ value) {\n"
477 : " if (value == null) {\n"
478 : " throw new NullPointerException();\n"
479 : " }\n"
480 : " ensure$capitalized_name$IsMutable();\n"
481 : " $name$_.set(\n"
482 : " index, com.google.protobuf.LazyFieldLite.fromValue(value));\n"
483 0 : "}\n");
484 :
485 : // Builder setRepeatedField(int index, Field.Builder builderForValue)
486 0 : WriteFieldDocComment(printer, descriptor_);
487 : printer->Print(variables_,
488 : "private void set$capitalized_name$(\n"
489 : " int index, $type$.Builder builderForValue) {\n"
490 : " ensure$capitalized_name$IsMutable();\n"
491 : " $name$_.set(index, com.google.protobuf.LazyFieldLite.fromValue(\n"
492 : " builderForValue.build()));\n"
493 0 : "}\n");
494 :
495 : // Builder addRepeatedField(Field value)
496 0 : WriteFieldDocComment(printer, descriptor_);
497 : printer->Print(variables_,
498 : "private void add$capitalized_name$($type$ value) {\n"
499 : " if (value == null) {\n"
500 : " throw new NullPointerException();\n"
501 : " }\n"
502 : " ensure$capitalized_name$IsMutable();\n"
503 : " $name$_.add(com.google.protobuf.LazyFieldLite.fromValue(value));\n"
504 0 : "}\n");
505 :
506 : // Builder addRepeatedField(int index, Field value)
507 0 : WriteFieldDocComment(printer, descriptor_);
508 : printer->Print(variables_,
509 : "private void add$capitalized_name$(\n"
510 : " int index, $type$ value) {\n"
511 : " if (value == null) {\n"
512 : " throw new NullPointerException();\n"
513 : " }\n"
514 : " ensure$capitalized_name$IsMutable();\n"
515 : " $name$_.add(\n"
516 : " index, com.google.protobuf.LazyFieldLite.fromValue(value));\n"
517 0 : "}\n");
518 :
519 : // Builder addRepeatedField(Field.Builder builderForValue)
520 0 : WriteFieldDocComment(printer, descriptor_);
521 : printer->Print(variables_,
522 : "private void add$capitalized_name$(\n"
523 : " $type$.Builder builderForValue) {\n"
524 : " ensure$capitalized_name$IsMutable();\n"
525 : " $name$_.add(com.google.protobuf.LazyFieldLite.fromValue(\n"
526 : " builderForValue.build()));\n"
527 0 : "}\n");
528 :
529 : // Builder addRepeatedField(int index, Field.Builder builderForValue)
530 0 : WriteFieldDocComment(printer, descriptor_);
531 : printer->Print(variables_,
532 : "private void add$capitalized_name$(\n"
533 : " int index, $type$.Builder builderForValue) {\n"
534 : " ensure$capitalized_name$IsMutable();\n"
535 : " $name$_.add(index, com.google.protobuf.LazyFieldLite.fromValue(\n"
536 : " builderForValue.build()));\n"
537 0 : "}\n");
538 :
539 : // Builder addAllRepeatedField(Iterable<Field> values)
540 0 : WriteFieldDocComment(printer, descriptor_);
541 : printer->Print(variables_,
542 : "private void addAll$capitalized_name$(\n"
543 : " java.lang.Iterable<? extends $type$> values) {\n"
544 : " ensure$capitalized_name$IsMutable();\n"
545 : " for (com.google.protobuf.MessageLite v : values) {\n"
546 : " $name$_.add(com.google.protobuf.LazyFieldLite.fromValue(v));\n"
547 : " }\n"
548 0 : "}\n");
549 :
550 : // Builder clearAllRepeatedField()
551 0 : WriteFieldDocComment(printer, descriptor_);
552 : printer->Print(variables_,
553 : "private void clear$capitalized_name$() {\n"
554 : " $name$_ = emptyProtobufList();\n"
555 0 : "}\n");
556 :
557 : // Builder removeRepeatedField(int index)
558 0 : WriteFieldDocComment(printer, descriptor_);
559 : printer->Print(variables_,
560 : "private void remove$capitalized_name$(int index) {\n"
561 : " ensure$capitalized_name$IsMutable();\n"
562 : " $name$_.remove(index);\n"
563 0 : "}\n");
564 0 : }
565 :
566 0 : void RepeatedImmutableLazyMessageFieldLiteGenerator::
567 : GenerateBuilderMembers(io::Printer* printer) const {
568 : // List<Field> getRepeatedFieldList()
569 0 : WriteFieldDocComment(printer, descriptor_);
570 : printer->Print(variables_,
571 : "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
572 : " return java.util.Collections.unmodifiableList(\n"
573 : " instance.get$capitalized_name$List());\n"
574 0 : "}\n");
575 :
576 : // int getRepeatedFieldCount()
577 0 : WriteFieldDocComment(printer, descriptor_);
578 : printer->Print(variables_,
579 : "$deprecation$public int get$capitalized_name$Count() {\n"
580 : " return instance.get$capitalized_name$Count();\n"
581 0 : "}\n");
582 :
583 : // Field getRepeatedField(int index)
584 0 : WriteFieldDocComment(printer, descriptor_);
585 : printer->Print(variables_,
586 : "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
587 : " return instance.get$capitalized_name$(index);\n"
588 0 : "}\n");
589 :
590 : // Builder setRepeatedField(int index, Field value)
591 0 : WriteFieldDocComment(printer, descriptor_);
592 : printer->Print(variables_,
593 : "$deprecation$public Builder set$capitalized_name$(\n"
594 : " int index, $type$ value) {\n"
595 : " copyOnWrite();\n"
596 : " instance.set$capitalized_name$(index, value);\n"
597 : " return this;\n"
598 0 : "}\n");
599 :
600 : // Builder setRepeatedField(int index, Field.Builder builderForValue)
601 0 : WriteFieldDocComment(printer, descriptor_);
602 : printer->Print(variables_,
603 : "$deprecation$public Builder set$capitalized_name$(\n"
604 : " int index, $type$.Builder builderForValue) {\n"
605 : " copyOnWrite();\n"
606 : " instance.set$capitalized_name$(index, builderForValue);\n"
607 : " return this;\n"
608 0 : "}\n");
609 :
610 : // Builder addRepeatedField(Field value)
611 0 : WriteFieldDocComment(printer, descriptor_);
612 : printer->Print(variables_,
613 : "$deprecation$public Builder add$capitalized_name$($type$ value) {\n"
614 : " copyOnWrite();\n"
615 : " instance.add$capitalized_name$(value);\n"
616 : " return this;\n"
617 0 : "}\n");
618 :
619 : // Builder addRepeatedField(int index, Field value)
620 0 : WriteFieldDocComment(printer, descriptor_);
621 : printer->Print(variables_,
622 : "$deprecation$public Builder add$capitalized_name$(\n"
623 : " int index, $type$ value) {\n"
624 : " copyOnWrite();\n"
625 : " instance.add$capitalized_name$(index, value);\n"
626 : " return this;\n"
627 0 : "}\n");
628 :
629 : // Builder addRepeatedField(Field.Builder builderForValue)
630 0 : WriteFieldDocComment(printer, descriptor_);
631 : printer->Print(variables_,
632 : "$deprecation$public Builder add$capitalized_name$(\n"
633 : " $type$.Builder builderForValue) {\n"
634 : " copyOnWrite();\n"
635 : " instance.add$capitalized_name$(builderForValue);\n"
636 : " return this;\n"
637 0 : "}\n");
638 :
639 : // Builder addRepeatedField(int index, Field.Builder builderForValue)
640 0 : WriteFieldDocComment(printer, descriptor_);
641 : printer->Print(variables_,
642 : "$deprecation$public Builder add$capitalized_name$(\n"
643 : " int index, $type$.Builder builderForValue) {\n"
644 : " copyOnWrite();\n"
645 : " instance.add$capitalized_name$(index, builderForValue);\n"
646 : " return this;\n"
647 0 : "}\n");
648 :
649 : // Builder addAllRepeatedField(Iterable<Field> values)
650 0 : WriteFieldDocComment(printer, descriptor_);
651 : printer->Print(variables_,
652 : "$deprecation$public Builder addAll$capitalized_name$(\n"
653 : " java.lang.Iterable<? extends $type$> values) {\n"
654 : " copyOnWrite();\n"
655 : " instance.addAll$capitalized_name$(values);\n"
656 : " return this;\n"
657 0 : "}\n");
658 :
659 : // Builder clearAllRepeatedField()
660 0 : WriteFieldDocComment(printer, descriptor_);
661 : printer->Print(variables_,
662 : "$deprecation$public Builder clear$capitalized_name$() {\n"
663 : " copyOnWrite();\n"
664 : " instance.clear$capitalized_name$();\n"
665 : " return this;\n"
666 0 : "}\n");
667 :
668 : // Builder removeRepeatedField(int index)
669 0 : WriteFieldDocComment(printer, descriptor_);
670 : printer->Print(variables_,
671 : "$deprecation$public Builder remove$capitalized_name$(int index) {\n"
672 : " copyOnWrite();\n"
673 : " instance.remove$capitalized_name$(index);\n"
674 : " return this;\n"
675 0 : "}\n");
676 0 : }
677 :
678 0 : void RepeatedImmutableLazyMessageFieldLiteGenerator::
679 : GenerateParsingCode(io::Printer* printer) const {
680 : printer->Print(variables_,
681 : "if (!$is_mutable$) {\n"
682 : " $name$_ = newProtobufList();\n"
683 : "}\n"
684 : "$name$_.add(new com.google.protobuf.LazyFieldLite(\n"
685 0 : " extensionRegistry, input.readBytes()));\n");
686 0 : }
687 :
688 0 : void RepeatedImmutableLazyMessageFieldLiteGenerator::
689 : GenerateSerializationCode(io::Printer* printer) const {
690 : printer->Print(variables_,
691 : "for (int i = 0; i < $name$_.size(); i++) {\n"
692 : " output.writeBytes($number$, $name$_.get(i).toByteString());\n"
693 0 : "}\n");
694 0 : }
695 :
696 0 : void RepeatedImmutableLazyMessageFieldLiteGenerator::
697 : GenerateSerializedSizeCode(io::Printer* printer) const {
698 : printer->Print(variables_,
699 : "for (int i = 0; i < $name$_.size(); i++) {\n"
700 : " size += com.google.protobuf.CodedOutputStream\n"
701 : " .computeLazyFieldSize($number$, $name$_.get(i));\n"
702 0 : "}\n");
703 0 : }
704 :
705 : } // namespace java
706 : } // namespace compiler
707 : } // namespace protobuf
708 : } // namespace google
|