• 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 // Generates Kotlin code for a given .proto file.
9 
10 #ifndef GOOGLE_PROTOBUF_COMPILER_KOTLIN_FILE_H__
11 #define GOOGLE_PROTOBUF_COMPILER_KOTLIN_FILE_H__
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "google/protobuf/compiler/java/options.h"
18 #include "google/protobuf/compiler/kotlin/message.h"
19 
20 namespace google {
21 namespace protobuf {
22 class FileDescriptor;  // descriptor.h
23 namespace io {
24 class Printer;  // printer.h
25 }
26 namespace compiler {
27 class GeneratorContext;  // code_generator.h
28 namespace java {
29 class Context;             // context.h
30 class MessageGenerator;    // message.h
31 class GeneratorFactory;    // generator_factory.h
32 class ExtensionGenerator;  // extension.h
33 class ClassNameResolver;   // name_resolver.h
34 }  // namespace java
35 }  // namespace compiler
36 }  // namespace protobuf
37 }  // namespace google
38 
39 namespace google {
40 namespace protobuf {
41 namespace compiler {
42 namespace kotlin {
43 
44 // TODO: b/366047913 - Move away from these generator classes and more towards
45 // the "Context" model that the Kotlin Native & Rust code generators use:
46 // http://google3/third_party/kotlin/protobuf/generator/native/file.cc;l=149-170;rcl=642292300
47 class FileGenerator {
48  public:
49   FileGenerator(const FileDescriptor* file, const java::Options& options);
50   FileGenerator(const FileGenerator&) = delete;
51   FileGenerator& operator=(const FileGenerator&) = delete;
52   ~FileGenerator() = default;
53 
54   std::string GetKotlinClassname();
55   void Generate(io::Printer* printer);
56   void GenerateSiblings(const std::string& package_dir,
57                         GeneratorContext* generator_context,
58                         std::vector<std::string>* file_list,
59                         std::vector<std::string>* annotation_list);
60 
java_package()61   const std::string& java_package() { return java_package_; }
62 
63  private:
64   const FileDescriptor* file_;
65   std::string java_package_;
66 
67   std::vector<std::unique_ptr<MessageGenerator>> message_generators_;
68   std::unique_ptr<java::Context> context_;
69   java::ClassNameResolver* name_resolver_;
70   const java::Options options_;
71 };
72 
73 }  // namespace kotlin
74 }  // namespace compiler
75 }  // namespace protobuf
76 }  // namespace google
77 
78 #endif  // GOOGLE_PROTOBUF_COMPILER_KOTLIN_FILE_H__
79