• 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 // Author: xiaofeng@google.com (Feng Xiao)
9 //
10 // Generators that generate shared code between immutable API and mutable API.
11 
12 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__
13 #define GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__
14 
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 #include "google/protobuf/compiler/java/options.h"
20 #include "google/protobuf/port.h"
21 
22 namespace google {
23 namespace protobuf {
24 class FileDescriptor;  // descriptor.h
25 namespace compiler {
26 class GeneratorContext;  // code_generator.h
27 namespace java {
28 class ClassNameResolver;  // name_resolver.h
29 }
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 // A generator that generates code that are shared between immutable API
43 // and mutable API. Currently only descriptors are shared.
44 class SharedCodeGenerator {
45  public:
46   SharedCodeGenerator(const FileDescriptor* file, const Options& options);
47   SharedCodeGenerator(const SharedCodeGenerator&) = delete;
48   SharedCodeGenerator& operator=(const SharedCodeGenerator&) = delete;
49   ~SharedCodeGenerator();
50 
51   void Generate(GeneratorContext* generator_context,
52                 std::vector<std::string>* file_list,
53                 std::vector<std::string>* annotation_file_list);
54 
55   void GenerateDescriptors(io::Printer* printer);
56 
57  private:
58   std::unique_ptr<ClassNameResolver> name_resolver_;
59   const FileDescriptor* file_;
60   const Options options_;
61 };
62 
63 }  // namespace java
64 }  // namespace compiler
65 }  // namespace protobuf
66 }  // namespace google
67 
68 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_SHARED_CODE_GENERATOR_H__
69