| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 dart:html APIs from the IDL database.""" | 7 dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 9 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
| 10 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ | 10 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 PARAMS=constructor_info.ParametersDeclaration(self._DartType), | 267 PARAMS=constructor_info.ParametersDeclaration(self._DartType), |
| 268 FACTORY=factory_name, | 268 FACTORY=factory_name, |
| 269 FACTORY_PARAMS=constructor_info.ParametersAsArgumentList()) | 269 FACTORY_PARAMS=constructor_info.ParametersAsArgumentList()) |
| 270 | 270 |
| 271 for index, param_info in enumerate(constructor_info.param_infos): | 271 for index, param_info in enumerate(constructor_info.param_infos): |
| 272 if param_info.is_optional: | 272 if param_info.is_optional: |
| 273 dispatcher_emitter.Emit( | 273 dispatcher_emitter.Emit( |
| 274 ' if (!?$OPT_PARAM_NAME) {\n' | 274 ' if (!?$OPT_PARAM_NAME) {\n' |
| 275 ' return $FACTORY._create($FACTORY_PARAMS);\n' | 275 ' return $FACTORY._create($FACTORY_PARAMS);\n' |
| 276 ' }\n', | 276 ' }\n', |
| 277 OPT_PARAM_NAME=constructor_info.param_infos[index].name, | 277 OPT_PARAM_NAME=param_info.name, |
| 278 FACTORY=factory_name, | 278 FACTORY=factory_name, |
| 279 FACTORY_PARAMS=constructor_info.ParametersAsArgumentList(index)) | 279 FACTORY_PARAMS=constructor_info.ParametersAsArgumentList(index)) |
| 280 else: | 280 else: |
| 281 inits = self._members_emitter.Emit( | 281 inits = self._members_emitter.Emit( |
| 282 '\n' | 282 '\n' |
| 283 ' factory $CONSTRUCTOR($PARAMS) {\n' | 283 ' factory $CONSTRUCTOR($PARAMS) {\n' |
| 284 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' | 284 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' |
| 285 '$!INITS' | 285 '$!INITS' |
| 286 ' return e;\n' | 286 ' return e;\n' |
| 287 ' }\n', | 287 ' }\n', |
| 288 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), | 288 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), |
| 289 FACTORY=factory_name, | 289 FACTORY=factory_name, |
| 290 CTOR_FACTORY_NAME=factory_constructor_name, | 290 CTOR_FACTORY_NAME=factory_constructor_name, |
| 291 PARAMS=constructor_info.ParametersDeclaration(self._DartType), | 291 PARAMS=constructor_info.ParametersDeclaration(self._DartType), |
| 292 FACTORY_PARAMS=factory_parameters) | 292 FACTORY_PARAMS=factory_parameters) |
| 293 | 293 |
| 294 for index, param_info in enumerate(constructor_info.param_infos): | 294 for index, param_info in enumerate(constructor_info.param_infos): |
| 295 if param_info.is_optional: | 295 if param_info.is_optional: |
| 296 inits.Emit(' if ($E != null) e.$E = $E;\n', | 296 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name) |
| 297 E=constructor_info.param_infos[index].name) | |
| 298 | 297 |
| 299 if not constructor_info.pure_dart_constructor: | 298 if not constructor_info.pure_dart_constructor: |
| 300 template_file = ('factoryprovider_%s.darttemplate' % self._interface.doc_j
s_name) | 299 template_file = ('factoryprovider_%s.darttemplate' % self._interface.doc_j
s_name) |
| 301 template = self._template_loader.TryLoad(template_file) | 300 template = self._template_loader.TryLoad(template_file) |
| 302 if template: | 301 if template: |
| 303 # There is a class specific factory. | 302 # There is a class specific factory. |
| 304 # TODO(antonm): should move into the class template. | 303 # TODO(antonm): should move into the class template. |
| 305 self._members_emitter.Emit(template) | 304 self._members_emitter.Emit(template) |
| 306 else: | 305 else: |
| 307 self.EmitStaticFactory(constructor_info) | 306 self.EmitStaticFactory(constructor_info) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 walk(interface.parents) | 408 walk(interface.parents) |
| 410 else: | 409 else: |
| 411 walk(interface.parents[1:]) | 410 walk(interface.parents[1:]) |
| 412 return result | 411 return result |
| 413 | 412 |
| 414 def _DartType(self, type_name): | 413 def _DartType(self, type_name): |
| 415 return self._type_registry.DartType(type_name) | 414 return self._type_registry.DartType(type_name) |
| 416 | 415 |
| 417 def _IsPrivate(self, name): | 416 def _IsPrivate(self, name): |
| 418 return name.startswith('_') | 417 return name.startswith('_') |
| OLD | NEW |