| 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 to provide Dart metadata for | 6 """This module provides shared functionality to provide Dart metadata for |
| 7 DOM APIs. | 7 DOM APIs. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import copy | 10 import copy |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 'DatabaseSync': _web_sql_annotations, | 255 'DatabaseSync': _web_sql_annotations, |
| 256 'DOMApplicationCache': [ | 256 'DOMApplicationCache': [ |
| 257 "@SupportedBrowser(SupportedBrowser.CHROME)", | 257 "@SupportedBrowser(SupportedBrowser.CHROME)", |
| 258 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | 258 "@SupportedBrowser(SupportedBrowser.FIREFOX)", |
| 259 "@SupportedBrowser(SupportedBrowser.IE, '10')", | 259 "@SupportedBrowser(SupportedBrowser.IE, '10')", |
| 260 "@SupportedBrowser(SupportedBrowser.OPERA)", | 260 "@SupportedBrowser(SupportedBrowser.OPERA)", |
| 261 "@SupportedBrowser(SupportedBrowser.SAFARI)", | 261 "@SupportedBrowser(SupportedBrowser.SAFARI)", |
| 262 ], | 262 ], |
| 263 'DOMFileSystem': _file_system_annotations, | 263 'DOMFileSystem': _file_system_annotations, |
| 264 'DOMFileSystemSync': _file_system_annotations, | 264 'DOMFileSystemSync': _file_system_annotations, |
| 265 'DOMPoint': _webkit_experimental_annotations, |
| 265 'DOMWindow.webkitConvertPointFromNodeToPage': _webkit_experimental_annotations
, | 266 'DOMWindow.webkitConvertPointFromNodeToPage': _webkit_experimental_annotations
, |
| 266 'DOMWindow.webkitConvertPointFromPageToNode': _webkit_experimental_annotations
, | 267 'DOMWindow.webkitConvertPointFromPageToNode': _webkit_experimental_annotations
, |
| 267 'DOMWindow.indexedDB': _indexed_db_annotations, | 268 'DOMWindow.indexedDB': _indexed_db_annotations, |
| 268 'DOMWindow.openDatabase': _web_sql_annotations, | 269 'DOMWindow.openDatabase': _web_sql_annotations, |
| 269 'DOMWindow.performance': _performance_annotations, | 270 'DOMWindow.performance': _performance_annotations, |
| 270 'DOMWindow.webkitNotifications': _webkit_experimental_annotations, | 271 'DOMWindow.webkitNotifications': _webkit_experimental_annotations, |
| 271 'DOMWindow.webkitRequestFileSystem': _file_system_annotations, | 272 'DOMWindow.webkitRequestFileSystem': _file_system_annotations, |
| 272 'DOMWindow.webkitResolveLocalFileSystemURL': _file_system_annotations, | 273 'DOMWindow.webkitResolveLocalFileSystemURL': _file_system_annotations, |
| 273 'Element.onwebkitTransitionEnd': _all_but_ie9_annotations, | 274 'Element.onwebkitTransitionEnd': _all_but_ie9_annotations, |
| 274 # Placeholder to add experimental flag, implementation for this is | 275 # Placeholder to add experimental flag, implementation for this is |
| 275 # pending in a separate CL. | 276 # pending in a separate CL. |
| 276 'Element.webkitMatchesSelector': ['@Experimental()'], | 277 'Element.webkitMatchesSelector': ['@Experimental()'], |
| 277 'Element.webkitCreateShadowRoot': [ | 278 'Element.webkitCreateShadowRoot': [ |
| 278 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", | 279 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", |
| 279 "@Experimental", | 280 "@Experimental", |
| 280 ], | 281 ], |
| 281 'Event.clipboardData': _webkit_experimental_annotations, | 282 'Event.clipboardData': _webkit_experimental_annotations, |
| 282 'FormData': _all_but_ie9_annotations, | 283 'DOMFormData': _all_but_ie9_annotations, |
| 283 'HashChangeEvent': [ | 284 'HashChangeEvent': [ |
| 284 "@SupportedBrowser(SupportedBrowser.CHROME)", | 285 "@SupportedBrowser(SupportedBrowser.CHROME)", |
| 285 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | 286 "@SupportedBrowser(SupportedBrowser.FIREFOX)", |
| 286 "@SupportedBrowser(SupportedBrowser.SAFARI)", | 287 "@SupportedBrowser(SupportedBrowser.SAFARI)", |
| 287 ], | 288 ], |
| 288 'History.pushState': _history_annotations, | 289 'History.pushState': _history_annotations, |
| 289 'History.replaceState': _history_annotations, | 290 'History.replaceState': _history_annotations, |
| 290 'HTMLContentElement': _shadow_dom_annotations, | 291 'HTMLContentElement': _shadow_dom_annotations, |
| 291 'HTMLDataListElement': _all_but_ie9_annotations, | 292 'HTMLDataListElement': _all_but_ie9_annotations, |
| 292 'HTMLDetailsElement': _webkit_experimental_annotations, | 293 'HTMLDetailsElement': _webkit_experimental_annotations, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 'SVGFESpotLightElement': _svg_annotations, | 364 'SVGFESpotLightElement': _svg_annotations, |
| 364 'SVGFETileElement': _svg_annotations, | 365 'SVGFETileElement': _svg_annotations, |
| 365 'SVGFETurbulenceElement': _svg_annotations, | 366 'SVGFETurbulenceElement': _svg_annotations, |
| 366 'SVGFilterElement': _svg_annotations, | 367 'SVGFilterElement': _svg_annotations, |
| 367 'SVGForeignObjectElement': _no_ie_annotations, | 368 'SVGForeignObjectElement': _no_ie_annotations, |
| 368 'SVGSetElement': _no_ie_annotations, | 369 'SVGSetElement': _no_ie_annotations, |
| 369 'SQLTransaction': _web_sql_annotations, | 370 'SQLTransaction': _web_sql_annotations, |
| 370 'SQLTransactionSync': _web_sql_annotations, | 371 'SQLTransactionSync': _web_sql_annotations, |
| 371 'WebGLRenderingContext': _webgl_annotations, | 372 'WebGLRenderingContext': _webgl_annotations, |
| 372 'WebKitCSSMatrix': _webkit_experimental_annotations, | 373 'WebKitCSSMatrix': _webkit_experimental_annotations, |
| 373 'WebKitPoint': _webkit_experimental_annotations, | |
| 374 'WebSocket': _all_but_ie9_annotations, | 374 'WebSocket': _all_but_ie9_annotations, |
| 375 'Worker': _all_but_ie9_annotations, | 375 'Worker': _all_but_ie9_annotations, |
| 376 'XMLHttpRequest.onloadend': _all_but_ie9_annotations, | 376 'XMLHttpRequest.onloadend': _all_but_ie9_annotations, |
| 377 'XMLHttpRequest.onprogress': _all_but_ie9_annotations, | 377 'XMLHttpRequest.onprogress': _all_but_ie9_annotations, |
| 378 'XMLHttpRequest.response': _all_but_ie9_annotations, | 378 'XMLHttpRequest.response': _all_but_ie9_annotations, |
| 379 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations, | 379 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations, |
| 380 'XSLTProcessor': [ | 380 'XSLTProcessor': [ |
| 381 "@SupportedBrowser(SupportedBrowser.CHROME)", | 381 "@SupportedBrowser(SupportedBrowser.CHROME)", |
| 382 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | 382 "@SupportedBrowser(SupportedBrowser.FIREFOX)", |
| 383 "@SupportedBrowser(SupportedBrowser.SAFARI)", | 383 "@SupportedBrowser(SupportedBrowser.SAFARI)", |
| 384 ], | 384 ], |
| 385 }) | 385 }) |
| 386 | 386 |
| 387 | 387 |
| 388 class DartMetadata(object): | 388 class DartMetadata(object): |
| 389 def __init__(self, api_status_path, doc_comments_path): | 389 def __init__(self, api_status_path, doc_comments_path): |
| 390 self._api_status_path = api_status_path | 390 self._api_status_path = api_status_path |
| 391 status_file = open(self._api_status_path, 'r+') | 391 status_file = open(self._api_status_path, 'r+') |
| 392 self._types = json.load(status_file) | 392 self._types = json.load(status_file) |
| 393 status_file.close() | 393 status_file.close() |
| 394 | 394 |
| 395 comments_file = open(doc_comments_path, 'r+') | 395 comments_file = open(doc_comments_path, 'r+') |
| 396 self._doc_comments = json.load(comments_file) | 396 self._doc_comments = json.load(comments_file) |
| 397 comments_file.close() | 397 comments_file.close() |
| 398 | 398 |
| 399 def GetFormattedMetadata(self, library_name, interface_name, member_id=None, | 399 def GetFormattedMetadata(self, library_name, interface, member_id=None, |
| 400 indentation=''): | 400 indentation=''): |
| 401 """ Gets all comments and annotations for an interface or member. | 401 """ Gets all comments and annotations for an interface or member. |
| 402 """ | 402 """ |
| 403 return self.FormatMetadata( | 403 return self.FormatMetadata( |
| 404 self.GetMetadata(library_name, interface_name, member_id), | 404 self.GetMetadata(library_name, interface, member_id), |
| 405 indentation) | 405 indentation) |
| 406 | 406 |
| 407 def GetMetadata(self, library_name, interface_name, | 407 def GetMetadata(self, library_name, interface, |
| 408 member_name=None, source_member_name=None): | 408 member_name=None, source_member_name=None): |
| 409 """ Gets all comments and annotations for an interface or member. | 409 """ Gets all comments and annotations for an interface or member. |
| 410 | 410 |
| 411 Args: | 411 Args: |
| 412 source_member_name: If the member is dependent on a different member | 412 source_member_name: If the member is dependent on a different member |
| 413 then this is used to apply the support annotations from the other | 413 then this is used to apply the support annotations from the other |
| 414 member. | 414 member. |
| 415 """ | 415 """ |
| 416 annotations = self._GetComments(library_name, interface_name, member_name) | 416 annotations = self._GetComments(library_name, interface, member_name) |
| 417 annotations = annotations + self._GetCommonAnnotations( | 417 annotations = annotations + self._GetCommonAnnotations( |
| 418 interface_name, member_name, source_member_name) | 418 interface, member_name, source_member_name) |
| 419 | 419 |
| 420 return annotations | 420 return annotations |
| 421 | 421 |
| 422 def GetDart2JSMetadata(self, idl_type, library_name, | 422 def GetDart2JSMetadata(self, idl_type, library_name, |
| 423 interface_name, member_name,): | 423 interface, member_name,): |
| 424 """ Gets all annotations for Dart2JS members- including annotations for | 424 """ Gets all annotations for Dart2JS members- including annotations for |
| 425 both dart2js and dartium. | 425 both dart2js and dartium. |
| 426 """ | 426 """ |
| 427 annotations = self.GetMetadata(library_name, interface_name, member_name) | 427 annotations = self.GetMetadata(library_name, interface, member_name) |
| 428 | 428 |
| 429 ann2 = self._GetDart2JSSpecificAnnotations(idl_type, interface_name, member_
name) | 429 ann2 = self._GetDart2JSSpecificAnnotations(idl_type, interface.id, member_na
me) |
| 430 if ann2: | 430 if ann2: |
| 431 if annotations: | 431 if annotations: |
| 432 annotations.extend(ann2) | 432 annotations.extend(ann2) |
| 433 else: | 433 else: |
| 434 annotations = ann2 | 434 annotations = ann2 |
| 435 return annotations | 435 return annotations |
| 436 | 436 |
| 437 def _GetCommonAnnotations(self, interface_name, member_name=None, | 437 def _GetCommonAnnotations(self, interface, member_name=None, |
| 438 source_member_name=None): | 438 source_member_name=None): |
| 439 if member_name: | 439 if member_name: |
| 440 key = '%s.%s' % (interface_name, member_name) | 440 key = '%s.%s' % (interface.id, member_name) |
| 441 dom_name = '%s.%s' % (interface.javascript_binding_name, member_name) |
| 441 else: | 442 else: |
| 442 key = interface_name | 443 key = interface.id |
| 444 dom_name = interface.javascript_binding_name |
| 443 | 445 |
| 444 annotations = ["@DomName('" + key + "')"] | 446 annotations = ["@DomName('" + dom_name + "')"] |
| 445 | 447 |
| 446 # Only add this for members, so we don't add DocsEditable to templated | 448 # Only add this for members, so we don't add DocsEditable to templated |
| 447 # classes (they get it from the default class template) | 449 # classes (they get it from the default class template) |
| 448 if member_name: | 450 if member_name: |
| 449 annotations.append('@DocsEditable'); | 451 annotations.append('@DocsEditable'); |
| 450 | 452 |
| 451 if key in _annotations: | 453 if key in _annotations: |
| 452 annotations.extend(_annotations[key]) | 454 annotations.extend(_annotations[key]) |
| 453 | 455 |
| 454 if (not member_name and interface_name.startswith('WebKit') and | 456 if (not member_name and |
| 455 interface_name not in html_interface_renames): | 457 interface.javascript_binding_name.startswith('WebKit') and |
| 458 interface.id not in html_interface_renames): |
| 456 annotations.extend(_webkit_experimental_annotations) | 459 annotations.extend(_webkit_experimental_annotations) |
| 457 | 460 |
| 458 if (member_name and member_name.startswith('webkit') and | 461 if (member_name and member_name.startswith('webkit') and |
| 459 key not in renamed_html_members): | 462 key not in renamed_html_members): |
| 460 annotations.extend(_webkit_experimental_annotations) | 463 annotations.extend(_webkit_experimental_annotations) |
| 461 | 464 |
| 462 if source_member_name: | 465 if source_member_name: |
| 463 member_name = source_member_name | 466 member_name = source_member_name |
| 464 | 467 |
| 465 # TODO(blois): Emit support level annotations | 468 # TODO(blois): Emit support level annotations |
| 466 self._GetSupportLevelAnnotation(interface_name, member_name) | 469 self._GetSupportLevelAnnotation(interface.id, member_name) |
| 467 | 470 |
| 468 return annotations | 471 return annotations |
| 469 | 472 |
| 470 def _GetComments(self, library_name, interface_name, member_name=None): | 473 def _GetComments(self, library_name, interface, member_name=None): |
| 471 """ Gets all comments for the interface or member and returns a list. """ | 474 """ Gets all comments for the interface or member and returns a list. """ |
| 472 | 475 |
| 473 # Add documentation from JSON. | 476 # Add documentation from JSON. |
| 474 comments = [] | 477 comments = [] |
| 475 library_name = 'dart.dom.%s' % library_name | 478 library_name = 'dart.dom.%s' % library_name |
| 476 if library_name in self._doc_comments: | 479 if library_name in self._doc_comments: |
| 477 library_info = self._doc_comments[library_name] | 480 library_info = self._doc_comments[library_name] |
| 478 if interface_name in library_info: | 481 if interface.id in library_info: |
| 479 interface_info = library_info[interface_name] | 482 interface_info = library_info[interface.id] |
| 480 if member_name: | 483 if member_name: |
| 481 if 'members' in interface_info and member_name in interface_info['memb
ers']: | 484 if 'members' in interface_info and member_name in interface_info['memb
ers']: |
| 482 comments = interface_info['members'][member_name] | 485 comments = interface_info['members'][member_name] |
| 483 elif 'comment' in interface_info: | 486 elif 'comment' in interface_info: |
| 484 comments = interface_info['comment'] | 487 comments = interface_info['comment'] |
| 485 | 488 |
| 486 if comments: | 489 if comments: |
| 487 comments = ['\n'.join(comments)] | 490 comments = ['\n'.join(comments)] |
| 488 | 491 |
| 489 return comments | 492 return comments |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 return | 572 return |
| 570 elif support_level == 'deprecated': | 573 elif support_level == 'deprecated': |
| 571 return '@Deprecated' | 574 return '@Deprecated' |
| 572 else: | 575 else: |
| 573 _logger.warn('Unknown support_level - %s:%s' % (interface.id, member_id)) | 576 _logger.warn('Unknown support_level - %s:%s' % (interface.id, member_id)) |
| 574 | 577 |
| 575 def Flush(self): | 578 def Flush(self): |
| 576 json_file = open(self._api_status_path, 'w+') | 579 json_file = open(self._api_status_path, 'w+') |
| 577 json.dump(self._types, json_file, indent=2, separators=(',', ': '), sort_key
s=True) | 580 json.dump(self._types, json_file, indent=2, separators=(',', ': '), sort_key
s=True) |
| 578 json_file.close() | 581 json_file.close() |
| OLD | NEW |