temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 2 | // Copyright 2008 Google Inc. All rights reserved. |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 3 | // https://developers.google.com/protocol-buffers/ |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 4 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 8 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 18 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 30 | |
| 31 | // Author: kenton@google.com (Kenton Varda) |
| 32 | // Based on original Protocol Buffers design by |
| 33 | // Sanjay Ghemawat, Jeff Dean, and others. |
| 34 | |
| 35 | #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ |
| 36 | #define GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ |
| 37 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 38 | #include <memory> |
Feng Xiao | 6ef984a | 2014-11-10 17:34:54 -0800 | [diff] [blame] | 39 | #ifndef _SHARED_PTR_H |
| 40 | #include <google/protobuf/stubs/shared_ptr.h> |
| 41 | #endif |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 42 | #include <string> |
| 43 | #include <vector> |
| 44 | #include <google/protobuf/stubs/common.h> |
| 45 | |
| 46 | namespace google { |
| 47 | namespace protobuf { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 48 | class FileDescriptor; // descriptor.h |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 49 | namespace io { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 50 | class Printer; // printer.h |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 51 | } |
| 52 | namespace compiler { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 53 | class GeneratorContext; // code_generator.h |
| 54 | namespace java { |
| 55 | class Context; // context.h |
| 56 | class MessageGenerator; // message.h |
| 57 | class GeneratorFactory; // generator_factory.h |
| 58 | class ExtensionGenerator; // extension.h |
| 59 | class ClassNameResolver; // name_resolver.h |
| 60 | } |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | namespace protobuf { |
| 65 | namespace compiler { |
| 66 | namespace java { |
| 67 | |
| 68 | class FileGenerator { |
| 69 | public: |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 70 | FileGenerator(const FileDescriptor* file, bool immutable_api = true); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 71 | ~FileGenerator(); |
| 72 | |
| 73 | // Checks for problems that would otherwise lead to cryptic compile errors. |
| 74 | // Returns true if there are no problems, or writes an error description to |
| 75 | // the given string and returns false otherwise. |
| 76 | bool Validate(string* error); |
| 77 | |
| 78 | void Generate(io::Printer* printer); |
| 79 | |
| 80 | // If we aren't putting everything into one file, this will write all the |
| 81 | // files other than the outer file (i.e. one for each message, enum, and |
| 82 | // service type). |
| 83 | void GenerateSiblings(const string& package_dir, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 84 | GeneratorContext* generator_context, |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 85 | vector<string>* file_list); |
| 86 | |
| 87 | const string& java_package() { return java_package_; } |
| 88 | const string& classname() { return classname_; } |
| 89 | |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 90 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 91 | private: |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 92 | void GenerateDescriptorInitializationCodeForImmutable(io::Printer* printer); |
| 93 | void GenerateDescriptorInitializationCodeForMutable(io::Printer* printer); |
| 94 | |
| 95 | bool ShouldIncludeDependency(const FileDescriptor* descriptor, |
| 96 | bool immutable_api_); |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 97 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 98 | const FileDescriptor* file_; |
| 99 | string java_package_; |
| 100 | string classname_; |
| 101 | |
Feng Xiao | f157a56 | 2014-11-14 11:50:31 -0800 | [diff] [blame] | 102 | google::protobuf::scoped_array<google::protobuf::scoped_ptr<MessageGenerator> > message_generators_; |
| 103 | google::protobuf::scoped_array<google::protobuf::scoped_ptr<ExtensionGenerator> > extension_generators_; |
| 104 | google::protobuf::scoped_ptr<GeneratorFactory> generator_factory_; |
| 105 | google::protobuf::scoped_ptr<Context> context_; |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 106 | ClassNameResolver* name_resolver_; |
| 107 | bool immutable_api_; |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 108 | |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 109 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 110 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); |
| 111 | }; |
| 112 | |
| 113 | } // namespace java |
| 114 | } // namespace compiler |
| 115 | } // namespace protobuf |
| 116 | |
| 117 | } // namespace google |
| 118 | #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FILE_H__ |