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

Side by Side Diff: sdk/lib/html/scripts/htmlrenamer.py

Issue 11364186: Dartifying SVG library class names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixing svg_1_test typo. Created 8 years, 1 month 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 | « sdk/lib/html/scripts/generator.py ('k') | sdk/lib/html/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 import re
5 6
6 html_interface_renames = { 7 html_interface_renames = {
7 'DOMCoreException': 'DOMException', 8 'DOMCoreException': 'DOMException',
8 'DOMFormData': 'FormData', 9 'DOMFormData': 'FormData',
9 'DOMURL': 'Url', 10 'DOMURL': 'Url',
10 'DOMWindow': 'LocalWindow', 11 'DOMWindow': 'LocalWindow',
11 'History': 'LocalHistory', 12 'History': 'LocalHistory',
12 'Location': 'LocalLocation', 13 'Location': 'LocalLocation',
14 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts.
15 'SVGElement': 'SvgElement', # Manual to avoid name conflicts.
16 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts.
13 'WebKitAnimation': 'Animation', 17 'WebKitAnimation': 'Animation',
14 'WebKitAnimationEvent': 'AnimationEvent', 18 'WebKitAnimationEvent': 'AnimationEvent',
15 'WebKitBlobBuilder': 'BlobBuilder', 19 'WebKitBlobBuilder': 'BlobBuilder',
16 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', 20 'WebKitCSSKeyframeRule': 'CSSKeyframeRule',
17 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', 21 'WebKitCSSKeyframesRule': 'CSSKeyframesRule',
18 'WebKitCSSMatrix': 'CSSMatrix', 22 'WebKitCSSMatrix': 'CSSMatrix',
19 'WebKitCSSTransformValue': 'CSSTransformValue', 23 'WebKitCSSTransformValue': 'CSSTransformValue',
20 'WebKitFlags': 'Flags', 24 'WebKitFlags': 'Flags',
21 'WebKitLoseContext': 'LoseContext', 25 'WebKitLoseContext': 'LoseContext',
22 'WebKitPoint': 'Point', 26 'WebKitPoint': 'Point',
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 _renamed_html_members = { 94 _renamed_html_members = {
91 'Document.defaultView': 'window', 95 'Document.defaultView': 'window',
92 'Element.webkitMatchesSelector' : 'matchesSelector', 96 'Element.webkitMatchesSelector' : 'matchesSelector',
93 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', 97 'Element.scrollIntoViewIfNeeded': 'scrollIntoView',
94 'Node.cloneNode': 'clone', 98 'Node.cloneNode': 'clone',
95 'Node.nextSibling': 'nextNode', 99 'Node.nextSibling': 'nextNode',
96 'Node.ownerDocument': 'document', 100 'Node.ownerDocument': 'document',
97 'Node.parentNode': 'parent', 101 'Node.parentNode': 'parent',
98 'Node.previousSibling': 'previousNode', 102 'Node.previousSibling': 'previousNode',
99 'Node.textContent': 'text', 103 'Node.textContent': 'text',
100 'SVGElement.className': '$dom_svgClassName', 104 'SvgElement.className': '$dom_svgClassName',
101 'SVGAnimatedString.className': '$dom_svgClassName', 105 'AnimatedString.className': '$dom_svgClassName',
102 'SVGStylable.className': '$dom_svgClassName', 106 'Stylable.className': '$dom_svgClassName',
103 'Url.createObjectURL': 'createObjectUrl', 107 'Url.createObjectURL': 'createObjectUrl',
104 'Url.revokeObjectURL': 'revokeObjectUrl', 108 'Url.revokeObjectURL': 'revokeObjectUrl',
105 } 109 }
106 110
107 # Members and classes from the dom that should be removed completely from 111 # Members and classes from the dom that should be removed completely from
108 # dart:html. These could be expressed in the IDL instead but expressing this 112 # dart:html. These could be expressed in the IDL instead but expressing this
109 # as a simple table instead is more concise. 113 # as a simple table instead is more concise.
110 # Syntax is: ClassName.(get\.|set\.)?MemberName 114 # Syntax is: ClassName.(get\.|set\.)?MemberName
111 # Using get: and set: is optional and should only be used when a getter needs 115 # Using get: and set: is optional and should only be used when a getter needs
112 # to be suppressed but not the setter, etc. 116 # to be suppressed but not the setter, etc.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 def __init__(self, database): 274 def __init__(self, database):
271 self._database = database 275 self._database = database
272 276
273 def RenameInterface(self, interface): 277 def RenameInterface(self, interface):
274 if interface.id.startswith('HTML'): 278 if interface.id.startswith('HTML'):
275 if any(interface.id in ['Element', 'Document'] 279 if any(interface.id in ['Element', 'Document']
276 for interface in self._database.Hierarchy(interface)): 280 for interface in self._database.Hierarchy(interface)):
277 return interface.id[len('HTML'):] 281 return interface.id[len('HTML'):]
278 elif interface.id in html_interface_renames: 282 elif interface.id in html_interface_renames:
279 return html_interface_renames[interface.id] 283 return html_interface_renames[interface.id]
280 return interface.id 284 return self._DartifyInterface(interface)
285
286 def RenameIDLName(self, name):
Anton Muhin 2012/11/13 11:37:19 why this indirection?
blois 2012/11/14 17:21:50 I wanted to be explicit that normally RenameInterf
Anton Muhin 2012/11/15 12:11:47 I am not sure it is worth the complication. Darti
287 """ Renames an IDL type name which does not have an interface. """
288 return self._DartifyTypeName(name)
281 289
282 def RenameMember(self, interface_name, member_node, member, member_prefix=''): 290 def RenameMember(self, interface_name, member_node, member, member_prefix=''):
283 """ 291 """
284 Returns the name of the member in the HTML library or None if the member is 292 Returns the name of the member in the HTML library or None if the member is
285 suppressed in the HTML library 293 suppressed in the HTML library
286 """ 294 """
287 interface = self._database.GetInterface(interface_name) 295 interface = self._database.GetInterface(interface_name)
288 296
289 if self._FindMatch(interface, member, member_prefix, _removed_html_members): 297 if self._FindMatch(interface, member, member_prefix, _removed_html_members):
290 return None 298 return None
(...skipping 13 matching lines...) Expand all
304 for interface in self._database.Hierarchy(interface): 312 for interface in self._database.Hierarchy(interface):
305 html_interface_name = self.RenameInterface(interface) 313 html_interface_name = self.RenameInterface(interface)
306 member_name = html_interface_name + '.' + member 314 member_name = html_interface_name + '.' + member
307 if member_name in candidates: 315 if member_name in candidates:
308 return member_name 316 return member_name
309 member_name = html_interface_name + '.' + member_prefix + member 317 member_name = html_interface_name + '.' + member_prefix + member
310 if member_name in candidates: 318 if member_name in candidates:
311 return member_name 319 return member_name
312 320
313 def GetLibraryName(self, interface): 321 def GetLibraryName(self, interface):
314 if interface.id.startswith('SVG'): 322 return self._GetLibraryName(interface.id)
323
324 def _GetLibraryName(self, idl_type_name):
325 """
326 Gets the name of the library this type should live in.
327 This is private because this should use interfaces to resolve the library.
328 """
329
330 if idl_type_name.startswith('SVG'):
315 return 'svg' 331 return 'svg'
316 return 'html' 332 return 'html'
333
334 def _DartifyInterface(self, interface):
335 """Gets the Dart-friend class name for an IDL interface. """
336 return self._DartifyTypeName(interface.id)
337
338 def _DartifyTypeName(self, type_name):
339 """Converts a DOM name to a Dart-friendly class name. """
340 library_name = self._GetLibraryName(type_name)
341 # Only renaming SVG for now.
342 if library_name != 'svg':
343 return type_name
344
345 # Strip off the SVG prefix.
346 name = type_name[3:]
347
348 def toLower(match):
349 inner = match.group(2).lower()
350 prefix = match.group(0)[0 : 1]
351 suffix = match.group(0)[len(inner) + 1 : ]
352 return prefix + inner + suffix
353
354 return re.sub(r"([A-Z]|[0-9])([A-Z]*)([A-Z]+|$)", toLower, name)
Anton Muhin 2012/11/13 11:37:19 do you really need [0-9] here?
Anton Muhin 2012/11/13 11:37:19 this mix of [A-Z]* and [A-Z], how does it work?
Anton Muhin 2012/11/13 11:37:19 if all you want is to change a sequence of caps in
blois 2012/11/14 17:21:50 This catches cases such as 2D and 3D which should
blois 2012/11/14 17:21:50 Added comments to the code.
blois 2012/11/14 17:21:50 I cleaned up the toLower code, makes it a bit more
Anton Muhin 2012/11/15 12:11:47 Thanks for explanation On 2012/11/14 17:21:50, bl
OLDNEW
« no previous file with comments | « sdk/lib/html/scripts/generator.py ('k') | sdk/lib/html/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698