diff options
author | Wink Saville <wink@google.com> | 2013-06-07 14:46:45 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-06-07 14:46:45 -0700 |
commit | 8ac37341ac169e99bc8e45fff614c60fee40e33a (patch) | |
tree | 93c739851fcc5e5efaa0f52bc64f89dbc39a03a9 | |
parent | 3c46a5260aba2b42a1a4b2399168dd155d37c52f (diff) | |
parent | 9459b5c45b0ad33bea9376c2afb66cf93da610ac (diff) | |
download | external_protobuf-8ac37341ac169e99bc8e45fff614c60fee40e33a.zip external_protobuf-8ac37341ac169e99bc8e45fff614c60fee40e33a.tar.gz external_protobuf-8ac37341ac169e99bc8e45fff614c60fee40e33a.tar.bz2 |
am 9459b5c4: Merge "Fix enum field references with java_multiple_files."
* commit '9459b5c45b0ad33bea9376c2afb66cf93da610ac':
Fix enum field references with java_multiple_files.
-rw-r--r-- | src/google/protobuf/compiler/javanano/javanano_helpers.cc | 18 | ||||
-rw-r--r-- | src/google/protobuf/unittest_enum_multiplejava_nano.proto | 4 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/src/google/protobuf/compiler/javanano/javanano_helpers.cc index 7839556..42cb133 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 += "."; } diff --git a/src/google/protobuf/unittest_enum_multiplejava_nano.proto b/src/google/protobuf/unittest_enum_multiplejava_nano.proto index d2da6c6..adf017d 100644 --- a/src/google/protobuf/unittest_enum_multiplejava_nano.proto +++ b/src/google/protobuf/unittest_enum_multiplejava_nano.proto @@ -47,3 +47,7 @@ enum SecondTopLevelEnum { SECOND_TOP_LEVEL_SECOND = 2; } +message SomeMessage { + optional FirstTopLevelEnum first = 1; + optional SecondTopLevelEnum second = 2; +} |