Chromium Code Reviews| Index: lib/html/scripts/generator.py |
| diff --git a/lib/html/scripts/generator.py b/lib/html/scripts/generator.py |
| index a3b6a871a4ddaa0e1f01e96036ce67a0298eb50d..8541432bd9404fedccb4b816488538e1b0987117 100644 |
| --- a/lib/html/scripts/generator.py |
| +++ b/lib/html/scripts/generator.py |
| @@ -362,11 +362,15 @@ class OperationInfo(object): |
| self.param_infos, 'null', |
| lambda param: TypeOrNothing(rename_type(param.dart_type))) |
| - def ParametersAsArgumentList(self): |
| + def ParametersAsArgumentList(self, parameter_count = None): |
| """Returns a string of the parameter names suitable for passing the |
| parameters as arguments. |
| """ |
| - return ', '.join(map(lambda param_info: param_info.name, self.param_infos)) |
| + if parameter_count is None: |
|
Anton Muhin
2012/09/17 10:11:28
please, do not duplicate common logic. Instead, s
blois
2012/09/17 19:48:22
Done.
|
| + return ', '.join(map(lambda param_info: param_info.name, self.param_infos)) |
| + return ', '.join(map( |
| + lambda param_info: param_info.name, |
| + self.param_infos[:parameter_count])) |
| def _FormatParams(self, params, default_value, type_fn): |
| def FormatParam(param): |
| @@ -402,6 +406,63 @@ class OperationInfo(object): |
| else: |
| return self.type_name |
| + def ConstructorFactoryName(self, rename_type): |
| + type_name = rename_type(self.type_name) |
|
Anton Muhin
2012/09/17 10:11:28
why you rename type here, but it's not renamed in
blois
2012/09/17 19:48:22
The rename_type here converts between DOM names an
|
| + if self.constructor_name: |
| + return 'create' + type_name + '_' + self.constructor_name |
| + else: |
| + return 'create' + type_name |
| + |
| + def GenerateFactoryInvocation(self, rename_type, emitter, factory_provider): |
| + has_optional = False |
|
Anton Muhin
2012/09/17 10:11:28
has_optional = any(param_info.is_optional for para
blois
2012/09/17 19:48:22
Done.
|
| + for param_info in self.param_infos: |
| + if param_info.is_optional: |
| + has_optional = True |
| + |
| + factory_name = self.ConstructorFactoryName(rename_type) |
| + if not has_optional: |
| + emitter.Emit( |
| + '\n' |
| + ' factory $CTOR($PARAMS) => $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n', |
| + CTOR=rename_type(self.ConstructorFullName()), |
| + PARAMS=self.ParametersInterfaceDeclaration(rename_type), |
| + FACTORY=factory_provider, |
| + CTOR_FACTORY_NAME=factory_name, |
| + FACTORY_PARAMS=self.ParametersAsArgumentList()) |
| + return |
| + |
| + # If we have optional parameters, check to see if they are set |
| + # and call the appropriate factory method. |
| + def EmitOptionalParameterInvocation(index): |
| + emitter.Emit( |
| + ' if (!?$(OPT_PARAM_NAME)) {\n' |
|
Anton Muhin
2012/09/17 10:11:28
nit: why OPT_PARAM_NAME is in parentheses?
blois
2012/09/17 19:48:22
Probably leftover from something else. Converted.
|
| + ' return $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' |
| + ' }\n', |
| + OPT_PARAM_NAME=self.param_infos[index].name, |
| + FACTORY=factory_provider, |
| + CTOR_FACTORY_NAME=factory_name, |
| + FACTORY_PARAMS=self.ParametersAsArgumentList(index)) |
| + |
| + emitter.Emit( |
|
Anton Muhin
2012/09/17 10:11:28
I'd rather do something like:
dispatcher_emitter
blois
2012/09/17 19:48:22
Done. Wasn't aware of that trick!
On 2012/09/17 1
|
| + '\n factory $CTOR($PARAMS) {\n', |
| + CTOR=rename_type(self.ConstructorFullName()), |
| + PARAMS=self.ParametersInterfaceDeclaration(rename_type)) |
| + |
| + index = 0 |
| + for param_info in self.param_infos: |
|
Anton Muhin
2012/09/17 10:11:28
for index, param_info in enumerate(self.param_info
blois
2012/09/17 19:48:22
Done.
|
| + if param_info.is_optional: |
| + EmitOptionalParameterInvocation(index) |
| + index += 1 |
| + |
| + emitter.Emit( |
| + ' return $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n', |
| + FACTORY=factory_provider, |
| + CTOR_FACTORY_NAME=factory_name, |
| + FACTORY_PARAMS=self.ParametersAsArgumentList()) |
| + |
| + emitter.Emit(' }\n') |
| + |
| + |
| def CopyAndWidenDefaultParameters(self): |
| """Returns equivalent OperationInfo, but default parameters are Dynamic.""" |
| info = copy.copy(self) |