protobuf/src/google/protobuf/compiler/java/java_field.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_FIELD_H__
36 #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__
37 
38 #include <cstdint>
39 #include <map>
40 #include <memory>
41 #include <string>
42 
43 #include <google/protobuf/stubs/logging.h>
44 #include <google/protobuf/stubs/common.h>
45 #include <google/protobuf/descriptor.h>
46 
47 namespace google {
48 namespace protobuf {
49 namespace compiler {
50 namespace java {
51 class Context; // context.h
52 class ClassNameResolver; // name_resolver.h
53 } // namespace java
54 } // namespace compiler
55 namespace io {
56 class Printer; // printer.h
57 }
58 } // namespace protobuf
59 } // namespace google
60 
61 namespace google {
62 namespace protobuf {
63 namespace compiler {
64 namespace java {
65 
66 class ImmutableFieldGenerator {
67  public:
69  virtual ~ImmutableFieldGenerator();
70 
71  virtual int GetNumBitsForMessage() const = 0;
72  virtual int GetNumBitsForBuilder() const = 0;
73  virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
74  virtual void GenerateMembers(io::Printer* printer) const = 0;
75  virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
76  virtual void GenerateInitializationCode(io::Printer* printer) const = 0;
77  virtual void GenerateBuilderClearCode(io::Printer* printer) const = 0;
78  virtual void GenerateMergingCode(io::Printer* printer) const = 0;
79  virtual void GenerateBuildingCode(io::Printer* printer) const = 0;
80  virtual void GenerateParsingCode(io::Printer* printer) const = 0;
81  virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const;
82  virtual void GenerateParsingDoneCode(io::Printer* printer) const = 0;
83  virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
84  virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
86  io::Printer* printer) const = 0;
87  virtual void GenerateKotlinDslMembers(io::Printer* printer) const = 0;
88 
89  virtual void GenerateEqualsCode(io::Printer* printer) const = 0;
90  virtual void GenerateHashCode(io::Printer* printer) const = 0;
91 
92  virtual std::string GetBoxedType() const = 0;
93 
94  private:
96 };
97 
98 class ImmutableFieldLiteGenerator {
99  public:
102 
103  virtual int GetNumBitsForMessage() const = 0;
104  virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
105  virtual void GenerateMembers(io::Printer* printer) const = 0;
106  virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
107  virtual void GenerateInitializationCode(io::Printer* printer) const = 0;
108  virtual void GenerateFieldInfo(io::Printer* printer,
109  std::vector<uint16_t>* output) const = 0;
110  virtual void GenerateKotlinDslMembers(io::Printer* printer) const = 0;
111 
112  virtual std::string GetBoxedType() const = 0;
113 
114  private:
116 };
117 
118 
119 // Convenience class which constructs FieldGenerators for a Descriptor.
120 template <typename FieldGeneratorType>
121 class FieldGeneratorMap {
122  public:
123  explicit FieldGeneratorMap(const Descriptor* descriptor, Context* context);
125 
126  const FieldGeneratorType& get(const FieldDescriptor* field) const;
127 
128  private:
129  const Descriptor* descriptor_;
130  std::vector<std::unique_ptr<FieldGeneratorType>> field_generators_;
131 
133 };
134 
135 template <typename FieldGeneratorType>
136 inline const FieldGeneratorType& FieldGeneratorMap<FieldGeneratorType>::get(
137  const FieldDescriptor* field) const {
138  GOOGLE_CHECK_EQ(field->containing_type(), descriptor_);
139  return *field_generators_[field->index()];
140 }
141 
142 // Instantiate template for mutable and immutable maps.
143 template <>
145  const Descriptor* descriptor, Context* context);
146 
147 template <>
149 
150 
151 template <>
153  const Descriptor* descriptor, Context* context);
154 
155 template <>
157 
158 
159 // Field information used in FieldGeneartors.
160 struct FieldGeneratorInfo {
164 };
165 
166 // Oneof information used in OneofFieldGenerators.
167 struct OneofGeneratorInfo {
170 };
171 
172 // Set some common variables used in variable FieldGenerators.
174  const FieldGeneratorInfo* info,
175  std::map<std::string, std::string>* variables);
176 
177 // Set some common oneof variables used in OneofFieldGenerators.
179  const OneofGeneratorInfo* info,
180  std::map<std::string, std::string>* variables);
181 
182 // Print useful comments before a field's accessors.
183 void PrintExtraFieldInfo(const std::map<std::string, std::string>& variables,
184  io::Printer* printer);
185 
186 } // namespace java
187 } // namespace compiler
188 } // namespace protobuf
189 } // namespace google
190 
191 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateInitializationCode
virtual void GenerateInitializationCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateBuildingCode
virtual void GenerateBuildingCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateHashCode
virtual void GenerateHashCode(io::Printer *printer) const =0
descriptor_
string_view descriptor_
Definition: elf.cc:154
google::protobuf::compiler::java::FieldGeneratorMap::descriptor_
const Descriptor * descriptor_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:126
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateFieldBuilderInitializationCode
virtual void GenerateFieldBuilderInitializationCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateKotlinDslMembers
virtual void GenerateKotlinDslMembers(io::Printer *printer) const =0
google::protobuf::FieldDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:515
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateMergingCode
virtual void GenerateMergingCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateParsingCode
virtual void GenerateParsingCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::ImmutableFieldGenerator
ImmutableFieldGenerator()
Definition: protobuf/src/google/protobuf/compiler/java/java_field.h:68
google::protobuf::compiler::java::FieldGeneratorMap::FieldGeneratorMap
FieldGeneratorMap(const Descriptor *descriptor, Context *context)
GOOGLE_CHECK_EQ
#define GOOGLE_CHECK_EQ(A, B)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:156
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::compiler::java::ImmutableFieldGenerator::GetNumBitsForBuilder
virtual int GetNumBitsForBuilder() const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateEqualsCode
virtual void GenerateEqualsCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateParsingDoneCode
virtual void GenerateParsingDoneCode(io::Printer *printer) const =0
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::FieldGeneratorInfo::name
std::string name
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:158
google::protobuf::compiler::java::SetCommonOneofVariables
void SetCommonOneofVariables(const FieldDescriptor *descriptor, const OneofGeneratorInfo *info, std::map< std::string, std::string > *variables)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc:262
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GenerateFieldInfo
virtual void GenerateFieldInfo(io::Printer *printer, std::vector< uint16 > *output) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:65
Descriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:121
google::protobuf::compiler::java::FieldGeneratorMap::get
const FieldGeneratorType & get(const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:133
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::~ImmutableFieldLiteGenerator
virtual ~ImmutableFieldLiteGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc:201
FieldDescriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:133
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldLiteGenerator)
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GetNumBitsForMessage
virtual int GetNumBitsForMessage() const =0
google::protobuf::compiler::java::PrintExtraFieldInfo
void PrintExtraFieldInfo(const std::map< std::string, std::string > &variables, io::Printer *printer)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc:277
io
google::protobuf::compiler::java::ImmutableFieldGenerator::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator)
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::ImmutableFieldLiteGenerator
ImmutableFieldLiteGenerator()
Definition: protobuf/src/google/protobuf/compiler/java/java_field.h:100
google::protobuf::compiler::java::OneofGeneratorInfo::name
std::string name
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:165
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GetBoxedType
virtual std::string GetBoxedType() const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateBuilderMembers
virtual void GenerateBuilderMembers(io::Printer *printer) const =0
google::protobuf::io::Printer
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/printer.h:181
google::protobuf::compiler::java::FieldGeneratorInfo::capitalized_name
std::string capitalized_name
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:159
google::protobuf::compiler::java::ImmutableFieldGenerator::~ImmutableFieldGenerator
virtual ~ImmutableFieldGenerator()
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc:194
java
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GenerateMembers
virtual void GenerateMembers(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateSerializationCode
virtual void GenerateSerializationCode(io::Printer *printer) const =0
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GenerateBuilderMembers
virtual void GenerateBuilderMembers(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GenerateInitializationCode
virtual void GenerateInitializationCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GetBoxedType
virtual std::string GetBoxedType() const =0
google::protobuf::compiler::java::ImmutableFieldLiteGenerator
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:96
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateBuilderClearCode
virtual void GenerateBuilderClearCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateSerializedSizeCode
virtual void GenerateSerializedSizeCode(io::Printer *printer) const =0
google::protobuf::compiler::java::FieldGeneratorMap::field_generators_
std::vector< std::unique_ptr< FieldGeneratorType > > field_generators_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:127
google::protobuf::compiler::java::ImmutableFieldGenerator::GetNumBitsForMessage
virtual int GetNumBitsForMessage() const =0
google::protobuf::Descriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:231
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateParsingCodeFromPacked
virtual void GenerateParsingCodeFromPacked(io::Printer *printer) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc:196
google::protobuf::compiler::java::SetCommonFieldVariables
void SetCommonFieldVariables(const FieldDescriptor *descriptor, const FieldGeneratorInfo *info, std::map< std::string, std::string > *variables)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc:244
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GenerateInterfaceMembers
virtual void GenerateInterfaceMembers(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateMembers
virtual void GenerateMembers(io::Printer *printer) const =0
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
google::protobuf::compiler::java::OneofGeneratorInfo::capitalized_name
std::string capitalized_name
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:166
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateInterfaceMembers
virtual void GenerateInterfaceMembers(io::Printer *printer) const =0
google::protobuf::compiler::java::FieldGeneratorMap::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap)
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16
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::ImmutableFieldLiteGenerator::GenerateKotlinDslMembers
virtual void GenerateKotlinDslMembers(io::Printer *printer) const =0
google::protobuf::compiler::java::FieldGeneratorMap::~FieldGeneratorMap
~FieldGeneratorMap()
google::protobuf::compiler::java::FieldGeneratorInfo::disambiguated_reason
std::string disambiguated_reason
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h:160


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