File indexing completed on 2025-01-31 10:11:58
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__
0009 #define GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__
0010
0011 #include <memory>
0012 #include <vector>
0013
0014 #include "absl/container/flat_hash_map.h"
0015 #include "google/protobuf/compiler/java/helpers.h"
0016 #include "google/protobuf/compiler/java/options.h"
0017 #include "google/protobuf/port.h"
0018
0019 namespace google {
0020 namespace protobuf {
0021 class FileDescriptor;
0022 class FieldDescriptor;
0023 class OneofDescriptor;
0024 class Descriptor;
0025 class EnumDescriptor;
0026 namespace compiler {
0027 namespace java {
0028 class ClassNameResolver;
0029 }
0030 }
0031 }
0032 }
0033
0034 namespace google {
0035 namespace protobuf {
0036 namespace compiler {
0037 namespace java {
0038
0039 struct FieldGeneratorInfo;
0040 struct OneofGeneratorInfo;
0041
0042
0043 class Context {
0044 public:
0045 Context(const FileDescriptor* file, const Options& options);
0046 Context(const Context&) = delete;
0047 Context& operator=(const Context&) = delete;
0048 ~Context();
0049
0050
0051
0052 ClassNameResolver* GetNameResolver() const;
0053
0054
0055 const FieldGeneratorInfo* GetFieldGeneratorInfo(
0056 const FieldDescriptor* field) const;
0057
0058
0059 const OneofGeneratorInfo* GetOneofGeneratorInfo(
0060 const OneofDescriptor* oneof) const;
0061
0062 const Options& options() const { return options_; }
0063
0064
0065
0066
0067 bool EnforceLite() const { return options_.enforce_lite; }
0068
0069
0070
0071 bool HasGeneratedMethods(const Descriptor* descriptor) const;
0072
0073 private:
0074 void InitializeFieldGeneratorInfo(const FileDescriptor* file);
0075 void InitializeFieldGeneratorInfoForMessage(const Descriptor* message);
0076 void InitializeFieldGeneratorInfoForFields(
0077 const std::vector<const FieldDescriptor*>& fields);
0078
0079 std::unique_ptr<ClassNameResolver> name_resolver_;
0080 absl::flat_hash_map<const FieldDescriptor*, FieldGeneratorInfo>
0081 field_generator_info_map_;
0082 absl::flat_hash_map<const OneofDescriptor*, OneofGeneratorInfo>
0083 oneof_generator_info_map_;
0084 Options options_;
0085 };
0086
0087 template <typename Descriptor>
0088 void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer,
0089 Descriptor* descriptor, bool immutable,
0090 const std::string& suffix = "") {
0091 if (IsOwnFile(descriptor, immutable)) {
0092 PrintGeneratedAnnotation(printer, '$',
0093 context->options().annotate_code
0094 ? AnnotationFileName(descriptor, suffix)
0095 : "",
0096 context->options());
0097 }
0098 }
0099
0100
0101 }
0102 }
0103 }
0104 }
0105
0106 #endif