Rename get/setXXXValue to get/setXXXUnwrapped (#6295)

pull/6298/head^2
Paul Yang 6 years ago committed by GitHub
parent b7a5772caf
commit 54288a01ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 88
      php/tests/wrapper_type_setters_test.php
  2. 6
      src/google/protobuf/compiler/php/php_generator.cc

@ -60,26 +60,26 @@ class WrapperTypeSettersTest extends TestBase
public function gettersAndSettersDataProvider() public function gettersAndSettersDataProvider()
{ {
return [ return [
[TestWrapperSetters::class, DoubleValue::class, "setDoubleValue", "setDoubleValueValue", "getDoubleValue", "getDoubleValueValue", [ [TestWrapperSetters::class, DoubleValue::class, "setDoubleValue", "setDoubleValueUnwrapped", "getDoubleValue", "getDoubleValueUnwrapped", [
[1.1, new DoubleValue(["value" => 1.1])], [1.1, new DoubleValue(["value" => 1.1])],
[2.2, new DoubleValue(["value" => 2.2])], [2.2, new DoubleValue(["value" => 2.2])],
[null, null], [null, null],
[0, new DoubleValue()], [0, new DoubleValue()],
]], ]],
[TestWrapperSetters::class, FloatValue::class, "setFloatValue", "setFloatValueValue", "getFloatValue", "getFloatValueValue", [ [TestWrapperSetters::class, FloatValue::class, "setFloatValue", "setFloatValueUnwrapped", "getFloatValue", "getFloatValueUnwrapped", [
[1.1, new FloatValue(["value" => 1.1])], [1.1, new FloatValue(["value" => 1.1])],
[2.2, new FloatValue(["value" => 2.2])], [2.2, new FloatValue(["value" => 2.2])],
[null, null], [null, null],
[0, new FloatValue()], [0, new FloatValue()],
]], ]],
[TestWrapperSetters::class, Int64Value::class, "setInt64Value", "setInt64ValueValue", "getInt64Value", "getInt64ValueValue", [ [TestWrapperSetters::class, Int64Value::class, "setInt64Value", "setInt64ValueUnwrapped", "getInt64Value", "getInt64ValueUnwrapped", [
[123, new Int64Value(["value" => 123])], [123, new Int64Value(["value" => 123])],
[-789, new Int64Value(["value" => -789])], [-789, new Int64Value(["value" => -789])],
[null, null], [null, null],
[0, new Int64Value()], [0, new Int64Value()],
[5.5, new Int64Value(["value" => 5])], // Test conversion from float to int [5.5, new Int64Value(["value" => 5])], // Test conversion from float to int
]], ]],
[TestWrapperSetters::class, UInt64Value::class, "setUInt64Value", "setUInt64ValueValue", "getUInt64Value", "getUInt64ValueValue", [ [TestWrapperSetters::class, UInt64Value::class, "setUInt64Value", "setUInt64ValueUnwrapped", "getUInt64Value", "getUInt64ValueUnwrapped", [
[123, new UInt64Value(["value" => 123])], [123, new UInt64Value(["value" => 123])],
[789, new UInt64Value(["value" => 789])], [789, new UInt64Value(["value" => 789])],
[null, null], [null, null],
@ -87,14 +87,14 @@ class WrapperTypeSettersTest extends TestBase
[5.5, new UInt64Value(["value" => 5])], // Test conversion from float to int [5.5, new UInt64Value(["value" => 5])], // Test conversion from float to int
[-7, new UInt64Value(["value" => -7])], // Test conversion from -ve to +ve [-7, new UInt64Value(["value" => -7])], // Test conversion from -ve to +ve
]], ]],
[TestWrapperSetters::class, Int32Value::class, "setInt32Value", "setInt32ValueValue", "getInt32Value", "getInt32ValueValue", [ [TestWrapperSetters::class, Int32Value::class, "setInt32Value", "setInt32ValueUnwrapped", "getInt32Value", "getInt32ValueUnwrapped", [
[123, new Int32Value(["value" => 123])], [123, new Int32Value(["value" => 123])],
[-789, new Int32Value(["value" => -789])], [-789, new Int32Value(["value" => -789])],
[null, null], [null, null],
[0, new Int32Value()], [0, new Int32Value()],
[5.5, new Int32Value(["value" => 5])], // Test conversion from float to int [5.5, new Int32Value(["value" => 5])], // Test conversion from float to int
]], ]],
[TestWrapperSetters::class, UInt32Value::class, "setUInt32Value", "setUInt32ValueValue", "getUInt32Value", "getUInt32ValueValue", [ [TestWrapperSetters::class, UInt32Value::class, "setUInt32Value", "setUInt32ValueUnwrapped", "getUInt32Value", "getUInt32ValueUnwrapped", [
[123, new UInt32Value(["value" => 123])], [123, new UInt32Value(["value" => 123])],
[789, new UInt32Value(["value" => 789])], [789, new UInt32Value(["value" => 789])],
[null, null], [null, null],
@ -102,12 +102,12 @@ class WrapperTypeSettersTest extends TestBase
[5.5, new UInt32Value(["value" => 5])], // Test conversion from float to int [5.5, new UInt32Value(["value" => 5])], // Test conversion from float to int
[-7, new UInt32Value(["value" => -7])], // Test conversion from -ve to +ve [-7, new UInt32Value(["value" => -7])], // Test conversion from -ve to +ve
]], ]],
[TestWrapperSetters::class, BoolValue::class, "setBoolValue", "setBoolValueValue", "getBoolValue", "getBoolValueValue", [ [TestWrapperSetters::class, BoolValue::class, "setBoolValue", "setBoolValueUnwrapped", "getBoolValue", "getBoolValueUnwrapped", [
[true, new BoolValue(["value" => true])], [true, new BoolValue(["value" => true])],
[false, new BoolValue(["value" => false])], [false, new BoolValue(["value" => false])],
[null, null], [null, null],
]], ]],
[TestWrapperSetters::class, StringValue::class, "setStringValue", "setStringValueValue", "getStringValue", "getStringValueValue", [ [TestWrapperSetters::class, StringValue::class, "setStringValue", "setStringValueUnwrapped", "getStringValue", "getStringValueUnwrapped", [
["asdf", new StringValue(["value" => "asdf"])], ["asdf", new StringValue(["value" => "asdf"])],
["", new StringValue(["value" => ""])], ["", new StringValue(["value" => ""])],
[null, null], [null, null],
@ -117,7 +117,7 @@ class WrapperTypeSettersTest extends TestBase
[-7, new StringValue(["value" => "-7"])], // Test conversion from number to string [-7, new StringValue(["value" => "-7"])], // Test conversion from number to string
[-7.5, new StringValue(["value" => "-7.5"])], // Test conversion from number to string [-7.5, new StringValue(["value" => "-7.5"])], // Test conversion from number to string
]], ]],
[TestWrapperSetters::class, BytesValue::class, "setBytesValue", "setBytesValueValue", "getBytesValue", "getBytesValueValue", [ [TestWrapperSetters::class, BytesValue::class, "setBytesValue", "setBytesValueUnwrapped", "getBytesValue", "getBytesValueUnwrapped", [
["asdf", new BytesValue(["value" => "asdf"])], ["asdf", new BytesValue(["value" => "asdf"])],
["", new BytesValue(["value" => ""])], ["", new BytesValue(["value" => ""])],
[null, null], [null, null],
@ -127,12 +127,12 @@ class WrapperTypeSettersTest extends TestBase
[-7, new BytesValue(["value" => "-7"])], // Test conversion from number to bytes [-7, new BytesValue(["value" => "-7"])], // Test conversion from number to bytes
[-7.5, new BytesValue(["value" => "-7.5"])], // Test conversion from number to bytes [-7.5, new BytesValue(["value" => "-7.5"])], // Test conversion from number to bytes
]], ]],
[TestWrapperSetters::class, DoubleValue::class, "setDoubleValueOneof", "setDoubleValueOneofValue", "getDoubleValueOneof", "getDoubleValueOneofValue", [ [TestWrapperSetters::class, DoubleValue::class, "setDoubleValueOneof", "setDoubleValueOneofUnwrapped", "getDoubleValueOneof", "getDoubleValueOneofUnwrapped", [
[1.1, new DoubleValue(["value" => 1.1])], [1.1, new DoubleValue(["value" => 1.1])],
[2.2, new DoubleValue(["value" => 2.2])], [2.2, new DoubleValue(["value" => 2.2])],
[null, null], [null, null],
[0, new DoubleValue()], [0, new DoubleValue()],
]],[TestWrapperSetters::class, StringValue::class, "setStringValueOneof", "setStringValueOneofValue", "getStringValueOneof", "getStringValueOneofValue", [ ]],[TestWrapperSetters::class, StringValue::class, "setStringValueOneof", "setStringValueOneofUnwrapped", "getStringValueOneof", "getStringValueOneofUnwrapped", [
["asdf", new StringValue(["value" => "asdf"])], ["asdf", new StringValue(["value" => "asdf"])],
["", new StringValue(["value" => ""])], ["", new StringValue(["value" => ""])],
[null, null], [null, null],
@ -157,47 +157,47 @@ class WrapperTypeSettersTest extends TestBase
public function invalidSettersDataProvider() public function invalidSettersDataProvider()
{ {
return [ return [
[TestWrapperSetters::class, "setDoubleValueValue", "abc"], [TestWrapperSetters::class, "setDoubleValueUnwrapped", "abc"],
[TestWrapperSetters::class, "setDoubleValueValue", []], [TestWrapperSetters::class, "setDoubleValueUnwrapped", []],
[TestWrapperSetters::class, "setDoubleValueValue", new stdClass()], [TestWrapperSetters::class, "setDoubleValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setDoubleValueValue", new DoubleValue()], [TestWrapperSetters::class, "setDoubleValueUnwrapped", new DoubleValue()],
[TestWrapperSetters::class, "setFloatValueValue", "abc"], [TestWrapperSetters::class, "setFloatValueUnwrapped", "abc"],
[TestWrapperSetters::class, "setFloatValueValue", []], [TestWrapperSetters::class, "setFloatValueUnwrapped", []],
[TestWrapperSetters::class, "setFloatValueValue", new stdClass()], [TestWrapperSetters::class, "setFloatValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setFloatValueValue", new FloatValue()], [TestWrapperSetters::class, "setFloatValueUnwrapped", new FloatValue()],
[TestWrapperSetters::class, "setInt64ValueValue", "abc"], [TestWrapperSetters::class, "setInt64ValueUnwrapped", "abc"],
[TestWrapperSetters::class, "setInt64ValueValue", []], [TestWrapperSetters::class, "setInt64ValueUnwrapped", []],
[TestWrapperSetters::class, "setInt64ValueValue", new stdClass()], [TestWrapperSetters::class, "setInt64ValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setInt64ValueValue", new Int64Value()], [TestWrapperSetters::class, "setInt64ValueUnwrapped", new Int64Value()],
[TestWrapperSetters::class, "setUInt64ValueValue", "abc"], [TestWrapperSetters::class, "setUInt64ValueUnwrapped", "abc"],
[TestWrapperSetters::class, "setUInt64ValueValue", []], [TestWrapperSetters::class, "setUInt64ValueUnwrapped", []],
[TestWrapperSetters::class, "setUInt64ValueValue", new stdClass()], [TestWrapperSetters::class, "setUInt64ValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setUInt64ValueValue", new UInt64Value()], [TestWrapperSetters::class, "setUInt64ValueUnwrapped", new UInt64Value()],
[TestWrapperSetters::class, "setInt32ValueValue", "abc"], [TestWrapperSetters::class, "setInt32ValueUnwrapped", "abc"],
[TestWrapperSetters::class, "setInt32ValueValue", []], [TestWrapperSetters::class, "setInt32ValueUnwrapped", []],
[TestWrapperSetters::class, "setInt32ValueValue", new stdClass()], [TestWrapperSetters::class, "setInt32ValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setInt32ValueValue", new Int32Value()], [TestWrapperSetters::class, "setInt32ValueUnwrapped", new Int32Value()],
[TestWrapperSetters::class, "setUInt32ValueValue", "abc"], [TestWrapperSetters::class, "setUInt32ValueUnwrapped", "abc"],
[TestWrapperSetters::class, "setUInt32ValueValue", []], [TestWrapperSetters::class, "setUInt32ValueUnwrapped", []],
[TestWrapperSetters::class, "setUInt32ValueValue", new stdClass()], [TestWrapperSetters::class, "setUInt32ValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setUInt32ValueValue", new UInt32Value()], [TestWrapperSetters::class, "setUInt32ValueUnwrapped", new UInt32Value()],
[TestWrapperSetters::class, "setBoolValueValue", []], [TestWrapperSetters::class, "setBoolValueUnwrapped", []],
[TestWrapperSetters::class, "setBoolValueValue", new stdClass()], [TestWrapperSetters::class, "setBoolValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setBoolValueValue", new BoolValue()], [TestWrapperSetters::class, "setBoolValueUnwrapped", new BoolValue()],
[TestWrapperSetters::class, "setStringValueValue", []], [TestWrapperSetters::class, "setStringValueUnwrapped", []],
[TestWrapperSetters::class, "setStringValueValue", new stdClass()], [TestWrapperSetters::class, "setStringValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setStringValueValue", new StringValue()], [TestWrapperSetters::class, "setStringValueUnwrapped", new StringValue()],
[TestWrapperSetters::class, "setBytesValueValue", []], [TestWrapperSetters::class, "setBytesValueUnwrapped", []],
[TestWrapperSetters::class, "setBytesValueValue", new stdClass()], [TestWrapperSetters::class, "setBytesValueUnwrapped", new stdClass()],
[TestWrapperSetters::class, "setBytesValueValue", new BytesValue()], [TestWrapperSetters::class, "setBytesValueUnwrapped", new BytesValue()],
]; ];
} }

@ -678,14 +678,14 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
field->name()); field->name());
} }
// For wrapper types, generate an additional getXXXValue getter // For wrapper types, generate an additional getXXXUnwrapped getter
if (!field->is_map() && if (!field->is_map() &&
!field->is_repeated() && !field->is_repeated() &&
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
IsWrapperType(field)) { IsWrapperType(field)) {
GenerateWrapperFieldGetterDocComment(printer, field); GenerateWrapperFieldGetterDocComment(printer, field);
printer->Print( printer->Print(
"public function get^camel_name^Value()\n" "public function get^camel_name^Unwrapped()\n"
"{\n" "{\n"
" $wrapper = $this->get^camel_name^();\n" " $wrapper = $this->get^camel_name^();\n"
" return is_null($wrapper) ? null : $wrapper->getValue();\n" " return is_null($wrapper) ? null : $wrapper->getValue();\n"
@ -798,7 +798,7 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
IsWrapperType(field)) { IsWrapperType(field)) {
GenerateWrapperFieldSetterDocComment(printer, field); GenerateWrapperFieldSetterDocComment(printer, field);
printer->Print( printer->Print(
"public function set^camel_name^Value($var)\n" "public function set^camel_name^Unwrapped($var)\n"
"{\n" "{\n"
" $wrappedVar = is_null($var) ? null : new \\^wrapper_type^(['value' => $var]);\n" " $wrappedVar = is_null($var) ? null : new \\^wrapper_type^(['value' => $var]);\n"
" return $this->set^camel_name^($wrappedVar);\n" " return $this->set^camel_name^($wrappedVar);\n"

Loading…
Cancel
Save