| 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 19 matching lines...) Expand all Loading... |
| 30 self._renamer = options.renamer | 30 self._renamer = options.renamer |
| 31 | 31 |
| 32 def EmitSupportCheck(self): | 32 def EmitSupportCheck(self): |
| 33 if self.HasSupportCheck(): | 33 if self.HasSupportCheck(): |
| 34 support_check = self.GetSupportCheck() | 34 support_check = self.GetSupportCheck() |
| 35 self._members_emitter.Emit('\n' | 35 self._members_emitter.Emit('\n' |
| 36 ' /// Checks if this type is supported on the current platform.\n' | 36 ' /// Checks if this type is supported on the current platform.\n' |
| 37 ' static bool get supported => $SUPPORT_CHECK;\n', | 37 ' static bool get supported => $SUPPORT_CHECK;\n', |
| 38 SUPPORT_CHECK=support_check) | 38 SUPPORT_CHECK=support_check) |
| 39 | 39 |
| 40 def EmitAttributeDocumentation(self, attribute): | |
| 41 """ Emits the MDN dartdoc comment for an attribute. | |
| 42 """ | |
| 43 | |
| 44 dom_name = DartDomNameOfAttribute(attribute) | |
| 45 | |
| 46 annotations = FindCommonAnnotations(dom_name) | |
| 47 annotations_str = '' | |
| 48 if annotations: | |
| 49 annotations_str = '\n' + '\n'.join(annotations) | |
| 50 self._members_emitter.Emit('\n /// @docsEditable true', | |
| 51 DOMINTERFACE=attribute.doc_js_interface_name, | |
| 52 ANNOTATIONS=annotations) | |
| 53 | |
| 54 def EmitOperationDocumentation(self, operation): | |
| 55 """ Emits the MDN dartdoc comment for an operation. | |
| 56 """ | |
| 57 | |
| 58 annotations = FindCommonAnnotations(operation.name) | |
| 59 annotations_str = '' | |
| 60 if annotations: | |
| 61 annotations_str = '\n' + '\n'.join(annotations) | |
| 62 self._members_emitter.Emit('\n /// @docsEditable true', | |
| 63 DOMINTERFACE=operation.overloads[0].doc_js_interface_name, | |
| 64 ANNOTATIONS=annotations) | |
| 65 | |
| 66 def EmitEventGetter(self, events_class_name): | 40 def EmitEventGetter(self, events_class_name): |
| 67 self._members_emitter.Emit( | 41 self._members_emitter.Emit( |
| 68 "\n /// @docsEditable true" | 42 "\n @DocsEditable" |
| 69 "\n @DomName('EventTarget.addEventListener, " | 43 "\n @DomName('EventTarget.addEventListener, " |
| 70 "EventTarget.removeEventListener, EventTarget.dispatchEvent')" | 44 "EventTarget.removeEventListener, EventTarget.dispatchEvent')" |
| 71 "\n $TYPE get on =>\n new $TYPE(this);\n", | 45 "\n $TYPE get on =>\n new $TYPE(this);\n", |
| 72 TYPE=events_class_name) | 46 TYPE=events_class_name) |
| 73 | 47 |
| 74 def AddMembers(self, interface, declare_only=False): | 48 def AddMembers(self, interface, declare_only=False): |
| 75 for const in sorted(interface.constants, ConstantOutputOrder): | 49 for const in sorted(interface.constants, ConstantOutputOrder): |
| 76 self.AddConstant(const) | 50 self.AddConstant(const) |
| 77 | 51 |
| 78 for attr in sorted(interface.attributes, ConstantOutputOrder): | 52 for attr in sorted(interface.attributes, ConstantOutputOrder): |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 '\n' | 269 '\n' |
| 296 ' factory $CTOR.fromBuffer(ArrayBuffer buffer, ' | 270 ' factory $CTOR.fromBuffer(ArrayBuffer buffer, ' |
| 297 '[int byteOffset, int length]) => \n' | 271 '[int byteOffset, int length]) => \n' |
| 298 ' $FACTORY.create$(CTOR)_fromBuffer(buffer, byteOffset, length);\n'
, | 272 ' $FACTORY.create$(CTOR)_fromBuffer(buffer, byteOffset, length);\n'
, |
| 299 CTOR=self._interface.id, | 273 CTOR=self._interface.id, |
| 300 TYPE=self._DartType(typed_array_type), | 274 TYPE=self._DartType(typed_array_type), |
| 301 FACTORY=factory_name) | 275 FACTORY=factory_name) |
| 302 | 276 |
| 303 def _AddConstructor(self, | 277 def _AddConstructor(self, |
| 304 constructor_info, factory_name, factory_constructor_name): | 278 constructor_info, factory_name, factory_constructor_name): |
| 305 self._members_emitter.Emit('\n /// @docsEditable true'); | 279 self._members_emitter.Emit('\n @DocsEditable'); |
| 306 | 280 |
| 307 if not factory_constructor_name: | 281 if not factory_constructor_name: |
| 308 factory_constructor_name = '_create' | 282 factory_constructor_name = '_create' |
| 309 factory_parameters = constructor_info.ParametersAsArgumentList() | 283 factory_parameters = constructor_info.ParametersAsArgumentList() |
| 310 has_factory_provider = True | 284 has_factory_provider = True |
| 311 else: | 285 else: |
| 312 factory_parameters = ', '.join(constructor_info.factory_parameters) | 286 factory_parameters = ', '.join(constructor_info.factory_parameters) |
| 313 has_factory_provider = False | 287 has_factory_provider = False |
| 314 | 288 |
| 315 has_optional = any(param_info.is_optional | 289 has_optional = any(param_info.is_optional |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 341 |
| 368 if not constructor_info.pure_dart_constructor: | 342 if not constructor_info.pure_dart_constructor: |
| 369 self.EmitStaticFactory(constructor_info) | 343 self.EmitStaticFactory(constructor_info) |
| 370 | 344 |
| 371 def EmitHelpers(self, base_class): | 345 def EmitHelpers(self, base_class): |
| 372 pass | 346 pass |
| 373 | 347 |
| 374 def DeclareAttribute(self, attribute, type_name, attr_name, read_only): | 348 def DeclareAttribute(self, attribute, type_name, attr_name, read_only): |
| 375 """ Declares an attribute but does not include the code to invoke it. | 349 """ Declares an attribute but does not include the code to invoke it. |
| 376 """ | 350 """ |
| 377 self.EmitAttributeDocumentation(attribute) | |
| 378 if read_only: | 351 if read_only: |
| 379 template = '\n $TYPE get $NAME;\n' | 352 template = '\n $TYPE get $NAME;\n' |
| 380 else: | 353 else: |
| 381 template = '\n $TYPE $NAME;\n' | 354 template = '\n $TYPE $NAME;\n' |
| 382 | 355 |
| 383 self._members_emitter.Emit(template, | 356 self._members_emitter.Emit(template, |
| 384 NAME=attr_name, | 357 NAME=attr_name, |
| 385 TYPE=type_name) | 358 TYPE=type_name) |
| 386 | 359 |
| 387 def DeclareOperation(self, operation, return_type_name, method_name): | 360 def DeclareOperation(self, operation, return_type_name, method_name): |
| 388 """ Declares an operation but does not include the code to invoke it. | 361 """ Declares an operation but does not include the code to invoke it. |
| 389 Arguments: | 362 Arguments: |
| 390 operation - The operation to be declared. | 363 operation - The operation to be declared. |
| 391 return_type_name - The name of the return type. | 364 return_type_name - The name of the return type. |
| 392 method_name - The name of the method. | 365 method_name - The name of the method. |
| 393 """ | 366 """ |
| 394 self.EmitOperationDocumentation(operation) | |
| 395 self._members_emitter.Emit( | 367 self._members_emitter.Emit( |
| 396 '\n' | 368 '\n' |
| 397 ' $TYPE $NAME($PARAMS);\n', | 369 ' $TYPE $NAME($PARAMS);\n', |
| 398 TYPE=return_type_name, | 370 TYPE=return_type_name, |
| 399 NAME=method_name, | 371 NAME=method_name, |
| 400 PARAMS=operation.ParametersDeclaration(self._DartType)) | 372 PARAMS=operation.ParametersDeclaration(self._DartType)) |
| 401 | 373 |
| 402 def EmitListMixin(self, element_name): | 374 def EmitListMixin(self, element_name): |
| 403 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 375 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
| 404 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 376 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 walk(interface.parents) | 443 walk(interface.parents) |
| 472 else: | 444 else: |
| 473 walk(interface.parents[1:]) | 445 walk(interface.parents[1:]) |
| 474 return result | 446 return result |
| 475 | 447 |
| 476 def _DartType(self, type_name): | 448 def _DartType(self, type_name): |
| 477 return self._type_registry.DartType(type_name) | 449 return self._type_registry.DartType(type_name) |
| 478 | 450 |
| 479 def _IsPrivate(self, name): | 451 def _IsPrivate(self, name): |
| 480 return name.startswith('_') | 452 return name.startswith('_') |
| OLD | NEW |