Chromium Code Reviews| 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 systems to generate | 6 """This module provides shared functionality for systems to generate |
| 7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
| 8 | 8 |
| 9 import copy | 9 import copy |
| 10 import json | |
| 11 import os | |
| 10 import re | 12 import re |
| 11 from htmlrenamer import html_interface_renames | 13 from htmlrenamer import html_interface_renames |
| 12 | 14 |
| 15 # Set up json file for retrieving comments. | |
| 16 current_dir = os.path.dirname(__file__) | |
|
blois
2013/01/25 19:16:32
should be private types (_current_dir, etc).
Andrei Mouravski
2013/01/25 19:23:31
Done.
| |
| 17 json_path = os.path.join(current_dir, '..', 'docs', 'docs.json') | |
| 18 dom_json = json.load(open(json_path)) | |
| 19 | |
| 13 _pure_interfaces = set([ | 20 _pure_interfaces = set([ |
| 14 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. | 21 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. |
| 15 'DOMStringMap', | 22 'DOMStringMap', |
| 16 'ElementTimeControl', | 23 'ElementTimeControl', |
| 17 'ElementTraversal', | 24 'ElementTraversal', |
| 18 'EventListener', | 25 'EventListener', |
| 19 'MediaQueryListListener', | 26 'MediaQueryListListener', |
| 20 'MutationCallback', | 27 'MutationCallback', |
| 21 'NodeSelector', | 28 'NodeSelector', |
| 22 'SVGExternalResourcesRequired', | 29 'SVGExternalResourcesRequired', |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 'SpeechRecognitionResult': _speech_recognition_annotations, | 795 'SpeechRecognitionResult': _speech_recognition_annotations, |
| 789 'WebSocket': _all_but_ie9_annotations, | 796 'WebSocket': _all_but_ie9_annotations, |
| 790 'WorkerContext.indexedDB': _indexed_db_annotations, | 797 'WorkerContext.indexedDB': _indexed_db_annotations, |
| 791 'WorkerContext.webkitRequestFileSystem': _file_system_annotations, | 798 'WorkerContext.webkitRequestFileSystem': _file_system_annotations, |
| 792 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations, | 799 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations, |
| 793 'WorkerContext.webkitResolveLocalFileSystemSyncURL': _file_system_annotations, | 800 'WorkerContext.webkitResolveLocalFileSystemSyncURL': _file_system_annotations, |
| 794 'WorkerContext.webkitResolveLocalFileSystemURL': _file_system_annotations, | 801 'WorkerContext.webkitResolveLocalFileSystemURL': _file_system_annotations, |
| 795 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations, | 802 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations, |
| 796 } | 803 } |
| 797 | 804 |
| 798 def FindCommonAnnotations(interface_name, member_name=None): | 805 def GetComments(interface_name, member_name=None, library_name=None): |
| 806 """ Finds all comments for the interface or member and returns a list. """ | |
| 807 | |
| 808 # Add documentation from JSON. | |
| 809 comments = [] | |
| 810 | |
| 811 if library_name in dom_json and interface_name in dom_json[library_name]: | |
| 812 if member_name and (member_name in | |
| 813 dom_json[library_name][interface_name]['members']): | |
| 814 comments = dom_json[library_name][interface_name]['members'][member_name] | |
| 815 elif 'comment' in dom_json[library_name][interface_name]: | |
| 816 comments = dom_json[library_name][interface_name]['comment'] | |
| 817 | |
| 818 return comments | |
| 819 | |
| 820 def GetAnnotationsAndComments(interface_name, member_name=None, | |
| 821 library_name=None): | |
| 822 annotations = GetComments(interface_name, member_name, library_name) | |
| 823 annotations.extend(FindCommonAnnotations(interface_name, member_name, | |
| 824 library_name)) | |
| 825 return annotations | |
| 826 | |
| 827 def FindCommonAnnotations(interface_name, member_name=None, library_name=None): | |
| 799 """ Finds annotations common between dart2js and dartium. | 828 """ Finds annotations common between dart2js and dartium. |
| 800 """ | 829 """ |
| 801 if member_name: | 830 if member_name: |
| 802 key = '%s.%s' % (interface_name, member_name) | 831 key = '%s.%s' % (interface_name, member_name) |
| 803 else: | 832 else: |
| 804 key = interface_name | 833 key = interface_name |
| 805 | 834 |
| 806 annotations = ["@DomName('" + key + "')",] | 835 annotations = ["@DomName('" + key + "')"] |
| 836 | |
| 807 # Only add this for members, so we don't add DocsEditable to templated classes | 837 # Only add this for members, so we don't add DocsEditable to templated classes |
| 808 # (they get it from the default class template) | 838 # (they get it from the default class template) |
| 809 if member_name: | 839 if member_name: |
| 810 annotations.append('@DocsEditable'); | 840 annotations.append('@DocsEditable'); |
| 811 | 841 |
| 812 if (dart_annotations.get(key) != None): | 842 if (dart_annotations.get(key) != None): |
| 813 annotations.extend(dart_annotations.get(key)) | 843 annotations.extend(dart_annotations.get(key)) |
| 814 | 844 |
| 815 return annotations | 845 return annotations |
| 816 | 846 |
| 817 def FindDart2JSAnnotations(idl_type, interface_name, member_name): | 847 def FindDart2JSAnnotationsAndComments(idl_type, interface_name, member_name, |
| 848 library_name=None): | |
| 818 """ Finds all annotations for Dart2JS members- including annotations for | 849 """ Finds all annotations for Dart2JS members- including annotations for |
| 819 both dart2js and dartium. | 850 both dart2js and dartium. |
| 820 """ | 851 """ |
| 821 annotations = FindCommonAnnotations(interface_name, member_name) | 852 annotations = GetAnnotationsAndComments(interface_name, member_name, |
| 853 library_name) | |
| 822 | 854 |
| 823 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name) | 855 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name) |
| 824 if ann2: | 856 if ann2: |
| 825 if annotations: | 857 if annotations: |
| 826 annotations.extend(ann2) | 858 annotations.extend(ann2) |
| 827 else: | 859 else: |
| 828 annotations = ann2 | 860 annotations = ann2 |
| 829 return annotations | 861 return annotations |
| 830 | 862 |
| 831 def AnyConversionAnnotations(idl_type, interface_name, member_name): | 863 def AnyConversionAnnotations(idl_type, interface_name, member_name): |
| 832 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or | 864 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or |
| 833 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)): | 865 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)): |
| 834 return True | 866 return True |
| 835 else: | 867 else: |
| 836 return False | 868 return False |
| 837 | 869 |
| 838 def FormatAnnotations(annotations, indentation): | 870 def FormatAnnotationsAndComments(annotations, indentation): |
| 839 if annotations: | 871 if annotations: |
| 840 newline = '\n%s' % indentation | 872 newline = '\n%s' % indentation |
| 841 result = newline.join(annotations) + newline | 873 result = newline.join(annotations) + newline |
| 842 return result | 874 return result |
| 843 return '' | 875 return '' |
| 844 | 876 |
| 845 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name): | 877 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name): |
| 846 """ Finds dart2js-specific annotations. This does not include ones shared with | 878 """ Finds dart2js-specific annotations. This does not include ones shared with |
| 847 dartium. | 879 dartium. |
| 848 """ | 880 """ |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1389 self) | 1421 self) |
| 1390 | 1422 |
| 1391 if type_data.clazz == 'SVGTearOff': | 1423 if type_data.clazz == 'SVGTearOff': |
| 1392 dart_interface_name = self._renamer.RenameInterface( | 1424 dart_interface_name = self._renamer.RenameInterface( |
| 1393 self._database.GetInterface(type_name)) | 1425 self._database.GetInterface(type_name)) |
| 1394 return SVGTearOffIDLTypeInfo( | 1426 return SVGTearOffIDLTypeInfo( |
| 1395 type_name, type_data, dart_interface_name, self) | 1427 type_name, type_data, dart_interface_name, self) |
| 1396 | 1428 |
| 1397 class_name = '%sIDLTypeInfo' % type_data.clazz | 1429 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1398 return globals()[class_name](type_name, type_data) | 1430 return globals()[class_name](type_name, type_data) |
| OLD | NEW |