示例#1
0
 def __init__(self, project, resource, offset=None):
     """If `offset` is None, the `resource` itself will be renamed"""
     self.project = project
     self.pycore = project.pycore
     self.resource = resource
     if offset is not None:
         self.old_name = worder.get_name_at(self.resource, offset)
         this_pymodule = self.pycore.resource_to_pyobject(self.resource)
         self.old_instance, self.old_pyname = \
             evaluate.eval_location2(this_pymodule, offset)
         if self.old_pyname is None:
             raise exceptions.RefactoringError(
                 'Rename refactoring should be performed'
                 ' on resolvable python identifiers.')
     else:
         if not resource.is_folder() and resource.name == '__init__.py':
             resource = resource.parent
         dummy_pymodule = self.pycore.get_string_module('')
         self.old_instance = None
         self.old_pyname = pynames.ImportedModule(dummy_pymodule,
                                                  resource=resource)
         if resource.is_folder():
             self.old_name = resource.name
         else:
             self.old_name = resource.name[:-3]
示例#2
0
 def __init__(self, project, resource, offset=None):
     """If `offset` is None, the `resource` itself will be renamed"""
     self.project = project
     self.pycore = project.pycore
     self.resource = resource
     if offset is not None:
         self.old_name = worder.get_name_at(self.resource, offset)
         this_pymodule = self.pycore.resource_to_pyobject(self.resource)
         self.old_instance, self.old_pyname = \
             evaluate.eval_location2(this_pymodule, offset)
         if self.old_pyname is None:
             raise exceptions.RefactoringError(
                 'Rename refactoring should be performed'
                 ' on resolvable python identifiers.')
     else:
         if not resource.is_folder() and resource.name == '__init__.py':
             resource = resource.parent
         dummy_pymodule = self.pycore.get_string_module('')
         self.old_instance = None
         self.old_pyname = pynames.ImportedModule(dummy_pymodule,
                                                  resource=resource)
         if resource.is_folder():
             self.old_name = resource.name
         else:
             self.old_name = resource.name[:-3]
示例#3
0
 def _set_name_and_pyname(self):
     self.name = worder.get_name_at(self.resource, self.offset)
     this_pymodule = self.project.get_pymodule(self.resource)
     self.primary, self.pyname = evaluate.eval_location2(
         this_pymodule, self.offset)
     if self.pyname is None:
         return
     pyobject = self.pyname.get_object()
     if isinstance(pyobject, pyobjects.PyClass) and "__init__" in pyobject:
         self.pyname = pyobject["__init__"]
         self.name = "__init__"
     pyobject = self.pyname.get_object()
     self.others = None
     if (self.name == "__init__"
             and isinstance(pyobject, pyobjects.PyFunction)
             and isinstance(pyobject.parent, pyobjects.PyClass)):
         pyclass = pyobject.parent
         self.others = (pyclass.get_name(),
                        pyclass.parent[pyclass.get_name()])
 def _set_name_and_pyname(self):
     self.name = worder.get_name_at(self.resource, self.offset)
     this_pymodule = self.project.get_pymodule(self.resource)
     self.primary, self.pyname = evaluate.eval_location2(
         this_pymodule, self.offset)
     if self.pyname is None:
         return
     pyobject = self.pyname.get_object()
     if isinstance(pyobject, pyobjects.PyClass) and \
        '__init__' in pyobject:
         self.pyname = pyobject['__init__']
         self.name = '__init__'
     pyobject = self.pyname.get_object()
     self.others = None
     if self.name == '__init__' and \
        isinstance(pyobject, pyobjects.PyFunction) and \
        isinstance(pyobject.parent, pyobjects.PyClass):
         pyclass = pyobject.parent
         self.others = (pyclass.get_name(),
                        pyclass.parent[pyclass.get_name()])
 def _set_name_and_pyname(self):
     self.name = worder.get_name_at(self.resource, self.offset)
     this_pymodule = self.pycore.resource_to_pyobject(self.resource)
     self.primary, self.pyname = evaluate.eval_location2(
         this_pymodule, self.offset)
     if self.pyname is None:
         return
     pyobject = self.pyname.get_object()
     if isinstance(pyobject, pyobjects.PyClass) and \
        '__init__' in pyobject:
         self.pyname = pyobject['__init__']
         self.name = '__init__'
     pyobject = self.pyname.get_object()
     self.others = None
     if self.name == '__init__' and \
        isinstance(pyobject, pyobjects.PyFunction) and \
        isinstance(pyobject.parent, pyobjects.PyClass):
         pyclass = pyobject.parent
         self.others = (pyclass.get_name(),
                        pyclass.parent[pyclass.get_name()])