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

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

Issue 11419300: Dartifying dart:html type names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
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 import re
6 6
7 html_interface_renames = { 7 html_interface_renames = {
8 'DOMCoreException': 'DOMException', 8 'CDATASection': 'CDataSection',
9 'DOMApplicationCache': 'ApplicationCache',
10 'DOMCoreException': 'DomException',
11 'DOMFileSystem': 'FileSystem',
12 'DOMFileSystemSync': 'FileSystemSync',
9 'DOMFormData': 'FormData', 13 'DOMFormData': 'FormData',
10 'DOMURL': 'Url', 14 'DOMURL': 'Url',
11 'DOMWindow': 'LocalWindow', 15 'DOMWindow': 'LocalWindow',
12 'History': 'LocalHistory', 16 'History': 'LocalHistory',
13 'HTMLDocument' : 'HtmlDocument', 17 'HTMLDocument' : 'HtmlDocument',
18 'IDBFactory': 'IdbFactory', # Manual to avoid name conflicts.
14 'Location': 'LocalLocation', 19 'Location': 'LocalLocation',
15 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts. 20 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts.
16 'SVGElement': 'SvgElement', # Manual to avoid name conflicts. 21 'SVGElement': 'SvgElement', # Manual to avoid name conflicts.
17 'SVGException': 'SvgException', # Manual of avoid conflict with Exception. 22 'SVGException': 'SvgException', # Manual of avoid conflict with Exception.
18 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts. 23 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts.
24 'WebGLVertexArrayObjectOES': 'WebGLVertexArrayObject',
19 'WebKitAnimation': 'Animation', 25 'WebKitAnimation': 'Animation',
20 'WebKitAnimationEvent': 'AnimationEvent', 26 'WebKitAnimationEvent': 'AnimationEvent',
21 'WebKitBlobBuilder': 'BlobBuilder', 27 'WebKitBlobBuilder': 'BlobBuilder',
22 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', 28 'WebKitCSSKeyframeRule': 'CssKeyframeRule',
23 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', 29 'WebKitCSSKeyframesRule': 'CssKeyframesRule',
24 'WebKitCSSMatrix': 'CSSMatrix', 30 'WebKitCSSMatrix': 'CssMatrix',
25 'WebKitCSSTransformValue': 'CSSTransformValue', 31 'WebKitCSSTransformValue': 'CssTransformValue',
26 'WebKitFlags': 'Flags', 32 'WebKitFlags': 'Flags',
27 'WebKitLoseContext': 'LoseContext', 33 'WebKitLoseContext': 'LoseContext',
28 'WebKitPoint': 'Point', 34 'WebKitPoint': 'Point',
29 'WebKitTransitionEvent': 'TransitionEvent', 35 'WebKitTransitionEvent': 'TransitionEvent',
30 'XMLHttpRequest': 'HttpRequest', 36 'XMLHttpRequest': 'HttpRequest',
31 'XMLHttpRequestException': 'HttpRequestException', 37 'XMLHttpRequestException': 'HttpRequestException',
32 'XMLHttpRequestProgressEvent': 'HttpRequestProgressEvent', 38 'XMLHttpRequestProgressEvent': 'HttpRequestProgressEvent',
33 'XMLHttpRequestUpload': 'HttpRequestUpload', 39 'XMLHttpRequestUpload': 'HttpRequestUpload',
34 } 40 }
35 41
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 "Node.get:nodeName", 304 "Node.get:nodeName",
299 "Node.lookupPrefix", 305 "Node.lookupPrefix",
300 "Node.get:PROCESSING_INSTRUCTION_NODE", 306 "Node.get:PROCESSING_INSTRUCTION_NODE",
301 'ShadowRoot.getElementsByTagNameNS', 307 'ShadowRoot.getElementsByTagNameNS',
302 "LocalWindow.blur", 308 "LocalWindow.blur",
303 "LocalWindow.clientInformation", 309 "LocalWindow.clientInformation",
304 "LocalWindow.get:frames", 310 "LocalWindow.get:frames",
305 "LocalWindow.get:length", 311 "LocalWindow.get:length",
306 "LocalWindow.focus", 312 "LocalWindow.focus",
307 "LocalWindow.prompt", 313 "LocalWindow.prompt",
314 "LocalWindow.webkitIndexedDB",
308 "LocalWindow.webkitCancelRequestAnimationFrame", 315 "LocalWindow.webkitCancelRequestAnimationFrame",
309 "WheelEvent.wheelDelta", 316 "WheelEvent.wheelDelta",
317 "WorkerContext.webkitIndexedDB",
310 ]) 318 ])
311 319
312 class HtmlRenamer(object): 320 class HtmlRenamer(object):
313 def __init__(self, database): 321 def __init__(self, database):
314 self._database = database 322 self._database = database
315 323
316 def RenameInterface(self, interface): 324 def RenameInterface(self, interface):
317 if interface.id in html_interface_renames: 325 if interface.id in html_interface_renames:
318 return html_interface_renames[interface.id] 326 return html_interface_renames[interface.id]
319 elif interface.id.startswith('HTML'): 327 elif interface.id.startswith('HTML'):
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 def GetLibraryName(self, interface): 368 def GetLibraryName(self, interface):
361 return self._GetLibraryName(interface.id) 369 return self._GetLibraryName(interface.id)
362 370
363 def _GetLibraryName(self, idl_type_name): 371 def _GetLibraryName(self, idl_type_name):
364 """ 372 """
365 Gets the name of the library this type should live in. 373 Gets the name of the library this type should live in.
366 This is private because this should use interfaces to resolve the library. 374 This is private because this should use interfaces to resolve the library.
367 """ 375 """
368 if idl_type_name.startswith('SVG'): 376 if idl_type_name.startswith('SVG'):
369 return 'svg' 377 return 'svg'
378
379 if idl_type_name.startswith('IDB'):
380 return 'indexed_db'
381
370 if 'Audio' in idl_type_name: 382 if 'Audio' in idl_type_name:
371 return 'web_audio' 383 return 'web_audio'
372 384
373 if self._database.HasInterface(idl_type_name): 385 if self._database.HasInterface(idl_type_name):
374 interface = self._database.GetInterface(idl_type_name) 386 interface = self._database.GetInterface(idl_type_name)
375 for parent in self._database.Hierarchy(interface): 387 for parent in self._database.Hierarchy(interface):
376 if parent.id == 'AudioNode': 388 if parent.id == 'AudioNode':
377 return 'web_audio' 389 return 'web_audio'
378 390
379 return 'html' 391 return 'html'
380 392
381 393
382 def DartifyTypeName(self, type_name): 394 def DartifyTypeName(self, type_name):
383 """Converts a DOM name to a Dart-friendly class name. """ 395 """Converts a DOM name to a Dart-friendly class name. """
384 library_name = self._GetLibraryName(type_name) 396 library_name = self._GetLibraryName(type_name)
385 # Only renaming SVG for now.
386 if library_name != 'svg':
387 return type_name
388 397
389 # Strip off the SVG prefix. 398 # Strip off any SVG prefix.
Emily Fortuna 2012/12/04 01:57:19 remove "SVG" from this line.
blois 2012/12/04 17:35:36 Done.
390 name = re.sub(r'^SVG', '', type_name) 399 name = re.sub(r'^SVG', '', type_name)
400 # Strip off any IDB prefix.
401 name = re.sub(r'^IDB', '', name)
402
391 return self._CamelCaseName(name) 403 return self._CamelCaseName(name)
392 404
393 def _DartifyMemberName(self, member_name): 405 def _DartifyMemberName(self, member_name):
394 # Strip off any OpenGL ES suffixes. 406 # Strip off any OpenGL ES suffixes.
395 name = re.sub(r'OES$', '', member_name) 407 name = re.sub(r'OES$', '', member_name)
396 return self._CamelCaseName(name) 408 return self._CamelCaseName(name)
397 409
398 def _CamelCaseName(self, name): 410 def _CamelCaseName(self, name):
399 411
400 def toLower(match): 412 def toLower(match):
401 return match.group(1) + match.group(2).lower() + match.group(3) 413 return match.group(1) + match.group(2).lower() + match.group(3)
402 414
403 # We're looking for a sequence of letters which start with capital letter 415 # We're looking for a sequence of letters which start with capital letter
404 # then a series of caps and finishes with either the end of the string or 416 # then a series of caps and finishes with either the end of the string or
405 # a capital letter. 417 # a capital letter.
406 # The [0-9] check is for names such as 2D or 3D 418 # The [0-9] check is for names such as 2D or 3D
407 # The following test cases should match as: 419 # The following test cases should match as:
408 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue 420 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue
409 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) 421 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change)
410 # IFrameElement: (I)()(F)rameElement (no change) 422 # IFrameElement: (I)()(F)rameElement (no change)
411 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) 423 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698