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..c71edfa5f8d6afd0546de55b68f30641f4996ff5 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: |
| + parameter_count = len(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): |
| @@ -396,12 +400,60 @@ class OperationInfo(object): |
| assert any([is_static == o.is_static for o in self.overloads]) |
| return is_static |
| - def ConstructorFullName(self): |
| + def _ConstructorFullName(self): |
| if self.constructor_name: |
| return self.type_name + '.' + self.constructor_name |
| else: |
| return self.type_name |
| + def ConstructorFactoryName(self, rename_type): |
| + return 'create' + rename_type(self._ConstructorFullName()).replace('.', '_') |
| + |
| + def GenerateFactoryInvocation(self, rename_type, emitter, factory_provider): |
| + has_optional = any(param_info.is_optional |
| + for param_info in self.param_infos) |
| + |
| + factory_name = self.ConstructorFactoryName(rename_type) |
| + if not has_optional: |
| + emitter.Emit( |
| + '\n' |
| + ' factory $CTOR($PARAMS) => $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n', |
|
vsm
2012/09/18 15:57:03
nit: line length
blois
2012/09/18 18:12:26
Done.
|
| + 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): |
|
Anton Muhin
2012/09/18 07:45:34
up to you, another option would be to put definiti
blois
2012/09/18 18:12:26
Done.
|
| + emitter.Emit( |
| + ' if (!?$OPT_PARAM_NAME) {\n' |
| + ' 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)) |
| + |
| + dispatcher_emitter = emitter.Emit( |
| + '\n' |
| + ' factory $CTOR($PARAMS) {\n' |
| + '$!DISPATCHER' |
| + ' return $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' |
| + ' }\n', |
| + CTOR=rename_type(self._ConstructorFullName()), |
| + PARAMS=self.ParametersInterfaceDeclaration(rename_type), |
| + FACTORY=factory_provider, |
| + CTOR_FACTORY_NAME=factory_name, |
| + FACTORY_PARAMS=self.ParametersAsArgumentList()) |
| + |
| + for index, param_info in enumerate(self.param_infos): |
| + if param_info.is_optional: |
| + EmitOptionalParameterInvocation(index, dispatcher_emitter) |
| + |
| + |
| def CopyAndWidenDefaultParameters(self): |
| """Returns equivalent OperationInfo, but default parameters are Dynamic.""" |
| info = copy.copy(self) |