Anonymous avatar Anonymous committed 7e5dde7

Calculating refactoring names from class names

Comments (0)

Files changed (2)

ropemacs/__init__.py

                     def do_refactor(prefix, self=self, refactoring=attr):
                         initial_asking = prefix is None
                         refactoring(self).show(initial_asking=initial_asking)
-                    setattr(self, attr.name, do_refactor)
-                    name = 'rope-' + attr.name.replace('_', '-')
+                    name = self._refactoring_name(attr)
+                    setattr(self, name, do_refactor)
+                    name = 'rope-' + name.replace('_', '-')
                     if attr.key.startswith('C-x'):
                         self.global_keys.append((attr.key, lisp[name]))
                     else:
                         self.local_keys.append((attr.key, lisp[name]))
 
+    def _refactoring_name(self, refactoring):
+        return refactor.refactoring_name(refactoring)
+
     def _key_sequence(self, sequence):
         result = []
         for key in sequence.split():

ropemacs/refactor.py

 
 
 class Refactoring(object):
-
-    name = None
     key = None
     confs = {}
     optionals = {}
     def region(self):
         return self.interface._get_region()
 
+    @property
+    def name(self):
+        return refactoring_name(self.__class__)
+
     def _calculate_changes(self, option_values, task_handle):
         pass
 
 
 
 class Rename(Refactoring):
-
-    name = 'rename'
     key = 'C-c r r'
     optionals = {
         'docs': dialog.Data('Rename occurrences in comments and docs: ',
 
 
 class RenameCurrentModule(Rename):
-
-    name = 'rename_current_module'
     key = 'C-c r 1 r'
     offset = None
 
 
 class Restructure(Refactoring):
-
-    name = 'restructure'
     key = 'C-c r x'
     confs = {'pattern': dialog.Data('Restructuring pattern: '),
              'goal': dialog.Data('Restructuring goal: ')}
 
 
 class Move(Refactoring):
-
-    name = 'move'
     key = 'C-c r v'
 
     def _create_refactoring(self):
 
 
 class MoveCurrentModule(Move):
-
-    name = 'move_current_module'
     key = 'C-c r 1 v'
-
     offset = None
 
 
 class ModuleToPackage(Refactoring):
-
-    name = 'module_to_package'
     key = 'C-c r 1 p'
     saveall = False
 
 
 
 class Inline(Refactoring):
-
-    name = 'inline'
     key = 'C-c r i'
     optionals = {'remove': dialog.Data('Remove the definition: ',
                                        values=['yes', 'no'], default='yes'),
 
 
 class _Extract(Refactoring):
-
     saveall = False
     optionals = {'similar': dialog.Data('Extract similar pieces: ',
                                         values=['yes', 'no'], default='yes'),
 
 
 class ExtractVariable(_Extract):
-
-    name = 'extract_variable'
     key = 'C-c r l'
     kind = 'variable'
     constructor = rope.refactor.extract.ExtractVariable
 
 
 class ExtractMethod(_Extract):
-
-    name = 'extract_method'
     key = 'C-c r m'
     kind = 'method'
     constructor = rope.refactor.extract.ExtractMethod
 
 
 class OrganizeImports(Refactoring):
-
-    name = 'organize_imports'
     key = 'C-c r o'
     saveall = False
 
 
 
 class GenerateVariable(_GenerateElement):
-
-    name = 'generate_variable'
     key = 'C-c r n v'
 
 
 class GenerateFunction(_GenerateElement):
-
-    name = 'generate_function'
     key = 'C-c r n f'
 
 
 class GenerateClass(_GenerateElement):
-
-    name = 'generate_class'
     key = 'C-c r n c'
 
 
 class GenerateModule(_GenerateElement):
-
-    name = 'generate_module'
     key = 'C-c r n m'
 
 
 class GeneratePackage(_GenerateElement):
+    key = 'C-c r n p'
 
-    name = 'generate_package'
-    key = 'C-c r n p'
+
+def refactoring_name(refactoring):
+    classname = refactoring.__name__
+    result = []
+    for c in classname:
+        if result and c.isupper():
+            result.append('_')
+        result.append(c.lower())
+    name = ''.join(result)
+    return name
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.