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..841aeb612da596744cf969cf5f2f0ba6beae5630 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,11 @@ 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): |
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
|
+ """ Renames an IDL type name which does not have an interface. """ |
+ return self._DartifyTypeName(name) |
def RenameMember(self, interface_name, member_node, member, member_prefix=''): |
""" |
@@ -311,6 +319,36 @@ 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 = type_name[3:] |
+ |
+ def toLower(match): |
+ inner = match.group(2).lower() |
+ prefix = match.group(0)[0 : 1] |
+ suffix = match.group(0)[len(inner) + 1 : ] |
+ return prefix + inner + suffix |
+ |
+ 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
|