Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:11:57

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // Author: kenton@google.com (Kenton Varda)
0009 //  Based on original Protocol Buffers design by
0010 //  Sanjay Ghemawat, Jeff Dean, and others.
0011 
0012 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__
0013 #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__
0014 
0015 #include <string>
0016 
0017 #include "google/protobuf/compiler/java/full/field_generator.h"
0018 #include "google/protobuf/descriptor.h"
0019 #include "google/protobuf/io/printer.h"
0020 
0021 namespace google {
0022 namespace protobuf {
0023 namespace compiler {
0024 namespace java {
0025 class Context;            // context.h
0026 class ClassNameResolver;  // name_resolver.h
0027 }  // namespace java
0028 }  // namespace compiler
0029 }  // namespace protobuf
0030 }  // namespace google
0031 
0032 namespace google {
0033 namespace protobuf {
0034 namespace compiler {
0035 namespace java {
0036 
0037 class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
0038  public:
0039   explicit ImmutableMessageFieldGenerator(const FieldDescriptor* descriptor,
0040                                           int messageBitIndex,
0041                                           int builderBitIndex,
0042                                           Context* context);
0043   ImmutableMessageFieldGenerator(const ImmutableMessageFieldGenerator&) =
0044       delete;
0045   ImmutableMessageFieldGenerator& operator=(
0046       const ImmutableMessageFieldGenerator&) = delete;
0047   ~ImmutableMessageFieldGenerator() override;
0048 
0049   // implements ImmutableFieldGenerator
0050   // ---------------------------------------
0051   int GetMessageBitIndex() const override;
0052   int GetBuilderBitIndex() const override;
0053   int GetNumBitsForMessage() const override;
0054   int GetNumBitsForBuilder() const override;
0055   void GenerateInterfaceMembers(io::Printer* printer) const override;
0056   void GenerateMembers(io::Printer* printer) const override;
0057   void GenerateBuilderMembers(io::Printer* printer) const override;
0058   void GenerateInitializationCode(io::Printer* printer) const override;
0059   void GenerateBuilderClearCode(io::Printer* printer) const override;
0060   void GenerateMergingCode(io::Printer* printer) const override;
0061   void GenerateBuildingCode(io::Printer* printer) const override;
0062   void GenerateBuilderParsingCode(io::Printer* printer) const override;
0063   void GenerateSerializationCode(io::Printer* printer) const override;
0064   void GenerateSerializedSizeCode(io::Printer* printer) const override;
0065   void GenerateFieldBuilderInitializationCode(
0066       io::Printer* printer) const override;
0067   void GenerateEqualsCode(io::Printer* printer) const override;
0068   void GenerateHashCode(io::Printer* printer) const override;
0069   void GenerateKotlinDslMembers(io::Printer* printer) const override;
0070 
0071   std::string GetBoxedType() const override;
0072 
0073  protected:
0074   const FieldDescriptor* descriptor_;
0075   int message_bit_index_;
0076   int builder_bit_index_;
0077   absl::flat_hash_map<absl::string_view, std::string> variables_;
0078   ClassNameResolver* name_resolver_;
0079   Context* context_;
0080 
0081   virtual void PrintNestedBuilderCondition(
0082       io::Printer* printer, const char* regular_case,
0083       const char* nested_builder_case) const;
0084   virtual void PrintNestedBuilderFunction(
0085       io::Printer* printer, const char* method_prototype,
0086       const char* regular_case, const char* nested_builder_case,
0087       const char* trailing_code,
0088       absl::optional<io::AnnotationCollector::Semantic> semantic =
0089           absl::nullopt) const;
0090 
0091  private:
0092   void GenerateKotlinOrNull(io::Printer* printer) const;
0093 };
0094 
0095 class ImmutableMessageOneofFieldGenerator
0096     : public ImmutableMessageFieldGenerator {
0097  public:
0098   ImmutableMessageOneofFieldGenerator(const FieldDescriptor* descriptor,
0099                                       int messageBitIndex, int builderBitIndex,
0100                                       Context* context);
0101   ImmutableMessageOneofFieldGenerator(
0102       const ImmutableMessageOneofFieldGenerator&) = delete;
0103   ImmutableMessageOneofFieldGenerator& operator=(
0104       const ImmutableMessageOneofFieldGenerator&) = delete;
0105   ~ImmutableMessageOneofFieldGenerator() override;
0106 
0107   void GenerateMembers(io::Printer* printer) const override;
0108   void GenerateBuilderMembers(io::Printer* printer) const override;
0109   void GenerateBuilderClearCode(io::Printer* printer) const override;
0110   void GenerateBuildingCode(io::Printer* printer) const override;
0111   void GenerateMergingCode(io::Printer* printer) const override;
0112   void GenerateBuilderParsingCode(io::Printer* printer) const override;
0113   void GenerateSerializationCode(io::Printer* printer) const override;
0114   void GenerateSerializedSizeCode(io::Printer* printer) const override;
0115 };
0116 
0117 class RepeatedImmutableMessageFieldGenerator
0118     : public ImmutableMessageFieldGenerator {
0119  public:
0120   explicit RepeatedImmutableMessageFieldGenerator(
0121       const FieldDescriptor* descriptor, int messageBitIndex,
0122       int builderBitIndex, Context* context);
0123   RepeatedImmutableMessageFieldGenerator(
0124       const RepeatedImmutableMessageFieldGenerator&) = delete;
0125   RepeatedImmutableMessageFieldGenerator& operator=(
0126       const RepeatedImmutableMessageFieldGenerator&) = delete;
0127   ~RepeatedImmutableMessageFieldGenerator() override;
0128 
0129   // implements ImmutableFieldGenerator ---------------------------------------
0130   int GetNumBitsForMessage() const override;
0131   int GetNumBitsForBuilder() const override;
0132   void GenerateInterfaceMembers(io::Printer* printer) const override;
0133   void GenerateMembers(io::Printer* printer) const override;
0134   void GenerateBuilderMembers(io::Printer* printer) const override;
0135   void GenerateInitializationCode(io::Printer* printer) const override;
0136   void GenerateBuilderClearCode(io::Printer* printer) const override;
0137   void GenerateMergingCode(io::Printer* printer) const override;
0138   void GenerateBuildingCode(io::Printer* printer) const override;
0139   void GenerateBuilderParsingCode(io::Printer* printer) const override;
0140   void GenerateSerializationCode(io::Printer* printer) const override;
0141   void GenerateSerializedSizeCode(io::Printer* printer) const override;
0142   void GenerateFieldBuilderInitializationCode(
0143       io::Printer* printer) const override;
0144   void GenerateEqualsCode(io::Printer* printer) const override;
0145   void GenerateHashCode(io::Printer* printer) const override;
0146   void GenerateKotlinDslMembers(io::Printer* printer) const override;
0147 
0148   std::string GetBoxedType() const override;
0149 
0150  protected:
0151   void PrintNestedBuilderCondition(
0152       io::Printer* printer, const char* regular_case,
0153       const char* nested_builder_case) const override;
0154   void PrintNestedBuilderFunction(
0155       io::Printer* printer, const char* method_prototype,
0156       const char* regular_case, const char* nested_builder_case,
0157       const char* trailing_code,
0158       absl::optional<io::AnnotationCollector::Semantic> semantic =
0159           absl::nullopt) const override;
0160 };
0161 
0162 }  // namespace java
0163 }  // namespace compiler
0164 }  // namespace protobuf
0165 }  // namespace google
0166 
0167 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__