Go to the documentation of this file.
65 using internal::WireFormat;
66 using internal::WireFormatLite;
73 name_resolver_(context->GetNameResolver()),
76 <<
"Generator factory error: A lite message generator is used to "
77 "generate non-lite messages.";
88 .GenerateStaticVariables(printer, bytecode_estimate);
94 int bytecode_estimate = 0;
100 .GenerateStaticVariableInitializers(printer);
102 return bytecode_estimate;
112 "$deprecation$public interface ${$$classname$OrBuilder$}$ extends \n"
113 " $extra_interfaces$\n"
114 " com.google.protobuf.GeneratedMessageLite.\n"
115 " ExtendableMessageOrBuilder<\n"
116 " $classname$, $classname$.Builder> {\n",
123 "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
124 " $extra_interfaces$\n"
125 " com.google.protobuf.MessageLiteOrBuilder {\n",
135 printer->
Print(
"\n");
137 .GenerateInterfaceMembers(printer);
142 "public $classname$.$oneof_capitalized_name$Case "
143 "get$oneof_capitalized_name$Case();\n",
144 "oneof_capitalized_name",
152 printer->
Print(
"}\n");
160 std::map<std::string, std::string> variables;
161 variables[
"static"] = is_own_file ?
" " :
" static ";
164 variables[
"deprecation"] =
177 "$deprecation$public $static$final class $classname$ extends\n"
178 " com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n"
179 " $classname$, $classname$.Builder> implements\n"
180 " $extra_interfaces$\n"
181 " $classname$OrBuilder {\n");
183 "com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>",
188 "$deprecation$public $static$final class $classname$ extends\n"
189 " com.google.protobuf.GeneratedMessageLite<\n"
190 " $classname$, $classname$.Builder> implements\n"
191 " $extra_interfaces$\n"
192 " $classname$OrBuilder {\n");
194 builder_type =
"com.google.protobuf.GeneratedMessageLite.Builder";
221 int totalInts = (totalBits + 31) / 32;
222 for (
int i = 0;
i < totalInts;
i++) {
223 printer->
Print(
"private int $bit_field_name$;\n",
"bit_field_name",
228 std::map<std::string, std::string> vars;
232 vars[
"oneof_capitalized_name"] =
237 "private int $oneof_name$Case_ = 0;\n"
238 "private java.lang.Object $oneof_name$_;\n");
241 "public enum $oneof_capitalized_name$Case\n"
242 " implements com.google.protobuf.Internal.EnumLite {\n");
246 printer->
Print(
"$field_name$($field_number$),\n",
"field_name",
250 printer->
Print(
"$cap_oneof_name$_NOT_SET(0);\n",
"cap_oneof_name",
253 "private final int value;\n"
254 "private $oneof_capitalized_name$Case(int value) {\n"
255 " this.value = value;\n"
260 " * @deprecated Use {@link #forNumber(int)} instead.\n"
262 "@java.lang.Deprecated\n"
263 "public static $oneof_capitalized_name$Case valueOf(int value) {\n"
264 " return forNumber(value);\n"
267 "public static $oneof_capitalized_name$Case forNumber(int value) {\n"
268 " switch (value) {\n");
271 printer->
Print(
" case $field_number$: return $field_name$;\n",
276 " case 0: return $cap_oneof_name$_NOT_SET;\n"
277 " default: return null;\n"
280 "@java.lang.Override\n"
281 "public int getNumber() {\n"
282 " return this.value;\n"
284 "cap_oneof_name",
ToUpper(vars[
"oneof_name"]));
286 printer->
Print(
"};\n\n");
289 "@java.lang.Override\n"
290 "public $oneof_capitalized_name$Case\n"
291 "get$oneof_capitalized_name$Case() {\n"
292 " return $oneof_capitalized_name$Case.forNumber(\n"
293 " $oneof_name$Case_);\n"
296 "private void clear$oneof_capitalized_name$() {\n"
297 " $oneof_name$Case_ = 0;\n"
298 " $oneof_name$_ = null;\n"
305 printer->
Print(
"public static final int $constant_name$ = $number$;\n",
309 printer->
Print(
"\n");
319 printer->
Print(
"private byte memoizedIsInitialized = 2;\n");
323 "@java.lang.Override\n"
324 "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n"
325 "protected final java.lang.Object dynamicMethod(\n"
326 " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n"
327 " java.lang.Object arg0, java.lang.Object arg1) {\n"
328 " switch (method) {\n"
329 " case NEW_MUTABLE_INSTANCE: {\n"
330 " return new $classname$();\n"
337 printer->
Print(
"case NEW_BUILDER: {\n");
345 "case BUILD_MESSAGE_INFO: {\n");
354 "case GET_DEFAULT_INSTANCE: {\n"
355 " return DEFAULT_INSTANCE;\n"
357 "case GET_PARSER: {\n"
365 " com.google.protobuf.Parser<$classname$> parser = PARSER;\n"
366 " if (parser == null) {\n"
367 " synchronized ($classname$.class) {\n"
368 " parser = PARSER;\n"
369 " if (parser == null) {\n"
371 " new DefaultInstanceBasedParser<$classname$>(\n"
372 " DEFAULT_INSTANCE);\n"
373 " PARSER = parser;\n"
385 "case GET_MEMOIZED_IS_INITIALIZED: {\n"
386 " return memoizedIsInitialized;\n"
388 "case SET_MEMOIZED_IS_INITIALIZED: {\n"
389 " memoizedIsInitialized = (byte) (arg0 == null ? 0 : 1);\n"
395 "case GET_MEMOIZED_IS_INITIALIZED: {\n"
396 " return (byte) 1;\n"
398 "case SET_MEMOIZED_IS_INITIALIZED: {\n"
406 " throw new UnsupportedOperationException();\n"
413 "// @@protoc_insertion_point(class_scope:$full_name$)\n",
418 printer->
Print(
"private static final $classname$ DEFAULT_INSTANCE;\n",
424 " $classname$ defaultInstance = new $classname$();\n"
425 " // New instances are implicitly immutable so no need to make\n"
427 " DEFAULT_INSTANCE = defaultInstance;\n"
431 " com.google.protobuf.GeneratedMessageLite.registerDefaultInstance(\n"
432 " $classname$.class, defaultInstance);\n"
438 "public static $classname$ getDefaultInstance() {\n"
439 " return DEFAULT_INSTANCE;\n"
447 "public static $classname$ of($field_type$ value) {\n"
448 " return newBuilder().setValue(value).build();\n"
466 printer->
Print(
"}\n\n");
475 std::vector<uint16> chars;
488 printer->
Print(
"java.lang.Object[] objects = null;");
491 printer->
Print(
"java.lang.Object[] objects = new java.lang.Object[] {\n");
499 "\"$oneof_name$_\",\n"
500 "\"$oneof_name$Case_\",\n",
510 int total_ints = (total_bits + 31) / 32;
511 for (
int i = 0;
i < total_ints;
i++) {
512 printer->
Print(
"\"$bit_field_name$\",\n",
"bit_field_name",
518 int repeated_count = 0;
519 std::unique_ptr<const FieldDescriptor*[]> sorted_fields(
523 if (
field->is_map()) {
525 }
else if (
field->is_repeated()) {
537 std::vector<const FieldDescriptor*> fields_for_is_initialized_check;
552 printer->
Print(
"};\n");
555 printer->
Print(
"java.lang.String info =\n");
557 for (
size_t i = 0;
i < chars.size();
i++) {
560 if (line.size() >= 80) {
561 printer->
Print(
" \"$string$\" +\n",
"string", line);
565 printer->
Print(
" \"$string$\";\n",
"string", line);
567 printer->
Print(
"return newMessageInfo(DEFAULT_INSTANCE, info, objects);\n");
576 "public static $classname$ parseFrom(\n"
577 " java.nio.ByteBuffer data)\n"
578 " throws com.google.protobuf.InvalidProtocolBufferException {\n"
579 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
580 " DEFAULT_INSTANCE, data);\n"
582 "public static $classname$ parseFrom(\n"
583 " java.nio.ByteBuffer data,\n"
584 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
585 " throws com.google.protobuf.InvalidProtocolBufferException {\n"
586 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
587 " DEFAULT_INSTANCE, data, extensionRegistry);\n"
589 "public static $classname$ parseFrom(\n"
590 " com.google.protobuf.ByteString data)\n"
591 " throws com.google.protobuf.InvalidProtocolBufferException {\n"
592 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
593 " DEFAULT_INSTANCE, data);\n"
595 "public static $classname$ parseFrom(\n"
596 " com.google.protobuf.ByteString data,\n"
597 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
598 " throws com.google.protobuf.InvalidProtocolBufferException {\n"
599 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
600 " DEFAULT_INSTANCE, data, extensionRegistry);\n"
602 "public static $classname$ parseFrom(byte[] data)\n"
603 " throws com.google.protobuf.InvalidProtocolBufferException {\n"
604 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
605 " DEFAULT_INSTANCE, data);\n"
607 "public static $classname$ parseFrom(\n"
609 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
610 " throws com.google.protobuf.InvalidProtocolBufferException {\n"
611 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
612 " DEFAULT_INSTANCE, data, extensionRegistry);\n"
614 "public static $classname$ parseFrom(java.io.InputStream input)\n"
615 " throws java.io.IOException {\n"
616 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
617 " DEFAULT_INSTANCE, input);\n"
619 "public static $classname$ parseFrom(\n"
620 " java.io.InputStream input,\n"
621 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
622 " throws java.io.IOException {\n"
623 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
624 " DEFAULT_INSTANCE, input, extensionRegistry);\n"
626 "public static $classname$ parseDelimitedFrom(java.io.InputStream "
628 " throws java.io.IOException {\n"
629 " return parseDelimitedFrom(DEFAULT_INSTANCE, input);\n"
631 "public static $classname$ parseDelimitedFrom(\n"
632 " java.io.InputStream input,\n"
633 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
634 " throws java.io.IOException {\n"
635 " return parseDelimitedFrom(DEFAULT_INSTANCE, input, "
636 "extensionRegistry);\n"
638 "public static $classname$ parseFrom(\n"
639 " com.google.protobuf.CodedInputStream input)\n"
640 " throws java.io.IOException {\n"
641 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
642 " DEFAULT_INSTANCE, input);\n"
644 "public static $classname$ parseFrom(\n"
645 " com.google.protobuf.CodedInputStream input,\n"
646 " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n"
647 " throws java.io.IOException {\n"
648 " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n"
649 " DEFAULT_INSTANCE, input, extensionRegistry);\n"
659 "public static Builder newBuilder() {\n"
660 " return (Builder) DEFAULT_INSTANCE.createBuilder();\n"
662 "public static Builder newBuilder($classname$ prototype) {\n"
663 " return (Builder) DEFAULT_INSTANCE.createBuilder(prototype);\n"
676 printer->
Print(
"return new Builder();\n");
690 .GenerateExtensionRegistrationCode(printer);
703 printer->
Print(
"}\n");
709 "private static volatile com.google.protobuf.Parser<$classname$> "
712 "public static com.google.protobuf.Parser<$classname$> parser() {\n"
713 " return DEFAULT_INSTANCE.getParserForType();\n"
723 .GenerateInitializationCode(printer);
const std::string & full_name() const
void Print(const std::map< std::string, std::string > &variables, const char *text)
MockGeneratorContext context_
void MaybePrintGeneratedAnnotation(Context *context, io::Printer *printer, Descriptor *descriptor, bool immutable, const std::string &suffix="")
void GenerateDynamicMethodNewBuildMessageInfo(io::Printer *printer)
bool HasDescriptorMethods(const Descriptor *descriptor, bool enforce_lite)
virtual ~ImmutableMessageLiteGenerator()
bool IsMapEntry(const Descriptor *descriptor)
string StrCat(const AlphaNum &a, const AlphaNum &b)
int nested_type_count() const
ImmutableMessageLiteGenerator(const Descriptor *descriptor, Context *context)
GLsizei const GLchar *const * string
std::string GetImmutableClassName(const DescriptorType *descriptor)
const FieldDescriptor * field(int index) const
const MessageOptions & options() const
std::string ExtraMessageOrBuilderInterfaces(const Descriptor *descriptor)
const FieldDescriptor * field(int index) const
void WriteMessageDocComment(io::Printer *printer, const Descriptor *message)
ClassNameResolver * name_resolver_
bool IsWrappersProtoFile(const FileDescriptor *descriptor)
void GenerateDynamicMethodNewBuilder(io::Printer *printer)
virtual void Generate(io::Printer *printer)
const OneofDescriptor * oneof_decl(int index) const
JavaType GetJavaType(const FieldDescriptor *field)
virtual int GenerateRegistrationCode(io::Printer *printer)
virtual void GenerateExtensionRegistrationCode(io::Printer *printer)
std::string ExtraMessageInterfaces(const Descriptor *descriptor)
virtual void GenerateInterface(io::Printer *printer)
void Generate(io::Printer *printer)
int oneof_decl_count() const
int extension_count() const
const EnumDescriptor * enum_type(int index) const
const Descriptor * descriptor_
std::string GetBitFieldName(int index)
string Substitute(const char *format, const SubstituteArg &arg0, const SubstituteArg &arg1, const SubstituteArg &arg2, const SubstituteArg &arg3, const SubstituteArg &arg4, const SubstituteArg &arg5, const SubstituteArg &arg6, const SubstituteArg &arg7, const SubstituteArg &arg8, const SubstituteArg &arg9)
const FieldDescriptor * extension(int index) const
int extension_range_count() const
void GenerateConstructor(io::Printer *printer)
const FieldDescriptor * field
void Annotate(const char *varname, const SomeDescriptor *descriptor)
#define GOOGLE_CHECK(EXPRESSION)
virtual void GenerateStaticVariables(io::Printer *printer, int *bytecode_estimate)
bool SupportFieldPresence(const FileDescriptor *descriptor)
const Descriptor * nested_type(int index) const
int enum_type_count() const
FieldGeneratorMap< ImmutableFieldLiteGenerator > field_generators_
virtual int GenerateStaticVariableInitializers(io::Printer *printer)
virtual void Generate(io::Printer *printer)
const std::string & name() const
const FileDescriptor * file() const
void GenerateBuilder(io::Printer *printer)
string ToUpper(const string &s)
const Descriptor * message_type() const
std::string FieldConstantName(const FieldDescriptor *field)
void GenerateInitializers(io::Printer *printer)
void GenerateParseFromMethods(io::Printer *printer)
const OneofDescriptor * containing_oneof() const
ClassNameResolver * GetNameResolver() const
virtual void Generate(io::Printer *printer)
bool HasRequiredFields(const Descriptor *type, std::unordered_set< const Descriptor * > *already_seen)
std::string capitalized_name
const OneofGeneratorInfo * GetOneofGeneratorInfo(const OneofDescriptor *oneof) const
bool IsOwnFile(const Descriptor *descriptor, bool immutable)
const char * PrimitiveTypeName(JavaType type)
const FieldDescriptor ** SortFieldsByNumber(const Descriptor *descriptor)
void WriteIntToUtf16CharSequence(int value, std::vector< uint16 > *output)
void GenerateParser(io::Printer *printer)
bool message_set_wire_format() const
void EscapeUtf16ToString(uint16 code, std::string *output)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55