diff options
author | Max Cai <maxtroy@google.com> | 2013-09-18 17:10:31 +0100 |
---|---|---|
committer | Max Cai <maxtroy@google.com> | 2013-09-18 17:11:28 +0100 |
commit | 26ce449901aa8c2f954fb4a5e8bbcc1253b3ca01 (patch) | |
tree | 53d04ec6f5e0a9aa5f716020bef385758f7ce139 /src | |
parent | 11c3b27da0b81064b745d4e11ba54d9ce592d318 (diff) | |
download | external_protobuf-26ce449901aa8c2f954fb4a5e8bbcc1253b3ca01.zip external_protobuf-26ce449901aa8c2f954fb4a5e8bbcc1253b3ca01.tar.gz external_protobuf-26ce449901aa8c2f954fb4a5e8bbcc1253b3ca01.tar.bz2 |
Add two codegen parameters to nano.
enum_style = c | java: 'c' to put the enum member int constants
at the parent scope; 'java' to create uninstantiatable shell
classes at the parent scope and put the int constants inside.
optional_field_style = default | accessors: 'default' to create
one public mutable field per optional proto field; 'accessors'
to encapsulate the generated fields behind get, set, has and
clear accessors.
This CL only contains parsing code for these two parameters.
Change-Id: Iec0c3b0f30af8eb7db328e790664306bc90be089
Diffstat (limited to 'src')
-rw-r--r-- | src/google/protobuf/compiler/javanano/javanano_generator.cc | 13 | ||||
-rw-r--r-- | src/google/protobuf/compiler/javanano/javanano_params.h | 19 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_generator.cc b/src/google/protobuf/compiler/javanano/javanano_generator.cc index 5bed1b1..8ba3f50 100644 --- a/src/google/protobuf/compiler/javanano/javanano_generator.cc +++ b/src/google/protobuf/compiler/javanano/javanano_generator.cc @@ -119,12 +119,23 @@ bool JavaNanoGenerator::Generate(const FileDescriptor* file, } else if (options[i].first == "java_multiple_files") { params.set_override_java_multiple_files(options[i].second == "true"); } else if (options[i].first == "java_nano_generate_has") { - params.set_generate_has(options[i].second == "true"); + params.set_generate_has(options[i].second == "true"); + } else if (options[i].first == "enum_style") { + params.set_java_enum_style(options[i].second == "java"); + } else if (options[i].first == "optional_field_style") { + params.set_optional_field_accessors(options[i].second == "accessors"); } else { *error = "Ignore unknown javanano generator option: " + options[i].first; } } + // Check illegal parameter combinations + if (params.generate_has() && params.optional_field_accessors()) { + error->assign("java_nano_generate_has=true cannot be used in conjunction" + " with optional_field_style=accessors"); + return false; + } + // ----------------------------------------------------------------- FileGenerator file_generator(file, params); diff --git a/src/google/protobuf/compiler/javanano/javanano_params.h b/src/google/protobuf/compiler/javanano/javanano_params.h index 51686da..5be5ff9 100644 --- a/src/google/protobuf/compiler/javanano/javanano_params.h +++ b/src/google/protobuf/compiler/javanano/javanano_params.h @@ -58,6 +58,8 @@ class Params { NameMap java_outer_classnames_; NameSet java_multiple_files_; bool generate_has_; + bool java_enum_style_; + bool optional_field_accessors_; public: Params(const string & base_name) : @@ -65,7 +67,9 @@ class Params { base_name_(base_name), override_java_multiple_files_(JAVANANO_MUL_UNSET), store_unknown_fields_(false), - generate_has_(false) { + generate_has_(false), + java_enum_style_(false), + optional_field_accessors_(false) { } const string& base_name() const { @@ -160,6 +164,19 @@ class Params { return generate_has_; } + void set_java_enum_style(bool value) { + java_enum_style_ = value; + } + bool java_enum_style() const { + return java_enum_style_; + } + + void set_optional_field_accessors(bool value) { + optional_field_accessors_ = value; + } + bool optional_field_accessors() const { + return optional_field_accessors_; + } }; } // namespace javanano |