Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:11:58

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // Author: kenton@google.com (Kenton Varda)
0009 //  Based on original Protocol Buffers design by
0010 //  Sanjay Ghemawat, Jeff Dean, and others.
0011 
0012 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__
0013 #define GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__
0014 
0015 #include <memory>
0016 #include <string>
0017 #include <vector>
0018 
0019 #include "google/protobuf/compiler/java/options.h"
0020 #include "google/protobuf/port.h"
0021 
0022 namespace google {
0023 namespace protobuf {
0024 class FileDescriptor;  // descriptor.h
0025 namespace io {
0026 class Printer;  // printer.h
0027 }
0028 namespace compiler {
0029 class GeneratorContext;  // code_generator.h
0030 namespace java {
0031 class Context;             // context.h
0032 class MessageGenerator;    // message.h
0033 class GeneratorFactory;    // generator_factory.h
0034 class ExtensionGenerator;  // extension.h
0035 class ClassNameResolver;   // name_resolver.h
0036 }  // namespace java
0037 }  // namespace compiler
0038 }  // namespace protobuf
0039 }  // namespace google
0040 
0041 namespace google {
0042 namespace protobuf {
0043 namespace compiler {
0044 namespace java {
0045 
0046 class FileGenerator {
0047  public:
0048   FileGenerator(const FileDescriptor* file, const Options& options,
0049                 bool immutable_api = true);
0050   FileGenerator(const FileGenerator&) = delete;
0051   FileGenerator& operator=(const FileGenerator&) = delete;
0052   ~FileGenerator();
0053 
0054   // Checks for problems that would otherwise lead to cryptic compile errors.
0055   // Returns true if there are no problems, or writes an error description to
0056   // the given string and returns false otherwise.
0057   bool Validate(std::string* error);
0058 
0059   void Generate(io::Printer* printer);
0060 
0061   std::string GetKotlinClassname();
0062   void GenerateKotlin(io::Printer* printer);
0063   void GenerateKotlinSiblings(const std::string& package_dir,
0064                               GeneratorContext* generator_context,
0065                               std::vector<std::string>* file_list,
0066                               std::vector<std::string>* annotation_list);
0067 
0068   // If we aren't putting everything into one file, this will write all the
0069   // files other than the outer file (i.e. one for each message, enum, and
0070   // service type).
0071   void GenerateSiblings(const std::string& package_dir,
0072                         GeneratorContext* generator_context,
0073                         std::vector<std::string>* file_list,
0074                         std::vector<std::string>* annotation_list);
0075 
0076   const std::string& java_package() { return java_package_; }
0077   const std::string& classname() { return classname_; }
0078 
0079  private:
0080   void GenerateDescriptorInitializationCodeForImmutable(io::Printer* printer);
0081 
0082   bool ShouldIncludeDependency(const FileDescriptor* descriptor,
0083                                bool immutable_api_);
0084 
0085   const FileDescriptor* file_;
0086   std::string java_package_;
0087   std::string classname_;
0088 
0089   std::vector<std::unique_ptr<MessageGenerator>> message_generators_;
0090   std::vector<std::unique_ptr<ExtensionGenerator>> extension_generators_;
0091   std::unique_ptr<Context> context_;
0092   std::unique_ptr<GeneratorFactory> generator_factory_;
0093   ClassNameResolver* name_resolver_;
0094   const Options options_;
0095   bool immutable_api_;
0096 };
0097 
0098 }  // namespace java
0099 }  // namespace compiler
0100 }  // namespace protobuf
0101 }  // namespace google
0102 
0103 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__