webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
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 // Used to get the Java class related names for a given descriptor. It caches
51 // the results to avoid redundant calculation across multiple name queries.
52 // Thread-safety note: This class is *not* thread-safe.
54  public:
57 
58  // Gets the unqualified outer class name for the file.
59  string GetFileClassName(const FileDescriptor* file, bool immutable);
60  // Gets the unqualified immutable outer class name of a file.
61  string GetFileImmutableClassName(const FileDescriptor* file);
62  // Gets the unqualified default immutable outer class name of a file
63  // (converted from the proto file's name).
65 
66  // Check whether there is any type defined in the proto file that has
67  // the given class name.
68  bool HasConflictingClassName(const FileDescriptor* file,
69  const string& classname);
70 
71  // Gets the name of the outer class that holds descriptor information.
72  // Descriptors are shared between immutable messages and mutable messages.
73  // Since both of them are generated optionally, the descriptors need to be
74  // put in another common place.
75  string GetDescriptorClassName(const FileDescriptor* file);
76 
77  // Gets the fully-qualified class name corresponding to the given descriptor.
78  string GetClassName(const Descriptor* descriptor, bool immutable);
79  string GetClassName(const EnumDescriptor* descriptor, bool immutable);
80  string GetClassName(const ServiceDescriptor* descriptor, bool immutable);
81  string GetClassName(const FileDescriptor* descriptor, bool immutable);
82 
83  template<class DescriptorType>
84  string GetImmutableClassName(const DescriptorType* descriptor) {
85  return GetClassName(descriptor, true);
86  }
87  template<class DescriptorType>
88  string GetMutableClassName(const DescriptorType* descriptor) {
89  return GetClassName(descriptor, false);
90  }
91 
92  // Gets the fully qualified name of an extension identifier.
93  string GetExtensionIdentifierName(const FieldDescriptor* descriptor,
94  bool immutable);
95 
96  // Gets the fully qualified name for generated classes in Java convention.
97  // Nested classes will be separated using '$' instead of '.'
98  // For example:
99  // com.package.OuterClass$OuterMessage$InnerMessage
100  string GetJavaImmutableClassName(const Descriptor* descriptor);
101  string GetJavaImmutableClassName(const EnumDescriptor* descriptor);
102  private:
103  // Get the full name of a Java class by prepending the Java package name
104  // or outer class name.
105  string GetClassFullName(const string& name_without_package,
106  const FileDescriptor* file,
107  bool immutable,
108  bool multiple_files);
109  // Get the Java Class style full name of a message.
110  string GetJavaClassFullName(
111  const string& name_without_package,
112  const FileDescriptor* file,
113  bool immutable);
114  // Caches the result to provide better performance.
115  map<const FileDescriptor*, string> file_immutable_outer_class_names_;
116 
117  GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver);
118 };
119 
120 } // namespace java
121 } // namespace compiler
122 } // namespace protobuf
123 
124 } // namespace google
125 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__
Definition: upb.c:6604
string GetFileDefaultImmutableClassName(const FileDescriptor *file)
Definition: java_name_resolver.cc:119
Definition: descriptor.h:801
string GetClassName(const Descriptor *descriptor, bool immutable)
Definition: java_name_resolver.cc:210
Definition: descriptor.h:994
const Descriptor * descriptor
Definition: descriptor.cc:271
ClassNameResolver()
Definition: java_name_resolver.cc:113
Definition: descriptor.h:1156
Definition: descriptor.h:172
string GetFileImmutableClassName(const FileDescriptor *file)
Definition: java_name_resolver.cc:131
string GetJavaImmutableClassName(const Descriptor *descriptor)
Definition: java_name_resolver.cc:255
bool HasConflictingClassName(const FileDescriptor *file, const string &classname)
Definition: java_name_resolver.cc:158
Definition: descriptor.h:439
Definition: java_name_resolver.h:53
VoEFile * file
Definition: voe_cmd_test.cc:59
Definition: protobuf.h:85
~ClassNameResolver()
Definition: java_name_resolver.cc:116
string GetFileClassName(const FileDescriptor *file, bool immutable)
Definition: java_name_resolver.cc:147
Definition: __init__.py:1
string GetMutableClassName(const DescriptorType *descriptor)
Definition: java_name_resolver.h:88
Definition: gflags_completions.h:115
string GetDescriptorClassName(const FileDescriptor *file)
Definition: java_name_resolver.cc:178
string GetImmutableClassName(const DescriptorType *descriptor)
Definition: java_name_resolver.h:84
string GetExtensionIdentifierName(const FieldDescriptor *descriptor, bool immutable)
Definition: java_name_resolver.cc:248
Definition: protobuf.h:70
Definition: protobuf.h:95