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

Unified 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: Incorporating review feedback. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/scripts/generator.py ('k') | sdk/lib/html/scripts/systemhtml.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/scripts/htmlrenamer.py
diff --git a/sdk/lib/html/scripts/htmlrenamer.py b/sdk/lib/html/scripts/htmlrenamer.py
index 3955815ae648db112bc9fac3659a5736b7e78653..9794d09212d3149b03aef5c4f31364d9d98759ac 100644
--- a/sdk/lib/html/scripts/htmlrenamer.py
+++ b/sdk/lib/html/scripts/htmlrenamer.py
@@ -2,6 +2,7 @@
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
+import re
html_interface_renames = {
'DOMCoreException': 'DOMException',
@@ -10,6 +11,9 @@ html_interface_renames = {
'DOMWindow': 'LocalWindow',
'History': 'LocalHistory',
'Location': 'LocalLocation',
+ 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts.
+ 'SVGElement': 'SvgElement', # Manual to avoid name conflicts.
+ 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts.
'WebKitAnimation': 'Animation',
'WebKitAnimationEvent': 'AnimationEvent',
'WebKitBlobBuilder': 'BlobBuilder',
@@ -97,9 +101,9 @@ _renamed_html_members = {
'Node.parentNode': 'parent',
'Node.previousSibling': 'previousNode',
'Node.textContent': 'text',
- 'SVGElement.className': '$dom_svgClassName',
- 'SVGAnimatedString.className': '$dom_svgClassName',
- 'SVGStylable.className': '$dom_svgClassName',
+ 'SvgElement.className': '$dom_svgClassName',
+ 'AnimatedString.className': '$dom_svgClassName',
+ 'Stylable.className': '$dom_svgClassName',
'Url.createObjectURL': 'createObjectUrl',
'Url.revokeObjectURL': 'revokeObjectUrl',
}
@@ -277,7 +281,13 @@ class HtmlRenamer(object):
return interface.id[len('HTML'):]
elif interface.id in html_interface_renames:
return html_interface_renames[interface.id]
- return interface.id
+ return self._DartifyInterface(interface)
+
+ def RenameIDLName(self, name):
+ """
+ Renames an IDL type name which does not have an interface.
+ Normally RenameInterface should be used instead. """
+ return self._DartifyTypeName(name)
def RenameMember(self, interface_name, member_node, member, member_prefix=''):
"""
@@ -311,6 +321,42 @@ class HtmlRenamer(object):
return member_name
def GetLibraryName(self, interface):
- if interface.id.startswith('SVG'):
+ return self._GetLibraryName(interface.id)
+
+ def _GetLibraryName(self, idl_type_name):
+ """
+ Gets the name of the library this type should live in.
+ This is private because this should use interfaces to resolve the library.
+ """
+
+ if idl_type_name.startswith('SVG'):
return 'svg'
return 'html'
+
+ def _DartifyInterface(self, interface):
+ """Gets the Dart-friend class name for an IDL interface. """
+ return self._DartifyTypeName(interface.id)
+
+ def _DartifyTypeName(self, type_name):
+ """Converts a DOM name to a Dart-friendly class name. """
+ library_name = self._GetLibraryName(type_name)
+ # Only renaming SVG for now.
+ if library_name != 'svg':
+ return type_name
+
+ # Strip off the SVG prefix.
+ name = re.sub(r'^SVG', '', type_name)
+
+ def toLower(match):
+ return match.group(1) + match.group(2).lower() + match.group(3)
+
+ # We're looking for a sequence of letters which start with capitol letter
Anton Muhin 2012/11/15 12:11:47 nit: capit<A>l? here and below
blois 2012/11/15 17:30:07 Done.
+ # then a series of caps and finishes with either the end of the string or
+ # a capitol letter.
+ # The [0-9] check is for names such as 2D or 3D
+ # The following test cases should match as:
+ # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue
+ # CanvasRenderingContext2D: CanvasRenderingContext(2)(D)$
+ # XPathNSResolver: XPath(N)(S)(R)esolver
Anton Muhin 2012/11/15 12:11:47 actually also (X)()(P)ath... and (I)()(F)
blois 2012/11/15 17:30:07 Done.
+ # IFrameElement: IFrameElement (no change)
+ return re.sub(r"([A-Z]|[0-9])([A-Z]*)([A-Z]+|$)", toLower, name)
Anton Muhin 2012/11/15 12:11:47 still I do not understand if in group(2) [A-Z]+ ca
Anton Muhin 2012/11/15 12:11:47 I am not sure anyone will like it, but technically
blois 2012/11/15 17:30:07 Good point, done.
blois 2012/11/15 17:30:07 That does work though I find it a bit less readabl
Anton Muhin 2012/11/15 17:49:23 Up to you, Pete On 2012/11/15 17:30:07, blois wro
« 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