Commit a6fc5da0 authored by Jisi Liu's avatar Jisi Liu

Fix review comments.

Change-Id: Iafd4a3aa9d55e31478bf070311eeadfe95ece4d7
parent f2cf6cdc
......@@ -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();
{
......
......@@ -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");
}
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment