• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GOOGLE_PROTOBUF_COMPILER_KOTLIN_MESSAGE_H__
9 #define GOOGLE_PROTOBUF_COMPILER_KOTLIN_MESSAGE_H__
10 
11 #include "absl/container/btree_map.h"
12 #include "google/protobuf/compiler/java/context.h"
13 #include "google/protobuf/compiler/java/generator_common.h"
14 #include "google/protobuf/compiler/java/full/field_generator.h"
15 #include "google/protobuf/compiler/java/lite/field_generator.h"
16 #include "google/protobuf/compiler/java/name_resolver.h"
17 #include "google/protobuf/descriptor.h"
18 
19 namespace google {
20 namespace protobuf {
21 namespace compiler {
22 namespace kotlin {
23 
24 class MessageGenerator {
25  public:
26   MessageGenerator(const Descriptor* descriptor, java::Context* context);
27   MessageGenerator(const MessageGenerator&) = delete;
28   MessageGenerator& operator=(const MessageGenerator&) = delete;
29   virtual ~MessageGenerator() = default;
30 
31   void Generate(io::Printer* printer) const;
32   void GenerateMembers(io::Printer* printer) const;
33   void GenerateTopLevelMembers(io::Printer* printer) const;
34 
35  private:
36   java::Context* context_;
37   java::ClassNameResolver* name_resolver_;
38   const Descriptor* descriptor_;
39   absl::btree_map<int, const OneofDescriptor*> oneofs_;
40   bool lite_;
41   bool jvm_dsl_;
42 
43   // TODO: b/366047913 - These can be simplified once lite and full field
44   // generators are unified.
45   java::FieldGeneratorMap<java::ImmutableFieldLiteGenerator>
46       lite_field_generators_;
47   java::FieldGeneratorMap<java::ImmutableFieldGenerator> field_generators_;
48 
49   void GenerateExtensions(io::Printer* printer) const;
50   void GenerateOrNull(io::Printer* printer) const;
51   void GenerateFieldMembers(io::Printer* printer) const;
52 };
53 }  // namespace kotlin
54 }  // namespace compiler
55 }  // namespace protobuf
56 }  // namespace google
57 
58 #endif  // GOOGLE_PROTOBUF_COMPILER_KOTLIN_MESSAGE_H__
59