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 <map>
39 #include <memory>
40 #include <string>
41 
45 
46 namespace google {
47 namespace protobuf {
48 namespace compiler {
49 namespace java {
50 class Context; // context.h
51 class ClassNameResolver; // name_resolver.h
52 } // namespace java
53 } // namespace compiler
54 namespace io {
55 class Printer; // printer.h
56 }
57 } // namespace protobuf
58 } // namespace google
59 
60 namespace google {
61 namespace protobuf {
62 namespace compiler {
63 namespace java {
64 
66  public:
68  virtual ~ImmutableFieldGenerator();
69 
70  virtual int GetNumBitsForMessage() const = 0;
71  virtual int GetNumBitsForBuilder() const = 0;
72  virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
73  virtual void GenerateMembers(io::Printer* printer) const = 0;
74  virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
75  virtual void GenerateInitializationCode(io::Printer* printer) const = 0;
76  virtual void GenerateBuilderClearCode(io::Printer* printer) const = 0;
77  virtual void GenerateMergingCode(io::Printer* printer) const = 0;
78  virtual void GenerateBuildingCode(io::Printer* printer) const = 0;
79  virtual void GenerateParsingCode(io::Printer* printer) const = 0;
80  virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const;
81  virtual void GenerateParsingDoneCode(io::Printer* printer) const = 0;
82  virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
83  virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
85  io::Printer* printer) const = 0;
86 
87  virtual void GenerateEqualsCode(io::Printer* printer) const = 0;
88  virtual void GenerateHashCode(io::Printer* printer) const = 0;
89 
90  virtual std::string GetBoxedType() const = 0;
91 
92  private:
94 };
95 
97  public:
100 
101  virtual int GetNumBitsForMessage() const = 0;
102  virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
103  virtual void GenerateMembers(io::Printer* printer) const = 0;
104  virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
105  virtual void GenerateInitializationCode(io::Printer* printer) const = 0;
106  virtual void GenerateFieldInfo(io::Printer* printer,
107  std::vector<uint16>* output) const = 0;
108 
109  virtual std::string GetBoxedType() const = 0;
110 
111  private:
113 };
114 
115 
116 // Convenience class which constructs FieldGenerators for a Descriptor.
117 template <typename FieldGeneratorType>
119  public:
120  explicit FieldGeneratorMap(const Descriptor* descriptor, Context* context);
122 
123  const FieldGeneratorType& get(const FieldDescriptor* field) const;
124 
125  private:
127  std::vector<std::unique_ptr<FieldGeneratorType>> field_generators_;
128 
130 };
131 
132 template <typename FieldGeneratorType>
133 inline const FieldGeneratorType& FieldGeneratorMap<FieldGeneratorType>::get(
134  const FieldDescriptor* field) const {
135  GOOGLE_CHECK_EQ(field->containing_type(), descriptor_);
136  return *field_generators_[field->index()];
137 }
138 
139 // Instantiate template for mutable and immutable maps.
140 template <>
142  const Descriptor* descriptor, Context* context);
143 
144 template <>
146 
147 
148 template <>
150  const Descriptor* descriptor, Context* context);
151 
152 template <>
154 
155 
156 // Field information used in FieldGeneartors.
161 };
162 
163 // Oneof information used in OneofFieldGenerators.
167 };
168 
169 // Set some common variables used in variable FieldGenerators.
171  const FieldGeneratorInfo* info,
172  std::map<std::string, std::string>* variables);
173 
174 // Set some common oneof variables used in OneofFieldGenerators.
176  const OneofGeneratorInfo* info,
177  std::map<std::string, std::string>* variables);
178 
179 // Print useful comments before a field's accessors.
180 void PrintExtraFieldInfo(const std::map<std::string, std::string>& variables,
181  io::Printer* printer);
182 
183 } // namespace java
184 } // namespace compiler
185 } // namespace protobuf
186 } // namespace google
187 
188 #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_CHECK_EQ
#define GOOGLE_CHECK_EQ(A, B)
Definition: logging.h:156
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateHashCode
virtual void GenerateHashCode(io::Printer *printer) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateFieldBuilderInitializationCode
virtual void GenerateFieldBuilderInitializationCode(io::Printer *printer) const =0
google::protobuf::FieldDescriptor
Definition: 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::FieldGeneratorMap
Definition: java_field.h:118
google::protobuf::compiler::java::ImmutableFieldGenerator::ImmutableFieldGenerator
ImmutableFieldGenerator()
Definition: java_field.h:67
google::protobuf::compiler::java::FieldGeneratorMap::FieldGeneratorMap
FieldGeneratorMap(const Descriptor *descriptor, Context *context)
google::protobuf::compiler::java::Context
Definition: java_context.h:65
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
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::compiler::java::FieldGeneratorInfo::name
std::string name
Definition: 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: java_field.cc:263
google::protobuf::compiler::java::FieldGeneratorInfo
Definition: java_field.h:157
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GenerateFieldInfo
virtual void GenerateFieldInfo(io::Printer *printer, std::vector< uint16 > *output) const =0
google::protobuf::compiler::java::ImmutableFieldGenerator
Definition: java_field.h:65
google::protobuf::compiler::java::FieldGeneratorMap::get
const FieldGeneratorType & get(const FieldDescriptor *field) const
Definition: java_field.h:133
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::~ImmutableFieldLiteGenerator
virtual ~ImmutableFieldLiteGenerator()
Definition: java_field.cc:202
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldLiteGenerator)
google::protobuf::compiler::java::FieldGeneratorMap::field_generators_
std::vector< std::unique_ptr< FieldGeneratorType > > field_generators_
Definition: java_field.h:127
google::protobuf::compiler::java::OneofGeneratorInfo
Definition: java_field.h:164
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::GetNumBitsForMessage
virtual int GetNumBitsForMessage() const =0
google::protobuf::compiler::java::FieldGeneratorMap::descriptor_
const Descriptor * descriptor_
Definition: java_field.h:126
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::ImmutableFieldGenerator::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator)
google::protobuf::compiler::java::ImmutableFieldLiteGenerator::ImmutableFieldLiteGenerator
ImmutableFieldLiteGenerator()
Definition: java_field.h:98
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
google::protobuf::compiler::java::OneofGeneratorInfo::name
std::string name
Definition: 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: printer.h:181
google::protobuf::compiler::java::FieldGeneratorInfo::capitalized_name
std::string capitalized_name
Definition: java_field.h:159
google::protobuf::compiler::java::ImmutableFieldGenerator::~ImmutableFieldGenerator
virtual ~ImmutableFieldGenerator()
Definition: java_field.cc:195
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
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
common.h
google::protobuf::compiler::java::ImmutableFieldGenerator::GetBoxedType
virtual std::string GetBoxedType() const =0
google::protobuf::compiler::java::ImmutableFieldLiteGenerator
Definition: 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
logging.h
google::protobuf::compiler::java::ImmutableFieldGenerator::GetNumBitsForMessage
virtual int GetNumBitsForMessage() const =0
google::protobuf::Descriptor
Definition: src/google/protobuf/descriptor.h:231
descriptor.h
google::protobuf::compiler::java::ImmutableFieldGenerator::GenerateParsingCodeFromPacked
virtual void GenerateParsingCodeFromPacked(io::Printer *printer) const
Definition: java_field.cc:197
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
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
google::protobuf::compiler::java::OneofGeneratorInfo::capitalized_name
std::string capitalized_name
Definition: java_field.h:166
descriptor_
const Descriptor * descriptor_
Definition: field_comparator_test.cc:56
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
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)
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11
google::protobuf::compiler::java::FieldGeneratorMap::~FieldGeneratorMap
~FieldGeneratorMap()
google::protobuf::compiler::java::FieldGeneratorInfo::disambiguated_reason
std::string disambiguated_reason
Definition: java_field.h:160


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