1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 // Author: dweis@google.com (Daniel Weis) 9 // Based on original Protocol Buffers design by 10 // Sanjay Ghemawat, Jeff Dean, and others. 11 12 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ 13 #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ 14 15 #include <memory> 16 #include <string> 17 #include <vector> 18 19 #include "absl/container/btree_map.h" 20 #include "google/protobuf/compiler/java/full/field_generator.h" 21 #include "google/protobuf/descriptor.h" 22 23 namespace google { 24 namespace protobuf { 25 namespace compiler { 26 namespace java { 27 class Context; // context.h 28 class ClassNameResolver; // name_resolver.h 29 } // namespace java 30 } // namespace compiler 31 namespace io { 32 class Printer; // printer.h 33 } 34 } // namespace protobuf 35 } // namespace google 36 37 namespace google { 38 namespace protobuf { 39 namespace compiler { 40 namespace java { 41 42 class MessageBuilderGenerator { 43 public: 44 explicit MessageBuilderGenerator(const Descriptor* descriptor, 45 Context* context); 46 MessageBuilderGenerator(const MessageBuilderGenerator&) = delete; 47 MessageBuilderGenerator& operator=(const MessageBuilderGenerator&) = delete; 48 virtual ~MessageBuilderGenerator(); 49 50 virtual void Generate(io::Printer* printer); 51 52 private: 53 void GenerateCommonBuilderMethods(io::Printer* printer); 54 void GenerateBuildPartial(io::Printer* printer); 55 int GenerateBuildPartialPiece(io::Printer* printer, int piece, 56 int first_field); 57 int GenerateBuildPartialPieceWithoutPresence(io::Printer* printer, int piece, 58 int first_field); 59 void GenerateDescriptorMethods(io::Printer* printer); 60 void GenerateBuilderParsingMethods(io::Printer* printer); 61 void GenerateBuilderFieldParsingCases(io::Printer* printer); 62 void GenerateBuilderFieldParsingCase(io::Printer* printer, 63 const FieldDescriptor* field); 64 void GenerateBuilderPackedFieldParsingCase(io::Printer* printer, 65 const FieldDescriptor* field); 66 void GenerateIsInitialized(io::Printer* printer); 67 68 const Descriptor* descriptor_; 69 Context* context_; 70 ClassNameResolver* name_resolver_; 71 FieldGeneratorMap<ImmutableFieldGenerator> field_generators_; 72 absl::btree_map<int, const OneofDescriptor*> oneofs_; 73 }; 74 75 } // namespace java 76 } // namespace compiler 77 } // namespace protobuf 78 } // namespace google 79 80 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ 81