aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/javanano/javanano_helpers.cc
diff options
context:
space:
mode:
authorGravatar Brian Duff <bduff@google.com>2013-06-07 00:12:27 -0700
committerGravatar Brian Duff <bduff@google.com>2013-06-07 14:00:05 -0700
commita220fe61e1aa175917907ec5016ae9ccb151ed31 (patch)
treea694453c79efb3921b5c48ebf7b382670f16f794 /src/google/protobuf/compiler/javanano/javanano_helpers.cc
parent63d4b5fd57159c1e9b54299c803358306fe915f9 (diff)
Fix enum field references with java_multiple_files.
When the java_multiple_files option is on, enums are placed in java class files based on the name of the original enum type. This fixes field references to such enum values to point to the correct class name when setting the default. Change-Id: I51a2e251c0d0ab1e45a182ba849d314232a74bac
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_helpers.cc')
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_helpers.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/src/google/protobuf/compiler/javanano/javanano_helpers.cc
index 78395567..42cb1339 100644
--- a/src/google/protobuf/compiler/javanano/javanano_helpers.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_helpers.cc
@@ -208,7 +208,8 @@ string ClassName(const Params& params, const EnumDescriptor* descriptor) {
const string full_name = descriptor->full_name();
// Remove enum class name as we use int's for enums
- string base_name = full_name.substr(0, full_name.find_last_of('.'));
+ int last_dot_in_name = full_name.find_last_of('.');
+ string base_name = full_name.substr(0, last_dot_in_name);
if (!file->package().empty()) {
if (file->package() == base_name.substr(0, file->package().size())) {
@@ -226,13 +227,22 @@ string ClassName(const Params& params, const EnumDescriptor* descriptor) {
// Construct the path name from the package and outer class
- // Add the java package name if it exsits
+ // Add the java package name if it exists
if (params.has_java_package(file_name)) {
result += params.java_package(file_name);
}
- // Add the outer classname if it exists
- if (params.has_java_outer_classname(file_name)) {
+ // If the java_multiple_files option is present, we will generate enums into separate
+ // classes, each named after the original enum type. This takes precedence over
+ // any outer_classname.
+ if (params.java_multiple_files() && last_dot_in_name != string::npos) {
+ string enum_simple_name = full_name.substr(last_dot_in_name + 1);
+ if (!result.empty()) {
+ result += ".";
+ }
+ result += enum_simple_name;
+ } else if (params.has_java_outer_classname(file_name)) {
+ // Add the outer classname if it exists
if (!result.empty()) {
result += ".";
}