aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2015-02-19 17:16:26 -0800
committerGravatar Jisi Liu <jisi.liu@gmail.com>2015-02-19 17:16:26 -0800
commita6fc5da0fc3285399da7974671a96a5fcbcd83f9 (patch)
treed6d5ecb89724c34f6df727551efe7cdae32b0d42
parentf2cf6cdcb2cd80458fb872e29e6936f4377c0e48 (diff)
Fix review comments.
Change-Id: Iafd4a3aa9d55e31478bf070311eeadfe95ece4d7
-rw-r--r--javanano/src/test/java/com/google/protobuf/nano/NanoTest.java2
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_field.cc11
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_message.cc10
3 files changed, 12 insertions, 11 deletions
diff --git a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
index f3ba2de5..2c9e2d84 100644
--- a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
+++ b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
@@ -3741,7 +3741,7 @@ public class NanoTest extends TestCase {
checkOneofCase(m, 0);
}
- public void testOneofMarshling() throws Exception {
+ public void testOneofMarshaling() throws Exception {
TestAllTypesNano m = new TestAllTypesNano();
TestAllTypesNano parsed = new TestAllTypesNano();
{
diff --git a/src/google/protobuf/compiler/javanano/javanano_field.cc b/src/google/protobuf/compiler/javanano/javanano_field.cc
index e40db620..85257f3f 100644
--- a/src/google/protobuf/compiler/javanano/javanano_field.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_field.cc
@@ -174,15 +174,10 @@ void GenerateOneofFieldEquals(const FieldDescriptor* descriptor,
if (GetJavaType(descriptor) == JAVATYPE_BYTES) {
printer->Print(variables,
"if (this.has$capitalized_name$()) {\n"
- " if (!other.has$capitalized_name$() ||\n"
- " !java.util.Arrays.equals((byte[]) this.$oneof_name$_,\n"
+ " if (!java.util.Arrays.equals((byte[]) this.$oneof_name$_,\n"
" (byte[]) other.$oneof_name$_)) {\n"
" return false;\n"
" }\n"
- "} else {\n"
- " if (other.has$capitalized_name$()) {\n"
- " return false;\n"
- " }\n"
"}\n");
} else {
printer->Print(variables,
@@ -190,10 +185,6 @@ void GenerateOneofFieldEquals(const FieldDescriptor* descriptor,
" if (!this.$oneof_name$_.equals(other.$oneof_name$_)) {\n"
" return false;\n"
" }\n"
- "} else {\n"
- " if (other.has$capitalized_name$()) {\n"
- " return false;\n"
- " }\n"
"}\n");
}
}
diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc
index ac591bbb..707f6b84 100644
--- a/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_message.cc
@@ -551,6 +551,16 @@ void MessageGenerator::GenerateEquals(io::Printer* printer) {
"$classname$ other = ($classname$) o;\n",
"classname", descriptor_->name());
+ // Checking oneof case before checking each oneof field.
+ for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ const OneofDescriptor* oneof_desc = descriptor_->oneof_decl(i);
+ printer->Print(
+ "if (this.$oneof_name$Case_ != other.$oneof_name$Case_) {\n"
+ " return false;\n"
+ "}\n",
+ "oneof_name", UnderscoresToCamelCase(oneof_desc));
+ }
+
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
field_generators_.get(field).GenerateEqualsCode(printer);