• 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 Java class.
14 
15 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__
16 #define GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__
17 
18 #include <string>
19 
20 #include "absl/strings/string_view.h"
21 #include "google/protobuf/compiler/java/options.h"
22 #include "google/protobuf/descriptor.h"
23 
24 // Must be last.
25 #include "google/protobuf/port_def.inc"
26 
27 namespace google {
28 namespace protobuf {
29 
30 class Descriptor;
31 class EnumDescriptor;
32 class FileDescriptor;
33 class FieldDescriptor;
34 class ServiceDescriptor;
35 
36 namespace compiler {
37 namespace java {
38 
39 // Requires:
40 //   descriptor != NULL
41 //
42 // Returns:
43 //   The fully-qualified Java class name.
44 std::string ClassName(const Descriptor* descriptor);
45 
46 // Requires:
47 //   descriptor != NULL
48 //
49 // Returns:
50 //   The fully-qualified Java class name.
51 std::string ClassName(const EnumDescriptor* descriptor);
52 
53 // Requires:
54 //   descriptor != NULL
55 //
56 // Returns:
57 //   The fully-qualified Java class name.
58 std::string ClassName(const FileDescriptor* descriptor);
59 
60 // Requires:
61 //   descriptor != NULL
62 //
63 // Returns:
64 //   The fully-qualified Java class name.
65 std::string ClassName(const ServiceDescriptor* descriptor);
66 
67 // Requires:
68 //   descriptor != NULL
69 //
70 // Returns:
71 //   Java package name.
72 std::string FileJavaPackage(const FileDescriptor* descriptor,
73                             Options options = {});
74 
75 // Requires:
76 //   descriptor != NULL
77 //
78 // Returns:
79 //   Java package directory.
80 std::string JavaPackageDirectory(const FileDescriptor* file);
81 
82 // Requires:
83 //   descriptor != NULL
84 //
85 // Returns:
86 //   The unqualified Java class name.
87 std::string FileClassName(const FileDescriptor* file);
88 
89 // Requires:
90 //   descriptor != NULL
91 // Returns:
92 //   Capitalized camel case field name.
93 std::string CapitalizedFieldName(const FieldDescriptor* field);
94 
95 // Requires:
96 //   descriptor != NULL
97 // Returns:
98 //   Capitalized camel case oneof name.
99 std::string CapitalizedOneofName(const OneofDescriptor* oneof);
100 
101 // Returns:
102 //   Converts a name to camel-case. If cap_first_letter is true, capitalize the
103 //   first letter.
104 std::string UnderscoresToCamelCase(absl::string_view input,
105                                    bool cap_next_letter);
106 // Requires:
107 //   field != NULL
108 // Returns:
109 //   Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes
110 //   "fooBarBaz" or "FooBarBaz", respectively.
111 std::string UnderscoresToCamelCase(const FieldDescriptor* field);
112 
113 // Requires:
114 //   method != NULL
115 // Returns:
116 //   Similar, but for method names.  (Typically, this merely has the effect
117 //   of lower-casing the first letter of the name.)
118 std::string UnderscoresToCamelCase(const MethodDescriptor* method);
119 
120 // Requires:
121 //   field != NULL
122 // Returns:
123 //   Same as UnderscoresToCamelCase, but checks for reserved keywords
124 std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field);
125 
126 
127 }  // namespace java
128 }  // namespace compiler
129 }  // namespace protobuf
130 }  // namespace google
131 
132 #include "google/protobuf/port_undef.inc"
133 #endif  // GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__
134