aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/javanano/javanano_helpers.cc
diff options
context:
space:
mode:
authorGravatar Max Cai <maxtroy@google.com>2013-09-24 17:40:37 +0100
committerGravatar Max Cai <maxtroy@google.com>2013-09-25 19:44:27 +0100
commit1479c7ab1b72346df56b95816a58234ba2ceb9cd (patch)
tree35f29c2fab71ccb576c1226644ce7f64914beb6b /src/google/protobuf/compiler/javanano/javanano_helpers.cc
parentb337f25628ceb3649df5c4e89b5125e7698a9b47 (diff)
Implement enum_style=java option.
This javanano_out command line option creates a container interface at the normal place where the enum constants would reside, per enum definition. The java_multiple_files flag would now affect the file- scope enums with the shells. If the flag is true then file-scope container interfaces are created in their own files. Change-Id: Id52258fcff8d3dee9db8f3d8022147a811bf3565
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_helpers.cc')
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_helpers.cc28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/src/google/protobuf/compiler/javanano/javanano_helpers.cc
index 630ecd10..c4241653 100644
--- a/src/google/protobuf/compiler/javanano/javanano_helpers.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_helpers.cc
@@ -197,12 +197,23 @@ string FileJavaPackage(const Params& params, const FileDescriptor* file) {
}
bool IsOuterClassNeeded(const Params& params, const FileDescriptor* file) {
- // Enums and extensions need the outer class as the scope.
- if (file->enum_type_count() != 0 || file->extension_count() != 0) {
+ // If java_multiple_files is false, the outer class is always needed.
+ if (!params.java_multiple_files(file->name())) {
return true;
}
- // Messages need the outer class only if java_multiple_files is false.
- return !params.java_multiple_files(file->name());
+
+ // File-scope extensions need the outer class as the scope.
+ if (file->extension_count() != 0) {
+ return true;
+ }
+
+ // If container interfaces are not generated, file-scope enums need the
+ // outer class as the scope.
+ if (file->enum_type_count() != 0 && !params.java_enum_style()) {
+ return true;
+ }
+
+ return false;
}
string ToJavaName(const Params& params, const string& name, bool is_class,
@@ -228,9 +239,14 @@ string ClassName(const Params& params, const FileDescriptor* descriptor) {
}
string ClassName(const Params& params, const EnumDescriptor* descriptor) {
- // An enum's class name is the enclosing message's class name or the outer
- // class name.
const Descriptor* parent = descriptor->containing_type();
+ // When using Java enum style, an enum's class name contains the enum name.
+ // Use the standard ToJavaName translation.
+ if (params.java_enum_style()) {
+ return ToJavaName(params, descriptor->name(), true, parent,
+ descriptor->file());
+ }
+ // Otherwise the enum members are accessed from the enclosing class.
if (parent != NULL) {
return ClassName(params, parent);
} else {