java_enum_field_lite.cc
Go to the documentation of this file.
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: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34 
35 #include <map>
36 #include <string>
37 
48 
49 
50 namespace google {
51 namespace protobuf {
52 namespace compiler {
53 namespace java {
54 
55 namespace {
56 bool EnableExperimentalRuntimeForLite() {
57 #ifdef PROTOBUF_EXPERIMENT
58  return PROTOBUF_EXPERIMENT;
59 #else // PROTOBUF_EXPERIMENT
60  return false;
61 #endif // !PROTOBUF_EXPERIMENT
62 }
63 
64 void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
65  int builderBitIndex, const FieldGeneratorInfo* info,
66  ClassNameResolver* name_resolver,
67  std::map<std::string, std::string>* variables) {
68  SetCommonFieldVariables(descriptor, info, variables);
69 
70  (*variables)["type"] =
71  name_resolver->GetImmutableClassName(descriptor->enum_type());
72  (*variables)["mutable_type"] =
73  name_resolver->GetMutableClassName(descriptor->enum_type());
74  (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
75  (*variables)["default_number"] =
76  StrCat(descriptor->default_value_enum()->number());
77  (*variables)["tag"] = StrCat(
79  (*variables)["tag_size"] = StrCat(
81  // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
82  // by the proto compiler
83  (*variables)["deprecation"] =
84  descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
85  (*variables)["required"] = descriptor->is_required() ? "true" : "false";
86 
87  if (SupportFieldPresence(descriptor->file())) {
88  // For singular messages and builders, one bit is used for the hasField bit.
89  (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
90 
91  // Note that these have a trailing ";".
92  (*variables)["set_has_field_bit_message"] =
93  GenerateSetBit(messageBitIndex) + ";";
94  (*variables)["clear_has_field_bit_message"] =
95  GenerateClearBit(messageBitIndex) + ";";
96 
97  (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex);
98  } else {
99  (*variables)["set_has_field_bit_message"] = "";
100  (*variables)["clear_has_field_bit_message"] = "";
101 
102  (*variables)["is_field_present_message"] =
103  (*variables)["name"] + "_ != " + (*variables)["default"] +
104  ".getNumber()";
105  }
106 
107  // For repeated builders, the underlying list tracks mutability state.
108  (*variables)["is_mutable"] = (*variables)["name"] + "_.isModifiable()";
109 
110  (*variables)["get_has_field_bit_from_local"] =
111  GenerateGetBitFromLocal(builderBitIndex);
112  (*variables)["set_has_field_bit_to_local"] =
113  GenerateSetBitToLocal(messageBitIndex);
114 
115  if (SupportUnknownEnumValue(descriptor->file())) {
116  (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED";
117  } else {
118  (*variables)["unknown"] = (*variables)["default"];
119  }
120 }
121 
122 } // namespace
123 
124 // ===================================================================
125 
127  const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
129  messageBitIndex_(messageBitIndex),
130  context_(context),
131  name_resolver_(context->GetNameResolver()) {
132  SetEnumVariables(descriptor, messageBitIndex, 0,
134  &variables_);
135 }
136 
138 
140  return SupportFieldPresence(descriptor_->file()) ? 1 : 0;
141 }
142 
144  io::Printer* printer) const {
147  printer->Print(variables_,
148  "$deprecation$boolean has$capitalized_name$();\n");
149  }
152  printer->Print(variables_,
153  "$deprecation$int get$capitalized_name$Value();\n");
154  }
156  printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n");
157 }
158 
160  io::Printer* printer) const {
161  printer->Print(variables_, "private int $name$_;\n");
165  printer->Print(
166  variables_,
167  "@java.lang.Override\n"
168  "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
169  " return $get_has_field_bit_message$;\n"
170  "}\n");
171  printer->Annotate("{", "}", descriptor_);
172  }
175  printer->Print(
176  variables_,
177  "@java.lang.Override\n"
178  "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
179  " return $name$_;\n"
180  "}\n");
181  printer->Annotate("{", "}", descriptor_);
182  }
184  printer->Print(variables_,
185  "@java.lang.Override\n"
186  "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
187  " $type$ result = $type$.forNumber($name$_);\n"
188  " return result == null ? $unknown$ : result;\n"
189  "}\n");
190  printer->Annotate("{", "}", descriptor_);
191 
192  // Generate private setters for the builder to proxy into.
195  printer->Print(variables_,
196  "private void set$capitalized_name$Value(int value) {\n"
197  " $set_has_field_bit_message$"
198  " $name$_ = value;\n"
199  "}\n");
200  }
202  printer->Print(variables_,
203  "private void set$capitalized_name$($type$ value) {\n"
204  " if (value == null) {\n"
205  " throw new NullPointerException();\n"
206  " }\n"
207  " $set_has_field_bit_message$\n"
208  " $name$_ = value.getNumber();\n"
209  "}\n");
211  printer->Print(variables_,
212  "private void clear$capitalized_name$() {\n"
213  " $clear_has_field_bit_message$\n"
214  " $name$_ = $default_number$;\n"
215  "}\n");
216 }
217 
219  io::Printer* printer) const {
222  printer->Print(
223  variables_,
224  "@java.lang.Override\n"
225  "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
226  " return instance.has$capitalized_name$();\n"
227  "}\n");
228  printer->Annotate("{", "}", descriptor_);
229  }
232  printer->Print(
233  variables_,
234  "@java.lang.Override\n"
235  "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
236  " return instance.get$capitalized_name$Value();\n"
237  "}\n");
238  printer->Annotate("{", "}", descriptor_);
240  printer->Print(variables_,
241  "$deprecation$public Builder "
242  "${$set$capitalized_name$Value$}$(int value) {\n"
243  " copyOnWrite();\n"
244  " instance.set$capitalized_name$Value(value);\n"
245  " return this;\n"
246  "}\n");
247  printer->Annotate("{", "}", descriptor_);
248  }
250  printer->Print(variables_,
251  "@java.lang.Override\n"
252  "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
253  " return instance.get$capitalized_name$();\n"
254  "}\n");
255  printer->Annotate("{", "}", descriptor_);
257  printer->Print(variables_,
258  "$deprecation$public Builder "
259  "${$set$capitalized_name$$}$($type$ value) {\n"
260  " copyOnWrite();\n"
261  " instance.set$capitalized_name$(value);\n"
262  " return this;\n"
263  "}\n");
264  printer->Annotate("{", "}", descriptor_);
266  printer->Print(
267  variables_,
268  "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
269  " copyOnWrite();\n"
270  " instance.clear$capitalized_name$();\n"
271  " return this;\n"
272  "}\n");
273  printer->Annotate("{", "}", descriptor_);
274 }
275 
277  io::Printer* printer) const {
279  printer->Print(variables_, "$name$_ = $default_number$;\n");
280  }
281 }
282 
284  io::Printer* printer, std::vector<uint16>* output) const {
287  output);
290  }
291  printer->Print(variables_, "\"$name$_\",\n");
294  /*var_name=*/"$type$",
295  /*terminating_string=*/",\n",
296  /*enforce_lite=*/context_->EnforceLite());
297  }
298 }
299 
302 }
303 
304 // ===================================================================
305 
307  const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
308  : ImmutableEnumFieldLiteGenerator(descriptor, messageBitIndex, context) {
309  const OneofGeneratorInfo* info =
310  context->GetOneofGeneratorInfo(descriptor->containing_oneof());
312 }
313 
315 
317  io::Printer* printer) const {
321  printer->Print(
322  variables_,
323  "@java.lang.Override\n"
324  "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
325  " return $has_oneof_case_message$;\n"
326  "}\n");
327  printer->Annotate("{", "}", descriptor_);
328  }
331  printer->Print(
332  variables_,
333  "@java.lang.Override\n"
334  "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
335  " if ($has_oneof_case_message$) {\n"
336  " return (java.lang.Integer) $oneof_name$_;\n"
337  " }\n"
338  " return $default_number$;\n"
339  "}\n");
340  printer->Annotate("{", "}", descriptor_);
341  }
343  printer->Print(variables_,
344  "@java.lang.Override\n"
345  "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
346  " if ($has_oneof_case_message$) {\n"
347  " $type$ result = $type$.forNumber((java.lang.Integer) "
348  "$oneof_name$_);\n"
349  " return result == null ? $unknown$ : result;\n"
350  " }\n"
351  " return $default$;\n"
352  "}\n");
353  printer->Annotate("{", "}", descriptor_);
354 
355  // Generate private setters for the builder to proxy into.
358  printer->Print(variables_,
359  "private void set$capitalized_name$Value(int value) {\n"
360  " $set_oneof_case_message$;\n"
361  " $oneof_name$_ = value;\n"
362  "}\n");
363  }
365  printer->Print(variables_,
366  "private void set$capitalized_name$($type$ value) {\n"
367  " if (value == null) {\n"
368  " throw new NullPointerException();\n"
369  " }\n"
370  " $set_oneof_case_message$;\n"
371  " $oneof_name$_ = value.getNumber();\n"
372  "}\n");
374  printer->Print(variables_,
375  "private void clear$capitalized_name$() {\n"
376  " if ($has_oneof_case_message$) {\n"
377  " $clear_oneof_case_message$;\n"
378  " $oneof_name$_ = null;\n"
379  " }\n"
380  "}\n");
381 }
382 
384  io::Printer* printer, std::vector<uint16>* output) const {
387  output);
391  /*var_name=*/"$type$",
392  /*terminating_string=*/",\n",
393  /*enforce_lite=*/context_->EnforceLite());
394  }
395 }
396 
398  io::Printer* printer) const {
401  printer->Print(
402  variables_,
403  "@java.lang.Override\n"
404  "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
405  " return instance.has$capitalized_name$();\n"
406  "}\n");
407  printer->Annotate("{", "}", descriptor_);
408  }
411  printer->Print(
412  variables_,
413  "@java.lang.Override\n"
414  "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
415  " return instance.get$capitalized_name$Value();\n"
416  "}\n");
417  printer->Annotate("{", "}", descriptor_);
419  printer->Print(variables_,
420  "$deprecation$public Builder "
421  "${$set$capitalized_name$Value$}$(int value) {\n"
422  " copyOnWrite();\n"
423  " instance.set$capitalized_name$Value(value);\n"
424  " return this;\n"
425  "}\n");
426  printer->Annotate("{", "}", descriptor_);
427  }
429  printer->Print(variables_,
430  "@java.lang.Override\n"
431  "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
432  " return instance.get$capitalized_name$();\n"
433  "}\n");
434  printer->Annotate("{", "}", descriptor_);
436  printer->Print(variables_,
437  "$deprecation$public Builder "
438  "${$set$capitalized_name$$}$($type$ value) {\n"
439  " copyOnWrite();\n"
440  " instance.set$capitalized_name$(value);\n"
441  " return this;\n"
442  "}\n");
443  printer->Annotate("{", "}", descriptor_);
445  printer->Print(
446  variables_,
447  "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
448  " copyOnWrite();\n"
449  " instance.clear$capitalized_name$();\n"
450  " return this;\n"
451  "}\n");
452  printer->Annotate("{", "}", descriptor_);
453 }
454 
455 // ===================================================================
456 
459  int messageBitIndex,
460  Context* context)
462  context_(context),
463  name_resolver_(context->GetNameResolver()) {
464  SetEnumVariables(descriptor, messageBitIndex, 0,
466  &variables_);
467 }
468 
471 
473  return 0;
474 }
475 
477  io::Printer* printer) const {
479  printer->Print(
480  variables_,
481  "$deprecation$java.util.List<$type$> get$capitalized_name$List();\n");
483  printer->Print(variables_,
484  "$deprecation$int get$capitalized_name$Count();\n");
486  printer->Print(variables_,
487  "$deprecation$$type$ get$capitalized_name$(int index);\n");
490  printer->Print(variables_,
491  "$deprecation$java.util.List<java.lang.Integer>\n"
492  "get$capitalized_name$ValueList();\n");
494  printer->Print(variables_,
495  "$deprecation$int get$capitalized_name$Value(int index);\n");
496  }
497 }
498 
500  io::Printer* printer) const {
501  printer->Print(
502  variables_,
503  "private com.google.protobuf.Internal.IntList $name$_;\n"
504  "private static final "
505  "com.google.protobuf.Internal.ListAdapter.Converter<\n"
506  " java.lang.Integer, $type$> $name$_converter_ =\n"
507  " new com.google.protobuf.Internal.ListAdapter.Converter<\n"
508  " java.lang.Integer, $type$>() {\n"
509  " @java.lang.Override\n"
510  " public $type$ convert(java.lang.Integer from) {\n"
511  " $type$ result = $type$.forNumber(from);\n"
512  " return result == null ? $unknown$ : result;\n"
513  " }\n"
514  " };\n");
517  printer->Print(
518  variables_,
519  "@java.lang.Override\n"
520  "$deprecation$public java.util.List<$type$> "
521  "${$get$capitalized_name$List$}$() {\n"
522  " return new com.google.protobuf.Internal.ListAdapter<\n"
523  " java.lang.Integer, $type$>($name$_, $name$_converter_);\n"
524  "}\n");
525  printer->Annotate("{", "}", descriptor_);
527  printer->Print(
528  variables_,
529  "@java.lang.Override\n"
530  "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
531  " return $name$_.size();\n"
532  "}\n");
533  printer->Annotate("{", "}", descriptor_);
535  printer->Print(
536  variables_,
537  "@java.lang.Override\n"
538  "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
539  " return $name$_converter_.convert($name$_.getInt(index));\n"
540  "}\n");
541  printer->Annotate("{", "}", descriptor_);
544  printer->Print(variables_,
545  "@java.lang.Override\n"
546  "$deprecation$public java.util.List<java.lang.Integer>\n"
547  "${$get$capitalized_name$ValueList$}$() {\n"
548  " return $name$_;\n"
549  "}\n");
550  printer->Annotate("{", "}", descriptor_);
552  printer->Print(variables_,
553  "@java.lang.Override\n"
554  "$deprecation$public int "
555  "${$get$capitalized_name$Value$}$(int index) {\n"
556  " return $name$_.getInt(index);\n"
557  "}\n");
558  printer->Annotate("{", "}", descriptor_);
559  }
560 
561  if (!EnableExperimentalRuntimeForLite() && descriptor_->is_packed() &&
563  printer->Print(variables_, "private int $name$MemoizedSerializedSize;\n");
564  }
565 
566  // Generate private setters for the builder to proxy into.
567  printer->Print(
568  variables_,
569  "private void ensure$capitalized_name$IsMutable() {\n"
570  " if (!$is_mutable$) {\n"
571  " $name$_ =\n"
572  " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
573  " }\n"
574  "}\n");
576  printer->Print(variables_,
577  "private void set$capitalized_name$(\n"
578  " int index, $type$ value) {\n"
579  " if (value == null) {\n"
580  " throw new NullPointerException();\n"
581  " }\n"
582  " ensure$capitalized_name$IsMutable();\n"
583  " $name$_.setInt(index, value.getNumber());\n"
584  "}\n");
586  printer->Print(variables_,
587  "private void add$capitalized_name$($type$ value) {\n"
588  " if (value == null) {\n"
589  " throw new NullPointerException();\n"
590  " }\n"
591  " ensure$capitalized_name$IsMutable();\n"
592  " $name$_.addInt(value.getNumber());\n"
593  "}\n");
595  printer->Print(variables_,
596  "private void addAll$capitalized_name$(\n"
597  " java.lang.Iterable<? extends $type$> values) {\n"
598  " ensure$capitalized_name$IsMutable();\n"
599  " for ($type$ value : values) {\n"
600  " $name$_.addInt(value.getNumber());\n"
601  " }\n"
602  "}\n");
604  printer->Print(variables_,
605  "private void clear$capitalized_name$() {\n"
606  " $name$_ = emptyIntList();\n"
607  "}\n");
608 
611  printer->Print(variables_,
612  "private void set$capitalized_name$Value(\n"
613  " int index, int value) {\n"
614  " ensure$capitalized_name$IsMutable();\n"
615  " $name$_.setInt(index, value);\n"
616  "}\n");
618  printer->Print(variables_,
619  "private void add$capitalized_name$Value(int value) {\n"
620  " ensure$capitalized_name$IsMutable();\n"
621  " $name$_.addInt(value);\n"
622  "}\n");
624  printer->Print(variables_,
625  "private void addAll$capitalized_name$Value(\n"
626  " java.lang.Iterable<java.lang.Integer> values) {\n"
627  " ensure$capitalized_name$IsMutable();\n"
628  " for (int value : values) {\n"
629  " $name$_.addInt(value);\n"
630  " }\n"
631  "}\n");
632  }
633 }
634 
636  io::Printer* printer, std::vector<uint16>* output) const {
639  output);
640  printer->Print(variables_, "\"$name$_\",\n");
643  /*var_name=*/"$type$",
644  /*terminating_string=*/",\n",
645  /*enforce_lite=*/context_->EnforceLite());
646  }
647 }
648 
650  io::Printer* printer) const {
652  printer->Print(variables_,
653  "@java.lang.Override\n"
654  "$deprecation$public java.util.List<$type$> "
655  "${$get$capitalized_name$List$}$() {\n"
656  " return instance.get$capitalized_name$List();\n"
657  "}\n");
658  printer->Annotate("{", "}", descriptor_);
660  printer->Print(
661  variables_,
662  "@java.lang.Override\n"
663  "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
664  " return instance.get$capitalized_name$Count();\n"
665  "}\n");
666  printer->Annotate("{", "}", descriptor_);
668  printer->Print(
669  variables_,
670  "@java.lang.Override\n"
671  "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
672  " return instance.get$capitalized_name$(index);\n"
673  "}\n");
674  printer->Annotate("{", "}", descriptor_);
676  printer->Print(variables_,
677  "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
678  " int index, $type$ value) {\n"
679  " copyOnWrite();\n"
680  " instance.set$capitalized_name$(index, value);\n"
681  " return this;\n"
682  "}\n");
683  printer->Annotate("{", "}", descriptor_);
685  printer->Print(variables_,
686  "$deprecation$public Builder "
687  "${$add$capitalized_name$$}$($type$ value) {\n"
688  " copyOnWrite();\n"
689  " instance.add$capitalized_name$(value);\n"
690  " return this;\n"
691  "}\n");
692  printer->Annotate("{", "}", descriptor_);
694  printer->Print(variables_,
695  "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
696  " java.lang.Iterable<? extends $type$> values) {\n"
697  " copyOnWrite();\n"
698  " instance.addAll$capitalized_name$(values);"
699  " return this;\n"
700  "}\n");
701  printer->Annotate("{", "}", descriptor_);
703  printer->Print(
704  variables_,
705  "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
706  " copyOnWrite();\n"
707  " instance.clear$capitalized_name$();\n"
708  " return this;\n"
709  "}\n");
710  printer->Annotate("{", "}", descriptor_);
711 
714  printer->Print(variables_,
715  "@java.lang.Override\n"
716  "$deprecation$public java.util.List<java.lang.Integer>\n"
717  "${$get$capitalized_name$ValueList$}$() {\n"
718  " return java.util.Collections.unmodifiableList(\n"
719  " instance.get$capitalized_name$ValueList());\n"
720  "}\n");
721  printer->Annotate("{", "}", descriptor_);
723  printer->Print(variables_,
724  "@java.lang.Override\n"
725  "$deprecation$public int "
726  "${$get$capitalized_name$Value$}$(int index) {\n"
727  " return instance.get$capitalized_name$Value(index);\n"
728  "}\n");
729  printer->Annotate("{", "}", descriptor_);
731  printer->Print(
732  variables_,
733  "$deprecation$public Builder ${$set$capitalized_name$Value$}$(\n"
734  " int index, int value) {\n"
735  " copyOnWrite();\n"
736  " instance.set$capitalized_name$Value(index, value);\n"
737  " return this;\n"
738  "}\n");
739  printer->Annotate("{", "}", descriptor_);
741  printer->Print(variables_,
742  "$deprecation$public Builder "
743  "${$add$capitalized_name$Value$}$(int value) {\n"
744  " instance.add$capitalized_name$Value(value);\n"
745  " return this;\n"
746  "}\n");
747  printer->Annotate("{", "}", descriptor_);
749  printer->Print(
750  variables_,
751  "$deprecation$public Builder ${$addAll$capitalized_name$Value$}$(\n"
752  " java.lang.Iterable<java.lang.Integer> values) {\n"
753  " copyOnWrite();\n"
754  " instance.addAll$capitalized_name$Value(values);\n"
755  " return this;\n"
756  "}\n");
757  printer->Annotate("{", "}", descriptor_);
758  }
759 }
760 
762  io::Printer* printer) const {
763  printer->Print(variables_, "$name$_ = emptyIntList();\n");
764 }
765 
768 }
769 
770 } // namespace java
771 } // namespace compiler
772 } // namespace protobuf
773 } // namespace google
google::protobuf::io::Printer::Print
void Print(const std::map< std::string, std::string > &variables, const char *text)
Definition: printer.cc:112
google::protobuf::compiler::java::GenerateClearBit
std::string GenerateClearBit(int bitIndex)
Definition: java_helpers.cc:672
context_
MockGeneratorContext context_
Definition: csharp_bootstrap_unittest.cc:125
google::protobuf::FieldDescriptor::enum_type
const EnumDescriptor * enum_type() const
Definition: src/google/protobuf/descriptor.cc:7235
java_name_resolver.h
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
java_doc_comment.h
google::protobuf.internal::WireFormat::TagSize
static size_t TagSize(int field_number, FieldDescriptor::Type type)
Definition: wire_format.h:293
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers
void GenerateInterfaceMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:143
google::protobuf::compiler::java::Context::EnforceLite
bool EnforceLite() const
Definition: java_context.h:87
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::context_
Context * context_
Definition: java_enum_field_lite.h:81
java_helpers.h
google::protobuf::StrCat
string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: strutil.cc:1480
google::protobuf::compiler::java::GenerateSetBit
std::string GenerateSetBit(int bitIndex)
Definition: java_helpers.cc:668
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator
Definition: java_enum_field_lite.h:58
google::protobuf::compiler::java::Context
Definition: java_context.h:65
google::protobuf::FieldDescriptor::containing_type
const Descriptor * containing_type() const
google::protobuf.internal::WireFormat::MakeTag
static uint32 MakeTag(const FieldDescriptor *field)
Definition: wire_format.h:289
google::protobuf::compiler::java::WriteFieldDocComment
void WriteFieldDocComment(io::Printer *printer, const FieldDescriptor *field)
Definition: java_doc_comment.cc:175
google::protobuf::compiler::java::ImmutableDefaultValue
std::string ImmutableDefaultValue(const FieldDescriptor *field, ClassNameResolver *name_resolver)
Definition: java_helpers.h:234
google::protobuf::compiler::java::PrintEnumVerifierLogic
void PrintEnumVerifierLogic(io::Printer *printer, const FieldDescriptor *descriptor, const std::map< std::string, std::string > &variables, const char *var_name, const char *terminating_string, bool enforce_lite)
Definition: java_helpers.cc:138
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::compiler::java::ClassNameResolver::GetImmutableClassName
std::string GetImmutableClassName(const DescriptorType *descriptor)
Definition: java_name_resolver.h:88
google::protobuf::compiler::java::SetCommonOneofVariables
void SetCommonOneofVariables(const FieldDescriptor *descriptor, const OneofGeneratorInfo *info, std::map< std::string, std::string > *variables)
Definition: java_field.cc:263
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::compiler::java::GetExperimentalJavaFieldType
int GetExperimentalJavaFieldType(const FieldDescriptor *field)
Definition: java_helpers.cc:961
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::GenerateMembers
void GenerateMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:159
google::protobuf::FieldDescriptor::is_packed
bool is_packed() const
Definition: src/google/protobuf/descriptor.cc:2983
FieldDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:129
google::protobuf::compiler::java::ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers
void GenerateBuilderMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:397
google::protobuf::compiler::java::IsDefaultValueJavaDefault
bool IsDefaultValueJavaDefault(const FieldDescriptor *field)
Definition: java_helpers.cc:580
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
google::protobuf::compiler::java::ImmutableEnumOneofFieldLiteGenerator::~ImmutableEnumOneofFieldLiteGenerator
~ImmutableEnumOneofFieldLiteGenerator()
Definition: java_enum_field_lite.cc:314
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::variables_
std::map< std::string, std::string > variables_
Definition: java_enum_field_lite.h:79
google::protobuf::compiler::java::SupportUnknownEnumValue
bool SupportUnknownEnumValue(const FileDescriptor *descriptor)
Definition: java_helpers.h:368
strutil.h
google::protobuf::compiler::java::OneofGeneratorInfo
Definition: java_field.h:164
google::protobuf::FieldDescriptor::file
const FileDescriptor * file() const
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::GetNumBitsForMessage
int GetNumBitsForMessage() const
Definition: java_enum_field_lite.cc:472
google::protobuf::compiler::java::ImmutableEnumOneofFieldLiteGenerator::ImmutableEnumOneofFieldLiteGenerator
ImmutableEnumOneofFieldLiteGenerator(const FieldDescriptor *descriptor, int messageBitIndex, Context *context)
Definition: java_enum_field_lite.cc:306
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::GenerateInitializationCode
void GenerateInitializationCode(io::Printer *printer) const
Definition: java_enum_field_lite.cc:761
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers
void GenerateMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:499
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo
void GenerateFieldInfo(io::Printer *printer, std::vector< uint16 > *output) const
Definition: java_enum_field_lite.cc:635
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::~RepeatedImmutableEnumFieldLiteGenerator
~RepeatedImmutableEnumFieldLiteGenerator()
Definition: java_enum_field_lite.cc:470
google::protobuf::compiler::java::Context::GetFieldGeneratorInfo
const FieldGeneratorInfo * GetFieldGeneratorInfo(const FieldDescriptor *field) const
Definition: java_context.cc:170
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::descriptor_
const FieldDescriptor * descriptor_
Definition: java_enum_field_lite.h:78
printer.h
google::protobuf::compiler::java::PrintExtraFieldInfo
void PrintExtraFieldInfo(const std::map< std::string, std::string > &variables, io::Printer *printer)
Definition: java_field.cc:278
google::protobuf::compiler::java::GenerateSetBitToLocal
std::string GenerateSetBitToLocal(int bitIndex)
Definition: java_helpers.cc:685
google::protobuf::FieldDescriptor::number
int number() const
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers
void GenerateBuilderMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:218
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::variables_
std::map< std::string, std::string > variables_
Definition: java_enum_field_lite.h:124
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers
void GenerateBuilderMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:649
google::protobuf::io::Printer::Annotate
void Annotate(const char *varname, const SomeDescriptor *descriptor)
Definition: printer.h:199
google::protobuf::io::Printer
Definition: printer.h:181
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::name_resolver_
ClassNameResolver * name_resolver_
Definition: java_enum_field_lite.h:126
google::protobuf::compiler::java::ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo
void GenerateFieldInfo(io::Printer *printer, std::vector< uint16 > *output) const
Definition: java_enum_field_lite.cc:383
google::protobuf::compiler::java::GetType
FieldDescriptor::Type GetType(const FieldDescriptor *field)
Definition: java_helpers.cc:317
google::protobuf::compiler::java::Context::HasGeneratedMethods
bool HasGeneratedMethods(const Descriptor *descriptor) const
Definition: java_context.cc:194
google::protobuf::compiler::java::SupportFieldPresence
bool SupportFieldPresence(const FileDescriptor *descriptor)
Definition: java_helpers.h:355
java
java_enum_field_lite.h
common.h
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::messageBitIndex_
const int messageBitIndex_
Definition: java_enum_field_lite.h:80
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::GetNumBitsForMessage
int GetNumBitsForMessage() const
Definition: java_enum_field_lite.cc:139
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::GetBoxedType
std::string GetBoxedType() const
Definition: java_enum_field_lite.cc:766
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::GenerateInitializationCode
void GenerateInitializationCode(io::Printer *printer) const
Definition: java_enum_field_lite.cc:276
google::protobuf::OneofDescriptor::index
int index() const
Definition: src/google/protobuf/descriptor.h:2103
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator
~ImmutableEnumFieldLiteGenerator()
Definition: java_enum_field_lite.cc:137
wire_format.h
logging.h
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers
void GenerateInterfaceMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:476
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::name_resolver_
ClassNameResolver * name_resolver_
Definition: java_enum_field_lite.h:82
google::protobuf::compiler::java::ImmutableEnumOneofFieldLiteGenerator::GenerateMembers
void GenerateMembers(io::Printer *printer) const
Definition: java_enum_field_lite.cc:316
google::protobuf::compiler::java::SetCommonFieldVariables
void SetCommonFieldVariables(const FieldDescriptor *descriptor, const FieldGeneratorInfo *info, std::map< std::string, std::string > *variables)
Definition: java_field.cc:245
java_context.h
google::protobuf::FieldDescriptor::containing_oneof
const OneofDescriptor * containing_oneof() const
google::protobuf::compiler::java::GenerateGetBit
std::string GenerateGetBit(int bitIndex)
Definition: java_helpers.cc:664
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::descriptor_
const FieldDescriptor * descriptor_
Definition: java_enum_field_lite.h:123
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::RepeatedImmutableEnumFieldLiteGenerator
RepeatedImmutableEnumFieldLiteGenerator(const FieldDescriptor *descriptor, int messageBitIndex, Context *context)
Definition: java_enum_field_lite.cc:458
google::protobuf::compiler::java::RepeatedImmutableEnumFieldLiteGenerator::context_
Context * context_
Definition: java_enum_field_lite.h:125
descriptor_
const Descriptor * descriptor_
Definition: field_comparator_test.cc:56
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::GetBoxedType
std::string GetBoxedType() const
Definition: java_enum_field_lite.cc:300
google::protobuf::compiler::java::Context::GetOneofGeneratorInfo
const OneofGeneratorInfo * GetOneofGeneratorInfo(const OneofDescriptor *oneof) const
Definition: java_context.cc:181
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::GenerateFieldInfo
void GenerateFieldInfo(io::Printer *printer, std::vector< uint16 > *output) const
Definition: java_enum_field_lite.cc:283
google::protobuf::compiler::java::WriteIntToUtf16CharSequence
void WriteIntToUtf16CharSequence(int value, std::vector< uint16 > *output)
Definition: java_helpers.h:402
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11
google::protobuf::compiler::java::ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator
ImmutableEnumFieldLiteGenerator(const FieldDescriptor *descriptor, int messageBitIndex, Context *context)
Definition: java_enum_field_lite.cc:126
google::protobuf::compiler::java::GenerateGetBitFromLocal
std::string GenerateGetBitFromLocal(int bitIndex)
Definition: java_helpers.cc:681


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:54