protobuf/src/google/protobuf/compiler/java/java_message.h
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 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
36 #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
37 
38 #include <map>
39 #include <string>
40 #include <google/protobuf/compiler/java/java_field.h>
41 
42 namespace google {
43 namespace protobuf {
44 namespace compiler {
45 namespace java {
46 class Context; // context.h
47 class ClassNameResolver; // name_resolver.h
48 } // namespace java
49 } // namespace compiler
50 namespace io {
51 class Printer; // printer.h
52 }
53 } // namespace protobuf
54 } // namespace google
55 
56 namespace google {
57 namespace protobuf {
58 namespace compiler {
59 namespace java {
60 
61 static const int kMaxStaticSize = 1 << 15; // aka 32k
62 
63 class MessageGenerator {
64  public:
65  explicit MessageGenerator(const Descriptor* descriptor);
66  virtual ~MessageGenerator();
67 
68  // All static variables have to be declared at the top-level of the file
69  // so that we can control initialization order, which is important for
70  // DescriptorProto bootstrapping to work.
71  virtual void GenerateStaticVariables(io::Printer* printer,
72  int* bytecode_estimate) = 0;
73 
74  // Output code which initializes the static variables generated by
75  // GenerateStaticVariables(). Returns an estimate of bytecode size.
76  virtual int GenerateStaticVariableInitializers(io::Printer* printer) = 0;
77 
78  // Generate the class itself.
79  virtual void Generate(io::Printer* printer) = 0;
80 
81  // Generates the base interface that both the class and its builder
82  // implement
83  virtual void GenerateInterface(io::Printer* printer) = 0;
84 
85  // Generate code to register all contained extensions with an
86  // ExtensionRegistry.
87  virtual void GenerateExtensionRegistrationCode(io::Printer* printer) = 0;
88  virtual void GenerateKotlinDsl(io::Printer* printer) const = 0;
89  virtual void GenerateKotlinMembers(io::Printer* printer) const = 0;
90  virtual void GenerateTopLevelKotlinMembers(io::Printer* printer) const = 0;
91 
92  protected:
93  const Descriptor* descriptor_;
94  std::set<const OneofDescriptor*> oneofs_;
95 
96  private:
98 };
99 
101  public:
103  virtual ~ImmutableMessageGenerator();
104 
105  void Generate(io::Printer* printer) override;
106  void GenerateInterface(io::Printer* printer) override;
107  void GenerateExtensionRegistrationCode(io::Printer* printer) override;
108  void GenerateStaticVariables(io::Printer* printer,
109  int* bytecode_estimate) override;
110 
111  // Returns an estimate of the number of bytes the printed code will compile to
112  int GenerateStaticVariableInitializers(io::Printer* printer) override;
113  void GenerateKotlinDsl(io::Printer* printer) const override;
114  void GenerateKotlinMembers(io::Printer* printer) const override;
115  void GenerateTopLevelKotlinMembers(io::Printer* printer) const override;
116 
117  private:
118  void GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate);
119 
120  // Returns an estimate of the number of bytes the printed code will compile to
122 
124  void GenerateParseFromMethods(io::Printer* printer);
126  const FieldDescriptor* field);
128  io::Printer* printer, const Descriptor::ExtensionRange* range);
129 
130  void GenerateBuilder(io::Printer* printer);
131  void GenerateIsInitialized(io::Printer* printer);
132  void GenerateDescriptorMethods(io::Printer* printer);
133  void GenerateInitializers(io::Printer* printer);
134  void GenerateEqualsAndHashCode(io::Printer* printer);
135  void GenerateParser(io::Printer* printer);
137  void GenerateMutableCopy(io::Printer* printer);
138  void GenerateKotlinExtensions(io::Printer* printer) const;
139  void GenerateAnyMethods(io::Printer* printer);
140 
141  Context* context_;
144 
146 };
147 
148 } // namespace java
149 } // namespace compiler
150 } // namespace protobuf
151 } // namespace google
152 
153 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateEqualsAndHashCode
void GenerateEqualsAndHashCode(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:998
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateMessageSerializationMethods
void GenerateMessageSerializationMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:564
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateTopLevelKotlinMembers
void GenerateTopLevelKotlinMembers(io::Printer *printer) const override
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1481
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateInterface
virtual void GenerateInterface(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:240
google::protobuf::compiler::java::MessageGenerator
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:63
google::protobuf::compiler::java::ImmutableMessageGenerator
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:96
google::protobuf::FieldDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:515
google::protobuf::compiler::java::MessageGenerator::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator)
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateIsInitialized
void GenerateIsInitialized(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:863
google::protobuf::compiler::java::ImmutableMessageGenerator::context_
Context * context_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:132
google::protobuf::compiler::java::FieldGeneratorMap
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:118
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateKotlinMembers
void GenerateKotlinMembers(io::Printer *printer) const override
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1455
capstone.range
range
Definition: third_party/bloaty/third_party/capstone/bindings/python/capstone/__init__.py:6
google::protobuf::compiler::java::Context
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_context.h:65
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateParseFromMethods
void GenerateParseFromMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:670
grpc::protobuf::io::Printer
GRPC_CUSTOM_PRINTER Printer
Definition: src/compiler/config.h:54
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateSerializeOneExtensionRange
void GenerateSerializeOneExtensionRange(io::Printer *printer, const Descriptor::ExtensionRange *range)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:756
google::protobuf::compiler::java::MessageGenerator::GenerateKotlinMembers
virtual void GenerateKotlinMembers(io::Printer *printer) const =0
google::protobuf::compiler::java::MessageGenerator::GenerateStaticVariableInitializers
virtual int GenerateStaticVariableInitializers(io::Printer *printer)=0
google::protobuf::compiler::java::ImmutableMessageGenerator::ImmutableMessageGenerator
ImmutableMessageGenerator(const Descriptor *descriptor, Context *context)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:83
google::protobuf::compiler::java::MessageGenerator::MessageGenerator
MessageGenerator(const Descriptor *descriptor)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:77
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateParsingConstructor
void GenerateParsingConstructor(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1168
google::protobuf::compiler::java::ImmutableMessageGenerator::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageGenerator)
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer
int GenerateFieldAccessorTableInitializer(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:212
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateMutableCopy
void GenerateMutableCopy(io::Printer *printer)
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1370
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateFieldAccessorTable
void GenerateFieldAccessorTable(io::Printer *printer, int *bytecode_estimate)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:184
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateStaticVariables
virtual void GenerateStaticVariables(io::Printer *printer, int *bytecode_estimate)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:96
google::protobuf::compiler::java::MessageGenerator::~MessageGenerator
virtual ~MessageGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:80
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateDescriptorMethods
void GenerateDescriptorMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:798
io
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateBuilder
void GenerateBuilder(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:764
google::protobuf::compiler::java::kMaxStaticSize
static const int kMaxStaticSize
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:61
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateAnyMethods
void GenerateAnyMethods(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1370
google::protobuf::compiler::java::MessageGenerator::oneofs_
std::set< const OneofDescriptor * > oneofs_
Definition: protobuf/src/google/protobuf/compiler/java/java_message.h:94
google::protobuf::compiler::java::ImmutableMessageGenerator::~ImmutableMessageGenerator
virtual ~ImmutableMessageGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:94
google::protobuf::compiler::java::ImmutableMessageGenerator::name_resolver_
ClassNameResolver * name_resolver_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:133
google::protobuf::compiler::java::MessageGenerator::GenerateKotlinDsl
virtual void GenerateKotlinDsl(io::Printer *printer) const =0
google::protobuf::compiler::java::MessageGenerator::GenerateStaticVariables
virtual void GenerateStaticVariables(io::Printer *printer, int *bytecode_estimate)=0
google::protobuf::io::Printer
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/printer.h:181
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateKotlinDsl
void GenerateKotlinDsl(io::Printer *printer) const override
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1404
google::protobuf::compiler::java::MessageGenerator::GenerateExtensionRegistrationCode
virtual void GenerateExtensionRegistrationCode(io::Printer *printer)=0
java
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateSerializeOneField
void GenerateSerializeOneField(io::Printer *printer, const FieldDescriptor *field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:751
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateParser
void GenerateParser(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1302
google::protobuf::compiler::java::MessageGenerator::GenerateInterface
virtual void GenerateInterface(io::Printer *printer)=0
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateKotlinExtensions
void GenerateKotlinExtensions(io::Printer *printer) const
Definition: protobuf/src/google/protobuf/compiler/java/java_message.cc:1500
google::protobuf::compiler::java::ImmutableMessageGenerator::field_generators_
FieldGeneratorMap< ImmutableFieldGenerator > field_generators_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:134
google::protobuf::Descriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:231
google::protobuf::compiler::java::MessageGenerator::descriptor_
const Descriptor * descriptor_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h:90
google::protobuf::compiler::java::MessageGenerator::Generate
virtual void Generate(io::Printer *printer)=0
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateStaticVariableInitializers
virtual int GenerateStaticVariableInitializers(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:146
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
google::protobuf::compiler::java::ClassNameResolver
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h:56
google::protobuf::compiler::java::MessageGenerator::GenerateTopLevelKotlinMembers
virtual void GenerateTopLevelKotlinMembers(io::Printer *printer) const =0
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateExtensionRegistrationCode
virtual void GenerateExtensionRegistrationCode(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1154
compiler
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/plugin.pb.cc:21
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::compiler::java::ImmutableMessageGenerator::Generate
virtual void Generate(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:290
google::protobuf::compiler::java::ImmutableMessageGenerator::GenerateInitializers
void GenerateInitializers(io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc:1360


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:09