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

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

Issue 14855011: Cleanup of DOM classname generation (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/scripts/dartmetadata.py ('k') | no next file » | 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 import logging 5 import logging
6 import monitored 6 import monitored
7 import re 7 import re
8 8
9 typed_array_renames = { 9 typed_array_renames = {
10 'ArrayBuffer': 'ByteBuffer', 10 'ArrayBuffer': 'ByteBuffer',
(...skipping 10 matching lines...) Expand all
21 'Uint32Array': 'Uint32List', 21 'Uint32Array': 'Uint32List',
22 } 22 }
23 23
24 html_interface_renames = monitored.Dict('htmlrenamer.html_interface_renames', 24 html_interface_renames = monitored.Dict('htmlrenamer.html_interface_renames',
25 dict({ 25 dict({
26 'CDATASection': 'CDataSection', 26 'CDATASection': 'CDataSection',
27 'Clipboard': 'DataTransfer', 27 'Clipboard': 'DataTransfer',
28 'Database': 'SqlDatabase', # Avoid conflict with Index DB's Database. 28 'Database': 'SqlDatabase', # Avoid conflict with Index DB's Database.
29 'DatabaseSync': 'SqlDatabaseSync', 29 'DatabaseSync': 'SqlDatabaseSync',
30 'DOMApplicationCache': 'ApplicationCache', 30 'DOMApplicationCache': 'ApplicationCache',
31 'DOMCoreException': 'DomException',
32 'DOMFileSystem': 'FileSystem', 31 'DOMFileSystem': 'FileSystem',
33 'DOMFormData': 'FormData',
34 'DOMPoint': '_DomPoint', 32 'DOMPoint': '_DomPoint',
35 'DOMURL': 'Url',
36 'DOMWindow': 'Window',
37 'EntryCallback': '_EntryCallback', 33 'EntryCallback': '_EntryCallback',
38 'EntriesCallback': '_EntriesCallback', 34 'EntriesCallback': '_EntriesCallback',
39 'ErrorCallback': '_ErrorCallback', 35 'ErrorCallback': '_ErrorCallback',
40 'FileCallback': '_FileCallback', 36 'FileCallback': '_FileCallback',
41 'FileSystemCallback': '_FileSystemCallback', 37 'FileSystemCallback': '_FileSystemCallback',
42 'FileWriterCallback': '_FileWriterCallback', 38 'FileWriterCallback': '_FileWriterCallback',
43 'HTMLDocument' : 'HtmlDocument', 39 'HTMLDocument' : 'HtmlDocument',
44 'IDBFactory': 'IdbFactory', # Manual to avoid name conflicts. 40 'IDBFactory': 'IdbFactory', # Manual to avoid name conflicts.
45 'NamedNodeMap': '_NamedNodeMap', 41 'NamedNodeMap': '_NamedNodeMap',
46 'NavigatorUserMediaErrorCallback': '_NavigatorUserMediaErrorCallback', 42 'NavigatorUserMediaErrorCallback': '_NavigatorUserMediaErrorCallback',
47 'NavigatorUserMediaSuccessCallback': '_NavigatorUserMediaSuccessCallback', 43 'NavigatorUserMediaSuccessCallback': '_NavigatorUserMediaSuccessCallback',
48 'NotificationPermissionCallback': '_NotificationPermissionCallback', 44 'NotificationPermissionCallback': '_NotificationPermissionCallback',
49 'PositionCallback': '_PositionCallback', 45 'PositionCallback': '_PositionCallback',
50 'PositionErrorCallback': '_PositionErrorCallback', 46 'PositionErrorCallback': '_PositionErrorCallback',
51 'RTCDTMFSender': 'RtcDtmfSender', 47 'RTCDTMFSender': 'RtcDtmfSender',
52 'RTCDTMFToneChangeEvent': 'RtcDtmfToneChangeEvent', 48 'RTCDTMFToneChangeEvent': 'RtcDtmfToneChangeEvent',
53 'RTCErrorCallback': '_RtcErrorCallback', 49 'RTCErrorCallback': '_RtcErrorCallback',
54 'RTCSessionDescriptionCallback': '_RtcSessionDescriptionCallback', 50 'RTCSessionDescriptionCallback': '_RtcSessionDescriptionCallback',
55 'StringCallback': '_StringCallback', 51 'StringCallback': '_StringCallback',
56 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts. 52 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts.
57 'SVGElement': 'SvgElement', # Manual to avoid name conflicts. 53 'SVGElement': 'SvgElement', # Manual to avoid name conflicts.
58 'SVGException': 'SvgException', # Manual of avoid conflict with Exception. 54 'SVGException': 'SvgException', # Manual of avoid conflict with Exception.
59 'SVGGradientElement': '_GradientElement', 55 'SVGGradientElement': '_GradientElement',
60 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts. 56 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts.
61 'WebGLVertexArrayObjectOES': 'VertexArrayObject', 57 'WebGLVertexArrayObjectOES': 'VertexArrayObject',
62 'WebKitCSSKeyframeRule': 'CssKeyframeRule',
63 'WebKitCSSKeyframesRule': 'CssKeyframesRule',
64 'WebKitCSSTransformValue': 'CssTransformValue',
65 'XMLHttpRequest': 'HttpRequest', 58 'XMLHttpRequest': 'HttpRequest',
66 'XMLHttpRequestException': 'HttpRequestException', 59 'XMLHttpRequestException': 'HttpRequestException',
67 'XMLHttpRequestProgressEvent': 'HttpRequestProgressEvent', 60 'XMLHttpRequestProgressEvent': 'HttpRequestProgressEvent',
68 'XMLHttpRequestUpload': 'HttpRequestUpload', 61 'XMLHttpRequestUpload': 'HttpRequestUpload',
69 }, **typed_array_renames)) 62 }, **typed_array_renames))
70 63
71 # Interfaces that are suppressed, but need to still exist for Dartium and to 64 # Interfaces that are suppressed, but need to still exist for Dartium and to
72 # properly wrap DOM objects if/when encountered. 65 # properly wrap DOM objects if/when encountered.
73 _removed_html_interfaces = [ 66 _removed_html_interfaces = [
74 'CSSPrimitiveValue', 67 'CSSPrimitiveValue',
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 if 'Callback' in interface.ext_attrs: 635 if 'Callback' in interface.ext_attrs:
643 if interface.id in _removed_html_interfaces: 636 if interface.id in _removed_html_interfaces:
644 return None 637 return None
645 638
646 if interface.id in html_interface_renames: 639 if interface.id in html_interface_renames:
647 return html_interface_renames[interface.id] 640 return html_interface_renames[interface.id]
648 elif interface.id.startswith('HTML'): 641 elif interface.id.startswith('HTML'):
649 if any(interface.id in ['Element', 'Document'] 642 if any(interface.id in ['Element', 'Document']
650 for interface in self._database.Hierarchy(interface)): 643 for interface in self._database.Hierarchy(interface)):
651 return interface.id[len('HTML'):] 644 return interface.id[len('HTML'):]
652 return self.DartifyTypeName(interface.id) 645 return self.DartifyTypeName(interface.javascript_binding_name)
653 646
654 647
655 def RenameMember(self, interface_name, member_node, member, member_prefix='', 648 def RenameMember(self, interface_name, member_node, member, member_prefix='',
656 dartify_name=True): 649 dartify_name=True):
657 """ 650 """
658 Returns the name of the member in the HTML library or None if the member is 651 Returns the name of the member in the HTML library or None if the member is
659 suppressed in the HTML library 652 suppressed in the HTML library
660 """ 653 """
661 interface = self._database.GetInterface(interface_name) 654 interface = self._database.GetInterface(interface_name)
662 655
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 def DartifyTypeName(self, type_name): 733 def DartifyTypeName(self, type_name):
741 """Converts a DOM name to a Dart-friendly class name. """ 734 """Converts a DOM name to a Dart-friendly class name. """
742 735
743 if type_name in html_interface_renames: 736 if type_name in html_interface_renames:
744 return html_interface_renames[type_name] 737 return html_interface_renames[type_name]
745 738
746 # Strip off any standard prefixes. 739 # Strip off any standard prefixes.
747 name = re.sub(r'^SVG', '', type_name) 740 name = re.sub(r'^SVG', '', type_name)
748 name = re.sub(r'^IDB', '', name) 741 name = re.sub(r'^IDB', '', name)
749 name = re.sub(r'^WebGL', '', name) 742 name = re.sub(r'^WebGL', '', name)
743 name = re.sub(r'^WebKit', '', name)
750 744
751 return self._CamelCaseName(name) 745 return self._CamelCaseName(name)
752 746
753 def _DartifyMemberName(self, member_name): 747 def _DartifyMemberName(self, member_name):
754 # Strip off any OpenGL ES suffixes. 748 # Strip off any OpenGL ES suffixes.
755 name = re.sub(r'OES$', '', member_name) 749 name = re.sub(r'OES$', '', member_name)
756 return self._CamelCaseName(name) 750 return self._CamelCaseName(name)
757 751
758 def _CamelCaseName(self, name): 752 def _CamelCaseName(self, name):
759 753
760 def toLower(match): 754 def toLower(match):
761 return match.group(1) + match.group(2).lower() + match.group(3) 755 return match.group(1) + match.group(2).lower() + match.group(3)
762 756
763 # We're looking for a sequence of letters which start with capital letter 757 # We're looking for a sequence of letters which start with capital letter
764 # then a series of caps and finishes with either the end of the string or 758 # then a series of caps and finishes with either the end of the string or
765 # a capital letter. 759 # a capital letter.
766 # The [0-9] check is for names such as 2D or 3D 760 # The [0-9] check is for names such as 2D or 3D
767 # The following test cases should match as: 761 # The following test cases should match as:
768 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue 762 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue
769 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) 763 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change)
770 # IFrameElement: (I)()(F)rameElement (no change) 764 # IFrameElement: (I)()(F)rameElement (no change)
771 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) 765 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name)
OLDNEW
« no previous file with comments | « tools/dom/scripts/dartmetadata.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698