コード例 #1
0
ファイル: refactor.py プロジェクト: Szkered/dotfiles-1
class Restructure(Refactoring):
    key = 'x'
    confs = {'pattern': dialog.Data('Restructuring pattern: '),
             'goal': dialog.Data('Restructuring goal: ')}

    def _calculate_changes(self, values, task_handle):
        restructuring = rope.refactor.restructure.Restructure(
            self.project, values['pattern'], values['goal'],
            args=values['args'], imports=values['imports'])
        return restructuring.get_changes(resources=values['resources'],
                                         task_handle=task_handle)

    def _get_optionals(self):
        return {
            'args': dialog.Data('Arguments: ', decode=self._decode_args),
            'imports': dialog.Data('Imports: ', decode=self._decode_imports),
            'resources': self.resources_option}

    def _decode_args(self, value):
        if value:
            args = {}
            for raw_check in value.split('\n'):
                if raw_check:
                    key, value = raw_check.split(':', 1)
                    args[key.strip()] = value.strip()
            return args

    def _decode_imports(self, value):
        if value:
            return [line.strip() for line in value.split('\n')]
コード例 #2
0
 def test_skipping_blanks(self):
     optionals = {'name1': dialog.Data(), 'name2': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', '\nname1\n value1\n\nname2 value2\n\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name1': 'value1\n', 'name2': 'value2'}, result)
     self.assertEquals('done', action)
コード例 #3
0
 def test_batchset_multiple_sets(self):
     optionals = {'name1': dialog.Data(), 'name2': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', 'name1 value1\nname2 value2', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name1': 'value1', 'name2': 'value2'}, result)
     self.assertEqual('done', action)
コード例 #4
0
 def find_occurrences(self):
     optionals = {
         'unsure': dialog.Data('Find uncertain occurrences: ',
                               default='no', values=['yes', 'no']),
         'resources': dialog.Data('Files to search: '),
         'in_hierarchy': dialog.Data(
                 'Rename methods in class hierarchy: ',
                 default='no', values=['yes', 'no'])}
     def get_kwds(values):
         return {'unsure': values.get('unsure') == 'yes',
                 'in_hierarchy': values.get('in_hierarchy') == 'yes'}
     self._base_findit(findit.find_occurrences, optionals, get_kwds)
コード例 #5
0
 def _create(self, name, callback, parentname='source'):
     self._check_project()
     confs = {'name': dialog.Data(name.title() + ' name: ')}
     parentname = parentname + 'folder'
     optionals = {parentname: dialog.Data(
             parentname.title() + ' Folder: ',
             default=self.project.address, kind='directory')}
     action, values = dialog.show_dialog(
         self._askdata, ['perform', 'cancel'], confs, optionals)
     if action == 'perform':
         parent = libutils.path_to_resource(
             self.project, values.get(parentname, self.project.address))
         resource = callback(parent, values['name'])
         if resource:
             self.env.find_file(resource.real_path)
コード例 #6
0
ファイル: refactor.py プロジェクト: Szkered/dotfiles-1
 def _get_confs(self):
     args = []
     for arg, default in self._get_args():
         args.append(arg)
     signature = '(' + ', '.join(args) + ')'
     return {'signature': dialog.Data('Change the signature: ',
                                      default=signature)}
コード例 #7
0
ファイル: interface.py プロジェクト: k-anderson/emacs
    def find_implementations(self):
        optionals = {'resources': dialog.Data('Files to search: ')}

        def get_kwds(values):
            return {}

        self._base_findit(findit.find_implementations, optionals, get_kwds)
コード例 #8
0
 def test_optional_confs2(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['name', 'value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name': 'value'}, result)
     self.assertEqual('done', action)
コード例 #9
0
 def test_trivial_batchset(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['batchset', 'name value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name': 'value'}, result)
     self.assertEquals('done', action)
コード例 #10
0
 def test_asking_normal_configs(self):
     confs = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         confs)
     self.assertEquals({'name': 'value'}, result)
     self.assertEquals('done', action)
コード例 #11
0
 def test_optional_confs(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals(None, result.get('name', None))
     self.assertEquals('done', action)
コード例 #12
0
 def test_ignoring_trailing_colon_in_config_names(self):
     optionals = {'name1': dialog.Data()}
     minibuffer = _MockAskConfig(['batchset', 'name1: value1\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name1': 'value1'}, result)
     self.assertEquals('done', action)
コード例 #13
0
 def test_multiline_sets(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', 'name\n line1\n  line2\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name': 'line1\n line2\n'}, result)
     self.assertEquals('done', action)
コード例 #14
0
 def _get_confs(self):
     if isinstance(self.mover, rope.refactor.move.MoveGlobal):
         prompt = 'Destination module: '
     if isinstance(self.mover, rope.refactor.move.MoveModule):
         prompt = 'Destination package: '
     if isinstance(self.mover, rope.refactor.move.MoveMethod):
         prompt = 'Destination attribute: '
     return {'destination': dialog.Data(prompt)}
コード例 #15
0
 def test_skip_initial_asking(self):
     confs = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['name', 'value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         confs=confs,
                                         initial_asking=False)
     self.assertEquals({'name': 'value'}, result)
     self.assertEquals('done', action)
コード例 #16
0
 def test_complex_batchset(self):
     optionals = {
         'name1': dialog.Data(),
         'name2': dialog.Data(),
         'name3': dialog.Data()
     }
     minibuffer = _MockAskConfig([
         'batchset', 'name3\n value3\nname1\n line1\n  '
         'line2\n\nname2 value2\n', 'done'
     ])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals(
         {
             'name1': 'line1\n line2\n',
             'name2': 'value2',
             'name3': 'value3\n'
         }, result)
     self.assertEquals('done', action)
コード例 #17
0
ファイル: refactor.py プロジェクト: Szkered/dotfiles-1
class MethodObject(Refactoring):
    saveall = False
    confs = {'classname': dialog.Data('New class name: ',
                                      default='_ExtractedClass')}

    def _create_refactoring(self):
        self.objecter = rope.refactor.method_object.MethodObject(
            self.project, self.resource, self.offset)

    def _calculate_changes(self, values, task_handle):
        classname = values.get('classname')
        return self.objecter.get_changes(classname)
コード例 #18
0
 def _get_optionals(self):
     opts = {}
     opts['docs'] = dialog.Boolean('Search comments and docs: ', True)
     if self.renamer.is_method():
         opts['in_hierarchy'] = dialog.Boolean('Rename methods in '
                                               'class hierarchy: ')
     opts['resources'] = self.resources_option
     opts['unsure'] = dialog.Data('Unsure occurrences: ',
                                  decode=self._decode_unsure,
                                  values=['ignore', 'match'],
                                  default='ignore')
     return opts
コード例 #19
0
class GenerateClass(Refactoring):
    key = 'n c'
    optionals = {'destination': dialog.Data('Destination module: ', None)}

    def _calculate_changes(self, values, task_handle):
        destination = values.get('destination')
        destination = self.project.pycore.find_module(
            destination) if destination else None
        self.generator = rope.contrib.generate.GenerateClass(
            self.project,
            self.resource,
            self.offset,
            goal_resource=destination)
        return self.generator.get_changes()

    def _done(self):
        resource, lineno = self.generator.get_location()
        self.interface._goto_location(resource, lineno)
コード例 #20
0
ファイル: refactor.py プロジェクト: climbus/ropemode
 def _get_optionals(self):
     return {"destination module": dialog.Data(
                 prompt="Destination module: "
 )}
コード例 #21
0
 def _get_optionals(self):
     return {
         'args': dialog.Data('Arguments: ', decode=self._decode_args),
         'imports': dialog.Data('Imports: ', decode=self._decode_imports),
         'resources': self.resources_option
     }
コード例 #22
0
 def resources_option(self):
     return dialog.Data('Files to apply this refactoring on: ',
                        decode=self._decode_resources)
コード例 #23
0
 def _get_confs(self):
     return {'name': dialog.Data('Extracted %s name: ' % self.kind)}
コード例 #24
0
 def _get_confs(self):
     default = 'create_%s' % self.factory.old_name.lower()
     return {'factory_name': dialog.Data('Factory name: ', default)}
コード例 #25
0
 def _get_confs(self):
     oldname = str(self.renamer.get_old_name())
     return {'new_name': dialog.Data('New name: ', default=oldname)}