Commits

Anonymous committed 2b0e3d5

codeanalyze: moved get_name_at() to worder

Comments (0)

Files changed (10)

rope/base/codeanalyze.py

 import token
 import tokenize
 
-import rope.base.worder
-
-
-def get_name_at(resource, offset):
-    source_code = resource.read()
-    word_finder = rope.base.worder.Worder(source_code)
-    return word_finder.get_word_at(offset)
-
 
 class Lines(object):
 

rope/base/worder.py

+import bisect
 import re
-import bisect
+
+import rope.base.simplify
+
+
+def get_name_at(resource, offset):
+    source_code = resource.read()
+    word_finder = Worder(source_code)
+    return word_finder.get_word_at(offset)
 
 
 class Worder(object):
     """
 
     def __init__(self, code, handle_ignores=False):
-        import rope.base.simplify
         simplified = rope.base.simplify.real_code(code)
         self.code_finder = _DumbWorder(simplified, code)
         self.handle_ignores = handle_ignores
         self.code = code
 
     def _init_ignores(self):
-        import rope.base.simplify
         ignores = rope.base.simplify.ignored_regions(self.code)
         self.dumb_finder = _DumbWorder(self.code, self.code)
         self.starts = [ignored[0] for ignored in ignores]

rope/contrib/findit.py

 import rope.base.codeanalyze
 import rope.base.evaluate
 import rope.base.pyobjects
-from rope.base import taskhandle, exceptions
+from rope.base import taskhandle, exceptions, worder
 from rope.refactor import occurrences
 
 
     in the project are searched.
 
     """
-    name = rope.base.codeanalyze.get_name_at(resource, offset)
+    name = worder.get_name_at(resource, offset)
     this_pymodule = project.pycore.resource_to_pyobject(resource)
     primary, pyname = rope.base.evaluate.get_primary_and_pyname_at(
         this_pymodule, offset)
     Finds the places a method is implemented.  Returns a list of
     `Location`\s.
     """
-    name = rope.base.codeanalyze.get_name_at(resource, offset)
+    name = worder.get_name_at(resource, offset)
     this_pymodule = project.pycore.resource_to_pyobject(resource)
     pyname = rope.base.evaluate.get_pyname_at(this_pymodule, offset)
     if pyname is not None:

rope/contrib/generate.py

 import rope.base.evaluate
-from rope.base import change, codeanalyze, pyobjects, exceptions, pynames, worder
+from rope.base import change, pyobjects, exceptions, pynames, worder
 from rope.refactor import sourceutils, importutils, functionutils, suites
 
 
         return self.get_name() in self.goal_scope.get_defined_names()
 
     def get_name(self):
-        return codeanalyze.get_name_at(self.resource, self.offset)
+        return worder.get_name_at(self.resource, self.offset)
 
 
 class _FunctionGenerationInfo(_GenerationInfo):
             return '__init__'
         if self.is_instance():
             return '__call__'
-        return codeanalyze.get_name_at(self.resource, self.offset)
+        return worder.get_name_at(self.resource, self.offset)
 
     def get_passed_args(self):
         result = []

rope/refactor/change_signature.py

 import copy
 
 import rope.base.exceptions
-from rope.base import pyobjects, codeanalyze, taskhandle, evaluate, worder
+from rope.base import pyobjects, taskhandle, evaluate, worder
 from rope.base.change import ChangeContents, ChangeSet
-from rope.refactor import occurrences, sourceutils, functionutils, rename
+from rope.refactor import occurrences, sourceutils, functionutils
 
 
 class ChangeSignature(object):
                 'Change method signature should be performed on functions')
 
     def _set_name_and_pyname(self):
-        self.name = codeanalyze.get_name_at(self.resource, self.offset)
+        self.name = worder.get_name_at(self.resource, self.offset)
         this_pymodule = self.pycore.resource_to_pyobject(self.resource)
         self.primary, self.pyname = evaluate.get_primary_and_pyname_at(
             this_pymodule, self.offset)

rope/refactor/encapsulate_field.py

-from rope.base import pynames, taskhandle, codeanalyze, evaluate, exceptions, worder, utils
+from rope.base import pynames, taskhandle, evaluate, exceptions, worder, utils
 from rope.base.change import ChangeSet, ChangeContents
 from rope.refactor import sourceutils, occurrences
 
 
     def __init__(self, project, resource, offset):
         self.pycore = project.pycore
-        self.name = codeanalyze.get_name_at(resource, offset)
+        self.name = worder.get_name_at(resource, offset)
         this_pymodule = self.pycore.resource_to_pyobject(resource)
         self.pyname = evaluate.get_pyname_at(this_pymodule, offset)
         if not self._is_an_attribute(self.pyname):

rope/refactor/introduce_parameter.py

 import rope.base.change
-from rope.base import codeanalyze, exceptions, evaluate, worder
+from rope.base import exceptions, evaluate, worder
 from rope.refactor import functionutils, sourceutils, occurrences
 
 
         return word_finder.get_primary_at(self.offset)
 
     def _get_name_and_pyname(self):
-        return (codeanalyze.get_name_at(self.resource, self.offset),
+        return (worder.get_name_at(self.resource, self.offset),
                 evaluate.get_pyname_at(self.pymodule, self.offset))
 
     def get_changes(self, new_parameter):

rope/refactor/localtofield.py

-from rope.base import pynames, codeanalyze, evaluate, exceptions
+from rope.base import pynames, evaluate, exceptions, worder
 from rope.refactor.rename import Rename
 
 
         self.offset = offset
 
     def get_changes(self):
-        name = codeanalyze.get_name_at(self.resource, self.offset)
+        name = worder.get_name_at(self.resource, self.offset)
         this_pymodule = self.pycore.resource_to_pyobject(self.resource)
         pyname = evaluate.get_pyname_at(this_pymodule, self.offset)
         if not self._is_a_method_local(pyname):

rope/refactor/move.py

 based on inputs.
 
 """
-from rope.base import pyobjects, codeanalyze, exceptions, pynames, taskhandle, evaluate
+from rope.base import pyobjects, codeanalyze, exceptions, pynames, taskhandle, evaluate, worder
 from rope.base.change import ChangeSet, ChangeContents, MoveResource
 from rope.refactor import importutils, rename, occurrences, sourceutils, functionutils
 
         self.pycore = project.pycore
         this_pymodule = self.pycore.resource_to_pyobject(resource)
         pyname = evaluate.get_pyname_at(this_pymodule, offset)
-        self.method_name = codeanalyze.get_name_at(resource, offset)
+        self.method_name = worder.get_name_at(resource, offset)
         self.pyfunction = pyname.get_object()
         if self.pyfunction.get_kind() != 'method':
             raise exceptions.RefactoringError('Only normal methods'

rope/refactor/rename.py

 import warnings
 
-from rope.base import (exceptions, codeanalyze, pyobjects,
-                       pynames, taskhandle, evaluate, worder)
+from rope.base import exceptions, pyobjects, pynames, taskhandle, evaluate, worder
 from rope.base.change import ChangeSet, ChangeContents, MoveResource
 from rope.refactor import occurrences, sourceutils
 
         self.pycore = project.pycore
         self.resource = resource
         if offset is not None:
-            self.old_name = codeanalyze.get_name_at(self.resource, offset)
+            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.get_primary_and_pyname_at(this_pymodule, offset)
         self.pycore = project.pycore
         self.resource = resource
         self.offset = offset
-        self.old_name = codeanalyze.get_name_at(resource, offset)
+        self.old_name = worder.get_name_at(resource, offset)
         self.pymodule = self.pycore.resource_to_pyobject(self.resource)
         self.old_pyname = evaluate.get_pyname_at(self.pymodule, offset)