• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 // Author: kenton@google.com (Kenton Varda)
9 //  Based on original Protocol Buffers design by
10 //  Sanjay Ghemawat, Jeff Dean, and others.
11 //
12 // Provides a mechanism for mapping a descriptor to the
13 // fully-qualified name of the corresponding C# class.
14 
15 #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__
16 #define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__
17 
18 #include <string>
19 
20 #include "absl/strings/string_view.h"
21 #include "google/protobuf/port_def.inc"
22 
23 namespace google {
24 namespace protobuf {
25 
26 class Descriptor;
27 class EnumDescriptor;
28 class FileDescriptor;
29 class ServiceDescriptor;
30 
31 namespace compiler {
32 namespace csharp {
33 
34 // Requires:
35 //   descriptor != NULL
36 //
37 // Returns:
38 //   The namespace to use for given file descriptor.
39 std::string PROTOC_EXPORT GetFileNamespace(const FileDescriptor* descriptor);
40 
41 // Requires:
42 //   descriptor != NULL
43 //
44 // Returns:
45 //   The fully-qualified C# class name.
46 std::string PROTOC_EXPORT GetClassName(const Descriptor* descriptor);
47 
48 // Requires:
49 //   descriptor != NULL
50 //
51 // Returns:
52 //   The fully-qualified C# enum class name.
53 std::string GetClassName(const EnumDescriptor* descriptor);
54 
55 // Requires:
56 //   descriptor != NULL
57 //
58 // Returns:
59 //   The unqualified name of the C# class that provides access to the file
60 //   descriptor. Proto compiler generates
61 //   such class for each .proto file processed.
62 std::string GetReflectionClassUnqualifiedName(const FileDescriptor* descriptor);
63 
64 // Gets unqualified name of the extension class
65 // Requires:
66 //   descriptor != NULL
67 //
68 // Returns:
69 //   The unqualified name of the generated C# extensions class that provide
70 //   access to extensions. Proto compiler generates such class for each
71 //   .proto file processed that contains extensions.
72 std::string GetExtensionClassUnqualifiedName(const FileDescriptor* descriptor);
73 
74 // Requires:
75 //   descriptor != NULL
76 //
77 // Returns:
78 //   The fully-qualified name of the C# class that provides access to the file
79 //   descriptor. Proto compiler generates such class for each .proto file
80 //   processed.
81 std::string PROTOC_EXPORT
82 GetReflectionClassName(const FileDescriptor* descriptor);
83 
84 // Generates output file name for given file descriptor. If generate_directories
85 // is true, the output file will be put under directory corresponding to file's
86 // namespace. base_namespace can be used to strip some of the top level
87 // directories. E.g. for file with namespace "Bar.Foo" and base_namespace="Bar",
88 // the resulting file will be put under directory "Foo" (and not "Bar/Foo").
89 //
90 // Requires:
91 //   descriptor != NULL
92 //   error != NULL
93 //
94 //  Returns:
95 //    The file name to use as output file for given file descriptor. In case
96 //    of failure, this function will return empty string and error parameter
97 //    will contain the error message.
98 std::string PROTOC_EXPORT GetOutputFile(const FileDescriptor* descriptor,
99                                         absl::string_view file_extension,
100                                         bool generate_directories,
101                                         absl::string_view base_namespace,
102                                         std::string* error);
103 
104 std::string UnderscoresToPascalCase(absl::string_view input);
105 
106 // Note that we wouldn't normally want to export this (we're not expecting
107 // it to be used outside libprotoc itself) but this exposes it for testing.
108 std::string PROTOC_EXPORT UnderscoresToCamelCase(absl::string_view input,
109                                                  bool cap_next_letter,
110                                                  bool preserve_period);
111 
UnderscoresToCamelCase(absl::string_view input,bool cap_next_letter)112 inline std::string UnderscoresToCamelCase(absl::string_view input,
113                                           bool cap_next_letter) {
114   return UnderscoresToCamelCase(input, cap_next_letter, false);
115 }
116 
117 }  // namespace csharp
118 }  // namespace compiler
119 }  // namespace protobuf
120 }  // namespace google
121 
122 #include "google/protobuf/port_undef.inc"
123 
124 #endif  // GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__
125