1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.
3 // http://code.google.com/p/protobuf/
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // Author: kenton@google.com (Kenton Varda)
18 // Based on original Protocol Buffers design by
19 // Sanjay Ghemawat, Jeff Dean, and others.
21 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__
22 #define GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__
25 #include <google/protobuf/descriptor.h>
32 // Commonly-used separator comments. Thick is a line of '=', thin is a line
34 extern const char kThickSeparator
[];
35 extern const char kThinSeparator
[];
37 // Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes
38 // "fooBarBaz" or "FooBarBaz", respectively.
39 string
UnderscoresToCamelCase(const FieldDescriptor
* field
);
40 string
UnderscoresToCapitalizedCamelCase(const FieldDescriptor
* field
);
42 // Similar, but for method names. (Typically, this merely has the effect
43 // of lower-casing the first letter of the name.)
44 string
UnderscoresToCamelCase(const MethodDescriptor
* method
);
46 // Strips ".proto" or ".protodevel" from the end of a filename.
47 string
StripProto(const string
& filename
);
49 // Gets the unqualified class name for the file. Each .proto file becomes a
50 // single Java class, with all its contents nested in that class.
51 string
FileClassName(const FileDescriptor
* file
);
53 // Returns the file's Java package name.
54 string
FileJavaPackage(const FileDescriptor
* file
);
56 // Converts the given fully-qualified name in the proto namespace to its
57 // fully-qualified name in the Java namespace, given that it is in the given
59 string
ToJavaName(const string
& full_name
, const FileDescriptor
* file
);
61 // These return the fully-qualified class name corresponding to the given
63 inline string
ClassName(const Descriptor
* descriptor
) {
64 return ToJavaName(descriptor
->full_name(), descriptor
->file());
66 inline string
ClassName(const EnumDescriptor
* descriptor
) {
67 return ToJavaName(descriptor
->full_name(), descriptor
->file());
69 inline string
ClassName(const ServiceDescriptor
* descriptor
) {
70 return ToJavaName(descriptor
->full_name(), descriptor
->file());
72 string
ClassName(const FileDescriptor
* descriptor
);
86 JavaType
GetJavaType(FieldDescriptor::Type field_type
);
88 inline JavaType
GetJavaType(const FieldDescriptor
* field
) {
89 return GetJavaType(field
->type());
92 // Get the fully-qualified class name for a boxed primitive type, e.g.
93 // "java.lang.Integer" for JAVATYPE_INT. Returns NULL for enum and message
95 const char* BoxedPrimitiveTypeName(JavaType type
);
98 } // namespace compiler
99 } // namespace protobuf
101 } // namespace google
102 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__