Initial import of v2.0.0beta
[protobuf.git] / src / google / protobuf / compiler / java / java_helpers.h
blob743763302243d718e11040818f681a59a1239af8
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.
3 // http://code.google.com/p/protobuf/
4 //
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
8 //
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__
24 #include <string>
25 #include <google/protobuf/descriptor.h>
27 namespace google {
28 namespace protobuf {
29 namespace compiler {
30 namespace java {
32 // Commonly-used separator comments. Thick is a line of '=', thin is a line
33 // of '-'.
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
58 // file.
59 string ToJavaName(const string& full_name, const FileDescriptor* file);
61 // These return the fully-qualified class name corresponding to the given
62 // descriptor.
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);
74 enum JavaType {
75 JAVATYPE_INT,
76 JAVATYPE_LONG,
77 JAVATYPE_FLOAT,
78 JAVATYPE_DOUBLE,
79 JAVATYPE_BOOLEAN,
80 JAVATYPE_STRING,
81 JAVATYPE_BYTES,
82 JAVATYPE_ENUM,
83 JAVATYPE_MESSAGE
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
94 // types.
95 const char* BoxedPrimitiveTypeName(JavaType type);
97 } // namespace java
98 } // namespace compiler
99 } // namespace protobuf
101 } // namespace google
102 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__