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 #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;  // name_resolver.h
0029 }
0030 }  // namespace compiler
0031 }  // namespace protobuf
0032 }  // namespace google
0033 
0034 namespace google {
0035 namespace protobuf {
0036 namespace compiler {
0037 namespace java {
0038 
0039 struct FieldGeneratorInfo;
0040 struct OneofGeneratorInfo;
0041 // A context object holds the information that is shared among all code
0042 // generators.
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   // Get the name resolver associated with this context. The resolver
0051   // can be used to map descriptors to Java class names.
0052   ClassNameResolver* GetNameResolver() const;
0053 
0054   // Get the FieldGeneratorInfo for a given field.
0055   const FieldGeneratorInfo* GetFieldGeneratorInfo(
0056       const FieldDescriptor* field) const;
0057 
0058   // Get the OneofGeneratorInfo for a given oneof.
0059   const OneofGeneratorInfo* GetOneofGeneratorInfo(
0060       const OneofDescriptor* oneof) const;
0061 
0062   const Options& options() const { return options_; }
0063 
0064   // Enforces all the files (including transitive dependencies) to use
0065   // LiteRuntime.
0066 
0067   bool EnforceLite() const { return options_.enforce_lite; }
0068 
0069   // Does this message class have generated parsing, serialization, and other
0070   // standard methods for which reflection-based fallback implementations exist?
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 }  // namespace java
0102 }  // namespace compiler
0103 }  // namespace protobuf
0104 }  // namespace google
0105 
0106 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__