Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: tools/dom/scripts/dartmetadata.py

Issue 15074006: Generating annotations from DOM triage list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/dom/dom.json ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 'XMLHttpRequest.overrideMimeType': _no_ie_annotations, 385 'XMLHttpRequest.overrideMimeType': _no_ie_annotations,
386 'XMLHttpRequest.response': _all_but_ie9_annotations, 386 'XMLHttpRequest.response': _all_but_ie9_annotations,
387 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations, 387 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations,
388 'XSLTProcessor': [ 388 'XSLTProcessor': [
389 "@SupportedBrowser(SupportedBrowser.CHROME)", 389 "@SupportedBrowser(SupportedBrowser.CHROME)",
390 "@SupportedBrowser(SupportedBrowser.FIREFOX)", 390 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
391 "@SupportedBrowser(SupportedBrowser.SAFARI)", 391 "@SupportedBrowser(SupportedBrowser.SAFARI)",
392 ], 392 ],
393 }) 393 })
394 394
395 # TODO(blois): minimize noise and enable by default.
396 _monitor_type_metadata = False
395 397
396 class DartMetadata(object): 398 class DartMetadata(object):
397 def __init__(self, api_status_path, doc_comments_path): 399 def __init__(self, api_status_path, doc_comments_path):
398 self._api_status_path = api_status_path 400 self._api_status_path = api_status_path
399 status_file = open(self._api_status_path, 'r+') 401 status_file = open(self._api_status_path, 'r+')
400 self._types = json.load(status_file) 402 self._types = json.load(status_file)
401 status_file.close() 403 status_file.close()
402 404
403 comments_file = open(doc_comments_path, 'r+') 405 comments_file = open(doc_comments_path, 'r+')
404 self._doc_comments = json.load(comments_file) 406 self._doc_comments = json.load(comments_file)
405 comments_file.close() 407 comments_file.close()
406 408
409 if _monitor_type_metadata:
410 monitored_interfaces = {}
411 for interface_id, interface_data in self._types.iteritems():
412 monitored_interface = interface_data.copy()
413 monitored_interface['members'] = monitored.Dict(
414 'dartmetadata.%s' % interface_id, interface_data['members'])
415
416 monitored_interfaces[interface_id] = monitored_interface
417
418 self._monitored_types = monitored.Dict('dartmetadata._monitored_types',
419 monitored_interfaces)
420 else:
421 self._monitored_types = self._types
422
407 def GetFormattedMetadata(self, library_name, interface, member_id=None, 423 def GetFormattedMetadata(self, library_name, interface, member_id=None,
408 indentation=''): 424 indentation=''):
409 """ Gets all comments and annotations for an interface or member. 425 """ Gets all comments and annotations for an interface or member.
410 """ 426 """
411 return self.FormatMetadata( 427 return self.FormatMetadata(
412 self.GetMetadata(library_name, interface, member_id), 428 self.GetMetadata(library_name, interface, member_id),
413 indentation) 429 indentation)
414 430
415 def GetMetadata(self, library_name, interface, 431 def GetMetadata(self, library_name, interface,
416 member_name=None, source_member_name=None): 432 member_name=None, source_member_name=None):
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 interface.id not in html_interface_renames): 482 interface.id not in html_interface_renames):
467 annotations.extend(_webkit_experimental_annotations) 483 annotations.extend(_webkit_experimental_annotations)
468 484
469 if (member_name and member_name.startswith('webkit') and 485 if (member_name and member_name.startswith('webkit') and
470 key not in renamed_html_members): 486 key not in renamed_html_members):
471 annotations.extend(_webkit_experimental_annotations) 487 annotations.extend(_webkit_experimental_annotations)
472 488
473 if source_member_name: 489 if source_member_name:
474 member_name = source_member_name 490 member_name = source_member_name
475 491
476 # TODO(blois): Emit support level annotations 492 support_annotations = self._GetSupportLevelAnnotations(
477 self._GetSupportLevelAnnotation(interface.id, member_name) 493 interface.id, member_name)
494
495 for annotation in support_annotations:
496 if annotation not in annotations:
497 annotations.append(annotation)
478 498
479 return annotations 499 return annotations
480 500
481 def _GetComments(self, library_name, interface, member_name=None): 501 def _GetComments(self, library_name, interface, member_name=None):
482 """ Gets all comments for the interface or member and returns a list. """ 502 """ Gets all comments for the interface or member and returns a list. """
483 503
484 # Add documentation from JSON. 504 # Add documentation from JSON.
485 comments = [] 505 comments = []
486 library_name = 'dart.dom.%s' % library_name 506 library_name = 'dart.dom.%s' % library_name
487 if library_name in self._doc_comments: 507 if library_name in self._doc_comments:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 if ann2: 547 if ann2:
528 return ann2 + ann1 548 return ann2 + ann1
529 return ann1 549 return ann1
530 550
531 ann2 = _dart2js_annotations.get('-' + idl_type) 551 ann2 = _dart2js_annotations.get('-' + idl_type)
532 if ann2: 552 if ann2:
533 return ann2 553 return ann2
534 ann2 = _dart2js_annotations.get(idl_type) 554 ann2 = _dart2js_annotations.get(idl_type)
535 return ann2 555 return ann2
536 556
537 def _GetSupportLevel(self, interface_id, member_id=None): 557 def _GetSupportInfo(self, interface_id, member_id=None):
538 """ Looks up the interface or member in the DOM status list and returns the 558 """ Looks up the interface or member in the DOM status list and returns the
539 support level for it. 559 support level for it.
540 """ 560 """
541 if interface_id in self._types: 561 if interface_id in self._monitored_types:
542 type_info = self._types[interface_id] 562 type_info = self._monitored_types[interface_id]
543 else: 563 else:
544 type_info = { 564 type_info = {
545 'members': {}, 565 'members': {},
546 'support_level': 'untriaged', 566 'support_level': 'untriaged',
547 } 567 }
548 self._types[interface_id] = type_info 568 self._types[interface_id] = type_info
549 569
550 if not member_id: 570 if not member_id:
551 return type_info.get('support_level') 571 return type_info
552 572
553 members = type_info['members'] 573 members = type_info['members']
554 574
555 if member_id in members: 575 if member_id in members:
556 member_info = members[member_id] 576 member_info = members[member_id]
557 else: 577 else:
558 if member_id == interface_id: 578 if member_id == interface_id:
559 member_info = {} 579 member_info = {}
560 else: 580 else:
561 member_info = {'support_level': 'untriaged'} 581 member_info = {'support_level': 'untriaged'}
562 members[member_id] = member_info 582 members[member_id] = member_info
563 583
564 support_level = member_info.get('support_level') 584 return member_info
565 # If unset then it inherits from the type.
566 if not support_level:
567 support_level = type_info.get('support_level')
568 return support_level
569 585
570 def _GetSupportLevelAnnotation(self, interface_id, member_id=None): 586 def _GetSupportLevelAnnotations(self, interface_id, member_id=None):
571 support_level = self._GetSupportLevel(interface_id, member_id) 587 """ Gets annotations for API support status.
588 """
589 support_info = self._GetSupportInfo(interface_id, member_id)
572 590
573 if support_level == 'untriaged': 591 dart_action = support_info.get('dart_action')
574 return '@Experimental' 592 support_level = support_info.get('support_level')
593 comment = support_info.get('comment')
594 annotations = []
595 # TODO(blois): should add an annotation for the comment, but keeping out
596 # to keep the initial diff a bit more localized.
597 #if comment:
598 # annotations.append('// %s' % comment)
599
600 if dart_action:
601 if dart_action == 'unstable':
602 annotations.append('@Unstable')
603 elif dart_action == 'experimental':
604 if comment:
605 annotations.append('// %s' % comment)
606 annotations.append('@Experimental // %s' % support_level)
607 elif dart_action == 'suppress':
608 if comment:
609 annotations.append('// %s' % comment)
610 annotations.append('@deprecated // %s' % support_level)
611 # TODO (blois): suppress generation of these APIs as a separate CL.
612 pass
613 else:
614 _logger.warn('Unknown dart_action - %s:%s' % (interface_id, member_id))
615 elif support_level == 'untriaged':
616 annotations.append('@Experimental // untriaged')
575 elif support_level == 'experimental': 617 elif support_level == 'experimental':
576 return '@Experimental' 618 if comment:
619 annotations.append('// %s' % comment)
620 annotations.append('@Experimental')
577 elif support_level == 'nonstandard': 621 elif support_level == 'nonstandard':
578 return '@Experimental' 622 if comment:
623 annotations.append('// %s' % comment)
624 annotations.append('@Experimental // non-standard')
579 elif support_level == 'stable': 625 elif support_level == 'stable':
580 return 626 pass
581 elif support_level == 'deprecated': 627 elif support_level == 'deprecated':
582 return '@Deprecated' 628 if comment:
629 annotations.append('// %s' % comment)
630 annotations.append('@Deprecated')
631 elif support_level is None:
632 pass
583 else: 633 else:
584 _logger.warn('Unknown support_level - %s:%s' % (interface_id, member_id)) 634 _logger.warn('Unknown support_level - %s:%s' % (interface_id, member_id))
585 635
636 return annotations
637
586 def Flush(self): 638 def Flush(self):
587 json_file = open(self._api_status_path, 'w+') 639 json_file = open(self._api_status_path, 'w+')
588 json.dump(self._types, json_file, indent=2, separators=(',', ': '), sort_key s=True) 640 json.dump(self._types, json_file, indent=2, separators=(',', ': '), sort_key s=True)
589 json_file.close() 641 json_file.close()
OLDNEW
« no previous file with comments | « tools/dom/dom.json ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698