java_name_resolver.h
Go to the documentation of this file.
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_NAME_RESOLVER_H__
32 #define GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__
33 
34 #include <map>
35 #include <string>
36 
38 
39 namespace google {
40 namespace protobuf {
41 class Descriptor;
42 class EnumDescriptor;
43 class FieldDescriptor;
44 class FileDescriptor;
45 class ServiceDescriptor;
46 
47 namespace compiler {
48 namespace java {
49 
50 // Indicates how closely the two class names match.
52 
53 // Used to get the Java class related names for a given descriptor. It caches
54 // the results to avoid redundant calculation across multiple name queries.
55 // Thread-safety note: This class is *not* thread-safe.
57  public:
60 
61  // Gets the unqualified outer class name for the file.
62  std::string GetFileClassName(const FileDescriptor* file, bool immutable);
63  // Gets the unqualified immutable outer class name of a file.
65  // Gets the unqualified default immutable outer class name of a file
66  // (converted from the proto file's name).
68 
69  // Check whether there is any type defined in the proto file that has
70  // the given class name.
71  bool HasConflictingClassName(const FileDescriptor* file,
72  const std::string& classname,
73  NameEquality equality_mode);
74 
75  // Gets the name of the outer class that holds descriptor information.
76  // Descriptors are shared between immutable messages and mutable messages.
77  // Since both of them are generated optionally, the descriptors need to be
78  // put in another common place.
80 
81  // Gets the fully-qualified class name corresponding to the given descriptor.
82  std::string GetClassName(const Descriptor* descriptor, bool immutable);
83  std::string GetClassName(const EnumDescriptor* descriptor, bool immutable);
84  std::string GetClassName(const ServiceDescriptor* descriptor, bool immutable);
85  std::string GetClassName(const FileDescriptor* descriptor, bool immutable);
86 
87  template <class DescriptorType>
88  std::string GetImmutableClassName(const DescriptorType* descriptor) {
89  return GetClassName(descriptor, true);
90  }
91  template <class DescriptorType>
92  std::string GetMutableClassName(const DescriptorType* descriptor) {
93  return GetClassName(descriptor, false);
94  }
95 
96  // Gets the fully qualified name of an extension identifier.
98  bool immutable);
99 
100  // Gets the fully qualified name for generated classes in Java convention.
101  // Nested classes will be separated using '$' instead of '.'
102  // For example:
103  // com.package.OuterClass$OuterMessage$InnerMessage
106  private:
107  // Get the full name of a Java class by prepending the Java package name
108  // or outer class name.
109  std::string GetClassFullName(const std::string& name_without_package,
110  const FileDescriptor* file, bool immutable,
111  bool multiple_files);
112  // Get the Java Class style full name of a message.
113  std::string GetJavaClassFullName(const std::string& name_without_package,
114  const FileDescriptor* file, bool immutable);
115  // Caches the result to provide better performance.
116  std::map<const FileDescriptor*, std::string>
118 
120 };
121 
122 } // namespace java
123 } // namespace compiler
124 } // namespace protobuf
125 } // namespace google
126 
127 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__
google::protobuf::compiler::java::EXACT_EQUAL
@ EXACT_EQUAL
Definition: java_name_resolver.h:51
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
FileDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:125
google::protobuf::compiler::java::ClassNameResolver::file_immutable_outer_class_names_
std::map< const FileDescriptor *, std::string > file_immutable_outer_class_names_
Definition: java_name_resolver.h:117
google::protobuf::compiler::java::ClassNameResolver::GetExtensionIdentifierName
std::string GetExtensionIdentifierName(const FieldDescriptor *descriptor, bool immutable)
Definition: java_name_resolver.cc:266
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::compiler::java::ClassNameResolver::GetImmutableClassName
std::string GetImmutableClassName(const DescriptorType *descriptor)
Definition: java_name_resolver.h:88
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::compiler::java::ClassNameResolver::GetClassFullName
std::string GetClassFullName(const std::string &name_without_package, const FileDescriptor *file, bool immutable, bool multiple_files)
Definition: java_name_resolver.cc:213
Descriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:113
FieldDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:129
google::protobuf::compiler::java::NameEquality
NameEquality
Definition: java_name_resolver.h:51
google::protobuf::ServiceDescriptor
Definition: src/google/protobuf/descriptor.h:1152
google::protobuf::compiler::java::ClassNameResolver::ClassNameResolver
ClassNameResolver()
Definition: java_name_resolver.cc:130
google::protobuf::compiler::java::ClassNameResolver::GetFileImmutableClassName
std::string GetFileImmutableClassName(const FileDescriptor *file)
Definition: java_name_resolver.cc:146
google::protobuf::compiler::java::ClassNameResolver::~ClassNameResolver
~ClassNameResolver()
Definition: java_name_resolver.cc:132
google::protobuf::compiler::java::ClassNameResolver::GetJavaClassFullName
std::string GetJavaClassFullName(const std::string &name_without_package, const FileDescriptor *file, bool immutable)
Definition: java_name_resolver.cc:251
google::protobuf::compiler::java::ClassNameResolver::GetFileClassName
std::string GetFileClassName(const FileDescriptor *file, bool immutable)
Definition: java_name_resolver.cc:163
EnumDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:137
google::protobuf::compiler::java::ClassNameResolver::GetJavaImmutableClassName
std::string GetJavaImmutableClassName(const Descriptor *descriptor)
Definition: java_name_resolver.cc:272
java
google::protobuf::compiler::java::ClassNameResolver::GetMutableClassName
std::string GetMutableClassName(const DescriptorType *descriptor)
Definition: java_name_resolver.h:92
google::protobuf::compiler::java::ClassNameResolver::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver)
common.h
google::protobuf::compiler::java::NO_MATCH
@ NO_MATCH
Definition: java_name_resolver.h:51
google::protobuf::Descriptor
Definition: src/google/protobuf/descriptor.h:231
google::protobuf::FileDescriptor
Definition: src/google/protobuf/descriptor.h:1320
google::protobuf::compiler::java::EQUAL_IGNORE_CASE
@ EQUAL_IGNORE_CASE
Definition: java_name_resolver.h:51
google::protobuf::compiler::java::ClassNameResolver::GetClassName
std::string GetClassName(const Descriptor *descriptor, bool immutable)
Definition: java_name_resolver.cc:229
google::protobuf::compiler::java::ClassNameResolver::GetDescriptorClassName
std::string GetDescriptorClassName(const FileDescriptor *file)
Definition: java_name_resolver.cc:198
google::protobuf::compiler::java::ClassNameResolver::HasConflictingClassName
bool HasConflictingClassName(const FileDescriptor *file, const std::string &classname, NameEquality equality_mode)
Definition: java_name_resolver.cc:174
google::protobuf::compiler::java::ClassNameResolver
Definition: java_name_resolver.h:56
google::protobuf::compiler::java::ClassNameResolver::GetFileDefaultImmutableClassName
std::string GetFileDefaultImmutableClassName(const FileDescriptor *file)
Definition: java_name_resolver.cc:134
google::protobuf::EnumDescriptor
Definition: src/google/protobuf/descriptor.h:918
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55