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