1 | // Protocol Buffers - Google's data interchange format |
2 | // Copyright 2008 Google Inc. All rights reserved. |
3 | // https://developers.google.com/protocol-buffers/ |
4 | // |
5 | // Redistribution and use in source and binary forms, with or without |
6 | // modification, are permitted provided that the following conditions are |
7 | // met: |
8 | // |
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. |
18 | // |
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. |
30 | |
31 | #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ |
32 | #define GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ |
33 | |
34 | #include <map> |
35 | #include <memory> |
36 | #include <vector> |
37 | |
38 | #include <google/protobuf/stubs/common.h> |
39 | #include <google/protobuf/compiler/java/options.h> |
40 | |
41 | namespace google { |
42 | namespace protobuf { |
43 | class FileDescriptor; |
44 | class FieldDescriptor; |
45 | class OneofDescriptor; |
46 | class Descriptor; |
47 | class EnumDescriptor; |
48 | namespace compiler { |
49 | namespace java { |
50 | class ClassNameResolver; // name_resolver.h |
51 | } |
52 | } // namespace compiler |
53 | } // namespace protobuf |
54 | } // namespace google |
55 | |
56 | namespace google { |
57 | namespace protobuf { |
58 | namespace compiler { |
59 | namespace java { |
60 | |
61 | struct FieldGeneratorInfo; |
62 | struct OneofGeneratorInfo; |
63 | // A context object holds the information that is shared among all code |
64 | // generators. |
65 | class Context { |
66 | public: |
67 | Context(const FileDescriptor* file, const Options& options); |
68 | ~Context(); |
69 | |
70 | // Get the name resolver associated with this context. The resolver |
71 | // can be used to map descriptors to Java class names. |
72 | ClassNameResolver* GetNameResolver() const; |
73 | |
74 | // Get the FieldGeneratorInfo for a given field. |
75 | const FieldGeneratorInfo* GetFieldGeneratorInfo( |
76 | const FieldDescriptor* field) const; |
77 | |
78 | // Get the OneofGeneratorInfo for a given oneof. |
79 | const OneofGeneratorInfo* GetOneofGeneratorInfo( |
80 | const OneofDescriptor* oneof) const; |
81 | |
82 | const Options& options() const { return options_; } |
83 | |
84 | // Enforces all the files (including transitive dependencies) to use |
85 | // LiteRuntime. |
86 | |
87 | bool EnforceLite() const { return options_.enforce_lite; } |
88 | |
89 | // Does this message class have generated parsing, serialization, and other |
90 | // standard methods for which reflection-based fallback implementations exist? |
91 | bool HasGeneratedMethods(const Descriptor* descriptor) const; |
92 | |
93 | private: |
94 | void InitializeFieldGeneratorInfo(const FileDescriptor* file); |
95 | void InitializeFieldGeneratorInfoForMessage(const Descriptor* message); |
96 | void InitializeFieldGeneratorInfoForFields( |
97 | const std::vector<const FieldDescriptor*>& fields); |
98 | |
99 | std::unique_ptr<ClassNameResolver> name_resolver_; |
100 | std::map<const FieldDescriptor*, FieldGeneratorInfo> |
101 | field_generator_info_map_; |
102 | std::map<const OneofDescriptor*, OneofGeneratorInfo> |
103 | oneof_generator_info_map_; |
104 | Options options_; |
105 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Context); |
106 | }; |
107 | |
108 | } // namespace java |
109 | } // namespace compiler |
110 | } // namespace protobuf |
111 | } // namespace google |
112 | |
113 | #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ |
114 | |