| 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 import emitter | 9 import emitter |
| 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 319 |
| 320 def AdditionalImplementedInterfaces(self): | 320 def AdditionalImplementedInterfaces(self): |
| 321 # TODO: Include all implemented interfaces, including other Lists. | 321 # TODO: Include all implemented interfaces, including other Lists. |
| 322 implements = [] | 322 implements = [] |
| 323 if self._interface_type_info.list_item_type(): | 323 if self._interface_type_info.list_item_type(): |
| 324 item_type_info = self._type_registry.TypeInfo( | 324 item_type_info = self._type_registry.TypeInfo( |
| 325 self._interface_type_info.list_item_type()) | 325 self._interface_type_info.list_item_type()) |
| 326 implements.append('List<%s>' % item_type_info.dart_type()) | 326 implements.append('List<%s>' % item_type_info.dart_type()) |
| 327 return implements | 327 return implements |
| 328 | 328 |
| 329 def Mixins(self): |
| 330 mixins = [] |
| 331 if self._interface_type_info.list_item_type(): |
| 332 item_type = self._type_registry.TypeInfo( |
| 333 self._interface_type_info.list_item_type()).dart_type() |
| 334 mixins.append('ListMixin<%s>' % item_type) |
| 335 mixins.append('ImmutableListMixin<%s>' % item_type) |
| 336 |
| 337 return mixins |
| 338 |
| 339 |
| 329 def AddConstructors(self, | 340 def AddConstructors(self, |
| 330 constructors, factory_name, factory_constructor_name): | 341 constructors, factory_name, factory_constructor_name): |
| 331 """ Adds all of the constructors. | 342 """ Adds all of the constructors. |
| 332 Arguments: | 343 Arguments: |
| 333 constructors - List of the constructors to be added. | 344 constructors - List of the constructors to be added. |
| 334 factory_name - Name of the factory for this class. | 345 factory_name - Name of the factory for this class. |
| 335 factory_constructor_name - The name of the constructor on the | 346 factory_constructor_name - The name of the constructor on the |
| 336 factory_name to call (calls an autogenerated FactoryProvider | 347 factory_name to call (calls an autogenerated FactoryProvider |
| 337 if unspecified) | 348 if unspecified) |
| 338 """ | 349 """ |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 '\n' | 528 '\n' |
| 518 ' $TYPE $NAME($PARAMS);\n', | 529 ' $TYPE $NAME($PARAMS);\n', |
| 519 TYPE=return_type_name, | 530 TYPE=return_type_name, |
| 520 NAME=method_name, | 531 NAME=method_name, |
| 521 PARAMS=operation.ParametersDeclaration(self._DartType)) | 532 PARAMS=operation.ParametersDeclaration(self._DartType)) |
| 522 | 533 |
| 523 def EmitListMixin(self, element_name): | 534 def EmitListMixin(self, element_name): |
| 524 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 535 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
| 525 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 536 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
| 526 template_file = 'immutable_list_mixin.darttemplate' | 537 template_file = 'immutable_list_mixin.darttemplate' |
| 527 has_contains = any(op.id == 'contains' for op in self._interface.operations) | |
| 528 has_clear = any(op.id == 'clear' for op in self._interface.operations) | |
| 529 has_length = False | 538 has_length = False |
| 530 has_length_setter = False | 539 has_length_setter = False |
| 531 | 540 |
| 532 for attr in self._interface.attributes: | 541 for attr in self._interface.attributes: |
| 533 if attr.id == 'length': | 542 if attr.id == 'length': |
| 534 has_length = True | 543 has_length = True |
| 535 has_length_setter = not attr.is_read_only | 544 has_length_setter = not attr.is_read_only |
| 536 | 545 |
| 537 has_num_items = any(attr.id == 'numberOfItems' | 546 has_num_items = any(attr.id == 'numberOfItems' |
| 538 for attr in self._interface.attributes) | 547 for attr in self._interface.attributes) |
| 539 | 548 |
| 540 template = self._template_loader.Load( | 549 template = self._template_loader.Load( |
| 541 template_file, | 550 template_file, |
| 542 { | 551 { |
| 543 'DEFINE_CONTAINS': not has_contains, | |
| 544 'DEFINE_CLEAR': not has_clear, | |
| 545 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items, | 552 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items, |
| 546 'DEFINE_LENGTH_SETTER': not has_length_setter, | 553 'DEFINE_LENGTH_SETTER': not has_length_setter, |
| 547 }) | 554 }) |
| 548 self._members_emitter.Emit(template, E=element_name) | 555 self._members_emitter.Emit(template, E=element_name) |
| 549 | 556 |
| 550 def SecureOutputType(self, type_name, is_dart_type=False): | 557 def SecureOutputType(self, type_name, is_dart_type=False): |
| 551 """ Converts the type name to the secure type name for return types. | 558 """ Converts the type name to the secure type name for return types. |
| 552 """ | 559 """ |
| 553 if is_dart_type: | 560 if is_dart_type: |
| 554 dart_name = type_name | 561 dart_name = type_name |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 if interface.parents: | 597 if interface.parents: |
| 591 parent = interface.parents[0] | 598 parent = interface.parents[0] |
| 592 if IsPureInterface(parent.type.id): | 599 if IsPureInterface(parent.type.id): |
| 593 walk(interface.parents) | 600 walk(interface.parents) |
| 594 else: | 601 else: |
| 595 walk(interface.parents[1:]) | 602 walk(interface.parents[1:]) |
| 596 return result | 603 return result |
| 597 | 604 |
| 598 def _DartType(self, type_name): | 605 def _DartType(self, type_name): |
| 599 return self._type_registry.DartType(type_name) | 606 return self._type_registry.DartType(type_name) |
| OLD | NEW |