Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
815ff7e1
Unverified
Commit
815ff7e1
authored
Jun 21, 2019
by
Paul Yang
Committed by
GitHub
Jun 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Append field number to accessors if there is conflict (#6169)" (#6282)
This reverts commit
9a8ef05a
.
parent
6e58040a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
104 deletions
+13
-104
test_wrapper_type_setters.proto
php/tests/proto/test_wrapper_type_setters.proto
+0
-11
wrapper_type_setters_test.php
php/tests/wrapper_type_setters_test.php
+0
-38
php_generator.cc
src/google/protobuf/compiler/php/php_generator.cc
+13
-55
No files found.
php/tests/proto/test_wrapper_type_setters.proto
View file @
815ff7e1
...
...
@@ -24,14 +24,3 @@ message TestWrapperSetters {
map
<
string
,
google.protobuf.StringValue
>
map_string_value
=
13
;
}
message
TestWrapperAccessorConflicts
{
int32
normal_vs_wrapper_value
=
1
;
google.protobuf.Int32Value
normal_vs_wrapper
=
2
;
int32
normal_vs_normal_value
=
3
;
int32
normal_vs_normal
=
4
;
google.protobuf.Int32Value
wrapper_vs_wrapper_value
=
5
;
google.protobuf.Int32Value
wrapper_vs_wrapper
=
6
;
}
php/tests/wrapper_type_setters_test.php
View file @
815ff7e1
...
...
@@ -16,44 +16,6 @@ use Google\Protobuf\UInt64Value;
class
WrapperTypeSettersTest
extends
TestBase
{
public
function
testConflictNormalVsWrapper
()
{
$m
=
new
Foo\TestWrapperAccessorConflicts
();
$m
->
setNormalVsWrapperValue1
(
1
);
$this
->
assertSame
(
1
,
$m
->
getNormalVsWrapperValue1
());
$m
->
setNormalVsWrapperValue2
(
1
);
$this
->
assertSame
(
1
,
$m
->
getNormalVsWrapperValue2
());
$wrapper
=
new
Int32Value
([
"value"
=>
1
]);
$m
->
setNormalVsWrapper
(
$wrapper
);
$this
->
assertSame
(
1
,
$m
->
getNormalVsWrapper
()
->
getValue
());
}
public
function
testConflictNormalVsNormal
()
{
$m
=
new
Foo\TestWrapperAccessorConflicts
();
$m
->
setNormalVsNormalValue
(
1
);
$this
->
assertSame
(
1
,
$m
->
getNormalVsNormalValue
());
$m
->
setNormalVsNormal
(
1
);
$this
->
assertSame
(
1
,
$m
->
getNormalVsNormal
());
}
public
function
testConflictWrapperVsWrapper
()
{
$m
=
new
Foo\TestWrapperAccessorConflicts
();
$m
->
setWrapperVsWrapperValueValue
(
1
);
$this
->
assertSame
(
1
,
$m
->
getWrapperVsWrapperValueValue
());
$wrapper
=
new
Int32Value
([
"value"
=>
1
]);
$m
->
setWrapperVsWrapperValue5
(
$wrapper
);
$this
->
assertSame
(
1
,
$m
->
getWrapperVsWrapperValue5
()
->
getValue
());
}
/**
* @dataProvider gettersAndSettersDataProvider
*/
...
...
src/google/protobuf/compiler/php/php_generator.cc
View file @
815ff7e1
...
...
@@ -655,58 +655,27 @@ void GenerateOneofField(const OneofDescriptor* oneof, io::Printer* printer) {
void
GenerateFieldAccessor
(
const
FieldDescriptor
*
field
,
bool
is_descriptor
,
io
::
Printer
*
printer
)
{
bool
need_other_name_for_accessor
=
false
;
bool
need_other_name_for_wrapper_accessor
=
false
;
const
Descriptor
*
desc
=
field
->
containing_type
();
if
(
!
field
->
is_repeated
()
&&
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_MESSAGE
&&
IsWrapperType
(
field
))
{
// Check if there is any field called xxx_value
const
FieldDescriptor
*
other
=
desc
->
FindFieldByName
(
StrCat
(
field
->
name
(),
"_value"
));
if
(
other
!=
NULL
)
{
need_other_name_for_wrapper_accessor
=
true
;
}
}
if
(
strings
::
EndsWith
(
field
->
name
(),
"_value"
))
{
std
::
size_t
pos
=
(
field
->
name
()).
find
(
"_value"
);
string
name
=
(
field
->
name
()).
substr
(
0
,
pos
);
const
FieldDescriptor
*
other
=
desc
->
FindFieldByName
(
name
);
if
(
other
!=
NULL
&&
!
other
->
is_repeated
()
&&
other
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_MESSAGE
&&
IsWrapperType
(
other
))
{
need_other_name_for_accessor
=
true
;
}
}
const
OneofDescriptor
*
oneof
=
field
->
containing_oneof
();
// Generate getter.
if
(
oneof
!=
NULL
)
{
GenerateFieldDocComment
(
printer
,
field
,
is_descriptor
,
kFieldGetter
);
printer
->
Print
(
"public function get^camel_name^
^field_number^
()
\n
"
"public function get^camel_name^()
\n
"
"{
\n
"
" return $this->readOneof(^number^);
\n
"
"}
\n\n
"
,
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
),
"number"
,
IntToString
(
field
->
number
()),
"field_number"
,
need_other_name_for_accessor
?
StrCat
(
field
->
number
())
:
""
);
"number"
,
IntToString
(
field
->
number
()));
}
else
{
GenerateFieldDocComment
(
printer
,
field
,
is_descriptor
,
kFieldGetter
);
printer
->
Print
(
"public function get^camel_name^
^field_number^
()
\n
"
"public function get^camel_name^()
\n
"
"{
\n
"
" return $this->^name^;
\n
"
"}
\n\n
"
,
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
),
"name"
,
field
->
name
(),
"field_number"
,
need_other_name_for_accessor
?
StrCat
(
field
->
number
())
:
""
);
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
),
"name"
,
field
->
name
());
}
// For wrapper types, generate an additional getXXXValue getter
...
...
@@ -715,28 +684,21 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
field
->
cpp_type
()
==
FieldDescriptor
::
CPPTYPE_MESSAGE
&&
IsWrapperType
(
field
))
{
GenerateWrapperFieldGetterDocComment
(
printer
,
field
);
printer
->
Print
(
"public function get^camel_name^Value
^field_number1^
()
\n
"
"public function get^camel_name^Value()
\n
"
"{
\n
"
" $wrapper = $this->get^camel_name^
^field_number2^
();
\n
"
" $wrapper = $this->get^camel_name^();
\n
"
" return is_null($wrapper) ? null : $wrapper->getValue();
\n
"
"}
\n\n
"
,
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
),
"field_number1"
,
need_other_name_for_wrapper_accessor
?
StrCat
(
field
->
number
())
:
""
,
"field_number2"
,
need_other_name_for_accessor
?
StrCat
(
field
->
number
())
:
""
);
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
));
}
// Generate setter.
GenerateFieldDocComment
(
printer
,
field
,
is_descriptor
,
kFieldSetter
);
printer
->
Print
(
"public function set^camel_name^
^field_number^
($var)
\n
"
"public function set^camel_name^($var)
\n
"
"{
\n
"
,
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
),
"field_number"
,
need_other_name_for_accessor
?
StrCat
(
field
->
number
())
:
""
);
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
));
Indent
(
printer
);
...
...
@@ -836,17 +798,13 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
IsWrapperType
(
field
))
{
GenerateWrapperFieldSetterDocComment
(
printer
,
field
);
printer
->
Print
(
"public function set^camel_name^Value
^field_number1^
($var)
\n
"
"public function set^camel_name^Value($var)
\n
"
"{
\n
"
" $wrappedVar = is_null($var) ? null : new
\\
^wrapper_type^(['value' => $var]);
\n
"
" return $this->set^camel_name^
^field_number2^
($wrappedVar);
\n
"
" return $this->set^camel_name^($wrappedVar);
\n
"
"}
\n\n
"
,
"camel_name"
,
UnderscoresToCamelCase
(
field
->
name
(),
true
),
"wrapper_type"
,
LegacyFullClassName
(
field
->
message_type
(),
is_descriptor
),
"field_number1"
,
need_other_name_for_wrapper_accessor
?
StrCat
(
field
->
number
())
:
""
,
"field_number2"
,
need_other_name_for_accessor
?
StrCat
(
field
->
number
())
:
""
);
"wrapper_type"
,
LegacyFullClassName
(
field
->
message_type
(),
is_descriptor
));
}
// Generate has method for proto2 only.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment