diff options
author | Max Cai <maxtroy@google.com> | 2013-12-10 12:56:22 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-12-10 12:56:23 +0000 |
commit | cea499acf68b35921b956785c26c0e6f18c241c1 (patch) | |
tree | 196b5f09c23bb1dddc242ef002106b78afdaff1a /src | |
parent | b6089cca5248f19832dde54faaad62891ff8bd25 (diff) | |
parent | 102cfe65b9b9e2b458c3d0ec69d47e8fc40dc726 (diff) | |
download | external_protobuf-cea499acf68b35921b956785c26c0e6f18c241c1.zip external_protobuf-cea499acf68b35921b956785c26c0e6f18c241c1.tar.gz external_protobuf-cea499acf68b35921b956785c26c0e6f18c241c1.tar.bz2 |
Merge "Nano: don't generate accessor methods for nested methods"
Diffstat (limited to 'src')
3 files changed, 6 insertions, 119 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_field.cc b/src/google/protobuf/compiler/javanano/javanano_field.cc index 62e133e..2581669 100644 --- a/src/google/protobuf/compiler/javanano/javanano_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_field.cc @@ -78,8 +78,9 @@ FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor, const Params FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field, const Params ¶ms, int* next_has_bit_index) { + JavaType java_type = GetJavaType(field); if (field->is_repeated()) { - switch (GetJavaType(field)) { + switch (java_type) { case JAVATYPE_MESSAGE: return new RepeatedMessageFieldGenerator(field, params); case JAVATYPE_ENUM: @@ -87,14 +88,13 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field, default: return new RepeatedPrimitiveFieldGenerator(field, params); } - } else if (params.optional_field_accessors() && field->is_optional()) { + } else if (params.optional_field_accessors() && field->is_optional() + && java_type != JAVATYPE_MESSAGE) { // We need a has-bit for each primitive/enum field because their default // values could be same as explicitly set values. But we don't need it // for a message field because they have no defaults and Nano uses 'null' // for unset messages, which cannot be set explicitly. - switch (GetJavaType(field)) { - case JAVATYPE_MESSAGE: - return new AccessorMessageFieldGenerator(field, params); + switch (java_type) { case JAVATYPE_ENUM: return new AccessorEnumFieldGenerator( field, params, (*next_has_bit_index)++); @@ -103,7 +103,7 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field, field, params, (*next_has_bit_index)++); } } else { - switch (GetJavaType(field)) { + switch (java_type) { case JAVATYPE_MESSAGE: return new MessageFieldGenerator(field, params); case JAVATYPE_ENUM: diff --git a/src/google/protobuf/compiler/javanano/javanano_message_field.cc b/src/google/protobuf/compiler/javanano/javanano_message_field.cc index d9abea3..74d3f85 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message_field.cc +++ b/src/google/protobuf/compiler/javanano/javanano_message_field.cc @@ -149,97 +149,6 @@ GenerateHashCodeCode(io::Printer* printer) const { // =================================================================== -AccessorMessageFieldGenerator:: -AccessorMessageFieldGenerator( - const FieldDescriptor* descriptor, const Params& params) - : FieldGenerator(params), descriptor_(descriptor) { - SetMessageVariables(params, descriptor, &variables_); -} - -AccessorMessageFieldGenerator::~AccessorMessageFieldGenerator() {} - -void AccessorMessageFieldGenerator:: -GenerateMembers(io::Printer* printer) const { - printer->Print(variables_, - "private $type$ $name$_;\n" - "public $type$ get$capitalized_name$() {\n" - " return $name$_;\n" - "}\n" - "public $message_name$ set$capitalized_name$($type$ value) {\n" - " if (value == null) {\n" - " throw new java.lang.NullPointerException();\n" - " }\n" - " $name$_ = value;\n" - " return this;\n" - "}\n" - "public boolean has$capitalized_name$() {\n" - " return $name$_ != null;\n" - "}\n" - "public $message_name$ clear$capitalized_name$() {\n" - " $name$_ = null;\n" - " return this;" - "}\n"); -} - -void AccessorMessageFieldGenerator:: -GenerateClearCode(io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = null;\n"); -} - -void AccessorMessageFieldGenerator:: -GenerateMergingCode(io::Printer* printer) const { - printer->Print(variables_, - "if ($name$_ == null) {\n" - " $name$_ = new $type$();\n" - "}\n"); - - if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) { - printer->Print(variables_, - "input.readGroup($name$_, $number$);\n"); - } else { - printer->Print(variables_, - "input.readMessage($name$_);\n"); - } -} - -void AccessorMessageFieldGenerator:: -GenerateSerializationCode(io::Printer* printer) const { - printer->Print(variables_, - "if ($name$_ != null) {\n" - " output.write$group_or_message$($number$, $name$_);\n" - "}\n"); -} - -void AccessorMessageFieldGenerator:: -GenerateSerializedSizeCode(io::Printer* printer) const { - printer->Print(variables_, - "if ($name$_ != null) {\n" - " size += com.google.protobuf.nano.CodedOutputByteBufferNano\n" - " .compute$group_or_message$Size($number$, $name$_);\n" - "}\n"); -} - -void AccessorMessageFieldGenerator:: -GenerateEqualsCode(io::Printer* printer) const { - printer->Print(variables_, - "if ($name$_ == null) {\n" - " if (other.$name$_ != null) {\n" - " return false;\n" - " }\n" - "} else if (!$name$_.equals(other.$name$_)) {\n" - " return false;\n" - "}\n"); -} - -void AccessorMessageFieldGenerator:: -GenerateHashCodeCode(io::Printer* printer) const { - printer->Print(variables_, - "result = 31 * result + ($name$_ == null ? 0 : $name$_.hashCode());\n"); -} - -// =================================================================== - RepeatedMessageFieldGenerator:: RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, const Params& params) : FieldGenerator(params), descriptor_(descriptor) { diff --git a/src/google/protobuf/compiler/javanano/javanano_message_field.h b/src/google/protobuf/compiler/javanano/javanano_message_field.h index b724351..55e2610 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message_field.h +++ b/src/google/protobuf/compiler/javanano/javanano_message_field.h @@ -65,28 +65,6 @@ class MessageFieldGenerator : public FieldGenerator { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); }; -class AccessorMessageFieldGenerator : public FieldGenerator { - public: - explicit AccessorMessageFieldGenerator( - const FieldDescriptor* descriptor, const Params& params); - ~AccessorMessageFieldGenerator(); - - // implements FieldGenerator --------------------------------------- - void GenerateMembers(io::Printer* printer) const; - void GenerateClearCode(io::Printer* printer) const; - void GenerateMergingCode(io::Printer* printer) const; - void GenerateSerializationCode(io::Printer* printer) const; - void GenerateSerializedSizeCode(io::Printer* printer) const; - void GenerateEqualsCode(io::Printer* printer) const; - void GenerateHashCodeCode(io::Printer* printer) const; - - private: - const FieldDescriptor* descriptor_; - map<string, string> variables_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AccessorMessageFieldGenerator); -}; - class RepeatedMessageFieldGenerator : public FieldGenerator { public: explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, |