-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix default parameters with specifiers issue
- Loading branch information
Showing
2 changed files
with
28 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,27 +96,22 @@ def _GenerateMethods(output_lines, source, class_node): | |
|
||
args = '' | ||
if node.parameters: | ||
# Due to the parser limitations, it is impossible to keep comments | ||
# while stripping the default parameters. When defaults are | ||
# present, we choose to strip them and comments (and produce | ||
# compilable code). | ||
# TODO([email protected]): Investigate whether it is possible to | ||
# preserve parameter name when reconstructing parameter text from | ||
# the AST. | ||
if len([param for param in node.parameters if param.default]) > 0: | ||
args = ', '.join(param.type.name for param in node.parameters) | ||
else: | ||
# Get the full text of the parameters from the start | ||
# of the first parameter to the end of the last parameter. | ||
start = node.parameters[0].start | ||
end = node.parameters[-1].end | ||
# Remove // comments. | ||
args_strings = re.sub(r'//.*', '', source[start:end]) | ||
# Condense multiple spaces and eliminate newlines putting the | ||
# parameters together on a single line. Ensure there is a | ||
# space in an argument which is split by a newline without | ||
# intervening whitespace, e.g.: int\nBar | ||
args = re.sub(' +', ' ', args_strings.replace('\n', ' ')) | ||
# Get the full text of the parameters from the start | ||
# of the first parameter to the end of the last parameter. | ||
start = node.parameters[0].start | ||
end = node.parameters[-1].end | ||
# Remove // comments. | ||
args_strings = re.sub(r'//.*', '', source[start:end]) | ||
# Remove /* comments */. | ||
args_strings = re.sub(r'/\*.*\*/', '', args_strings) | ||
# Remove default arguments. | ||
args_strings = re.sub(r'=.*,', ',', args_strings) | ||
args_strings = re.sub(r'=.*', '', args_strings) | ||
# Condense multiple spaces and eliminate newlines putting the | ||
# parameters together on a single line. Ensure there is a | ||
# space in an argument which is split by a newline without | ||
# intervening whitespace, e.g.: int\nBar | ||
args = re.sub(' +', ' ', args_strings.replace('\n', ' ')) | ||
|
||
# Create the mock method definition. | ||
output_lines.extend(['%s%s(%s,' % (indent, mock_method_macro, node.name), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters