File indexing completed on 2025-01-31 10:11:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__
0011 #define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__
0012
0013 #include <memory>
0014 #include <string>
0015
0016 #include "absl/container/btree_map.h"
0017 #include "absl/container/flat_hash_map.h"
0018 #include "absl/strings/string_view.h"
0019 #include "google/protobuf/compiler/java/context.h"
0020 #include "google/protobuf/descriptor.h"
0021
0022 namespace google {
0023 namespace protobuf {
0024 namespace compiler {
0025 namespace java {
0026
0027 class MessageGenerator {
0028 public:
0029 explicit MessageGenerator(const Descriptor* descriptor);
0030 MessageGenerator(const MessageGenerator&) = delete;
0031 MessageGenerator& operator=(const MessageGenerator&) = delete;
0032 virtual ~MessageGenerator();
0033
0034
0035
0036
0037 virtual void GenerateStaticVariables(io::Printer* printer,
0038 int* bytecode_estimate) = 0;
0039
0040
0041
0042 virtual int GenerateStaticVariableInitializers(io::Printer* printer) = 0;
0043
0044
0045 virtual void Generate(io::Printer* printer) = 0;
0046
0047
0048
0049 virtual void GenerateInterface(io::Printer* printer) = 0;
0050
0051
0052
0053 virtual void GenerateExtensionRegistrationCode(io::Printer* printer) = 0;
0054 virtual void GenerateKotlinDsl(io::Printer* printer) const = 0;
0055 virtual void GenerateKotlinMembers(io::Printer* printer) const = 0;
0056 virtual void GenerateTopLevelKotlinMembers(io::Printer* printer) const = 0;
0057
0058 protected:
0059 const Descriptor* descriptor_;
0060 absl::btree_map<int, const OneofDescriptor*> oneofs_;
0061 };
0062
0063 class EnumGenerator {
0064 public:
0065 virtual ~EnumGenerator() = default;
0066 virtual void Generate(io::Printer* printer) = 0;
0067 };
0068
0069
0070
0071
0072 class ExtensionGenerator {
0073 public:
0074 virtual ~ExtensionGenerator() = default;
0075
0076 virtual void Generate(io::Printer* printer) = 0;
0077
0078
0079
0080 virtual int GenerateNonNestedInitializationCode(io::Printer* printer) = 0;
0081
0082
0083
0084 virtual int GenerateRegistrationCode(io::Printer* printer) = 0;
0085
0086 protected:
0087 static void InitTemplateVars(
0088 const FieldDescriptor* descriptor, const std::string& scope,
0089 bool immutable, ClassNameResolver* name_resolver,
0090 absl::flat_hash_map<absl::string_view, std::string>* vars_pointer,
0091 Context* context);
0092 };
0093
0094 class ServiceGenerator {
0095 public:
0096 explicit ServiceGenerator(const ServiceDescriptor* descriptor)
0097 : descriptor_(descriptor) {}
0098 virtual ~ServiceGenerator() = default;
0099
0100 ServiceGenerator(const ServiceGenerator&) = delete;
0101 ServiceGenerator& operator=(const ServiceGenerator&) = delete;
0102
0103 virtual void Generate(io::Printer* printer) = 0;
0104
0105 enum RequestOrResponse { REQUEST, RESPONSE };
0106 enum IsAbstract { IS_ABSTRACT, IS_CONCRETE };
0107
0108 protected:
0109 const ServiceDescriptor* descriptor_;
0110 };
0111
0112
0113
0114 class GeneratorFactory {
0115 public:
0116 virtual ~GeneratorFactory() = default;
0117
0118 virtual std::unique_ptr<MessageGenerator> NewMessageGenerator(
0119 const Descriptor* descriptor) const = 0;
0120
0121 virtual std::unique_ptr<EnumGenerator> NewEnumGenerator(
0122 const EnumDescriptor* descriptor) const = 0;
0123
0124 virtual std::unique_ptr<ExtensionGenerator> NewExtensionGenerator(
0125 const FieldDescriptor* descriptor) const = 0;
0126
0127 virtual std::unique_ptr<ServiceGenerator> NewServiceGenerator(
0128 const ServiceDescriptor* descriptor) const = 0;
0129 };
0130
0131 }
0132 }
0133 }
0134 }
0135
0136 #endif