Allow the use of the "Rename To" annotation for literal method renaming.
authorC. Scott Ananian <cscott@litl.com>
Mon, 27 Apr 2009 14:48:12 +0000 (10:48 -0400)
committerJohan Bilien <jobi@litl.com>
Tue, 12 May 2009 15:00:32 +0000 (16:00 +0100)
As originally implemented, this annotation was only used for method
overloading (argument signature polymorphism).  Allow it to be used to
clean up historically poorly-named methods as well.

giscanner/annotationparser.py

index 30b0eed..5458ee1 100644 (file)
@@ -692,8 +692,21 @@ class AnnotationApplier(object):
             return True
 
         self._namespace.remove_matching(shadowed_filter)
-        assert len(shadowed) == 1
-        node.name = shadowed[0].name
+        if len(shadowed) == 1:
+            # method override; use the same (stripped) name as the overloaded
+            # method referenced.
+            # Note that 'g_timeout_add_full' may specify a new_name of
+            # 'g_timeout_add' but the *real* name desired is the stripped name
+            # of 'g_timeout_add' which is 'timeout_add' (for example).
+            node.name = shadowed[0].name
+        elif len(shadowed) == 0:
+            # literal rename, to force a particular prefix strip or whatever
+            # Example: the "nm-utils" package uses a "NM" prefix in most places
+            # but some functions have an "nm_utils_" prefix; the 'Rename To:'
+            # annotation in this case is used to strip the 'utils_' part off.
+            node.name = new_name
+        else:
+            assert False # more than two shadowed methods?  Shouldn't happen.
 
     def _guess_direction(self, node):
         if node.direction: