Anonymous avatar Anonymous committed 32b2d76

Renaming WordRangeFinder.get_name_at to get_statement_at

Comments (0)

Files changed (5)

docs/workingon.txt

 
-* WordRangeFinder.get_name_at to WordRangeFinder.get_expression_at
+- WordRangeFinder.get_name_at to WordRangeFinder.get_expression_at
+
 * (a_statment + another_statment).an_attr
 * dictionaries
 * Triples

rope/codeanalyze.py

             current_offset = self._find_atom_start(offset)
         while current_offset > 0 and \
               self.source_code[self._find_last_non_space_char(current_offset - 1)] == '.':
-            current_offset = self._find_last_non_space_char(current_offset - 1)
-            current_offset = self._find_last_non_space_char(current_offset - 1)
-            if self.source_code[current_offset].isalnum() or self.source_code[current_offset] == '_':
+            dot_position = self._find_last_non_space_char(current_offset - 1)
+            current_offset = self._find_last_non_space_char(dot_position - 1)
+
+            if self.source_code[current_offset].isalnum() or \
+               self.source_code[current_offset] == '_':
                 current_offset = self._find_word_start(current_offset)
             elif self.source_code[current_offset] in '\'"':
                 current_offset = self._find_string_start(current_offset)
                     break
         return current_offset
     
-    def get_name_at(self, offset):
+    def get_statement_at(self, offset):
         return self.source_code[self._find_name_start(offset - 1):
                                 self._find_word_end(offset - 1) + 1].strip()
 
-    def get_splitted_name_before(self, offset):
-        """returns expression, starting, starting_offset"""
+    def get_splitted_statement_before(self, offset):
+        """returns expression, starting, starting_offset
+        
+        This function is used in `rope.codeassist.assist` function.
+        """
         if offset == 0:
             return ('', '', 0)
         word_start = self._find_atom_start(offset - 1)
         self.word_finder = WordRangeFinder(source_code)
     
     def get_pyname_at(self, offset):
-        name = self.word_finder.get_name_at(offset)
+        name = self.word_finder.get_statement_at(offset)
         lineno = self.scope_finder.get_location(offset)[0]
         holding_scope = self.scope_finder.get_holding_scope(self.module_scope, lineno)
         result = self.get_pyname_in_scope(holding_scope, name)

rope/codeassist.py

         return indents
 
     def _comment_current_statement(self):
-        range_finder = StatementRangeFinder(ArrayLinesAdapter(self.lines), self.lineno)
+        range_finder = StatementRangeFinder(ArrayLinesAdapter(self.lines),
+                                            self.lineno)
         range_finder.analyze()
         start = range_finder.get_statement_start() - 1
         end = range_finder.get_scope_end() - 1
 
     def _find_inner_holding_scope(self, base_scope):
         scope_finder = HoldingScopeFinder(self.source_code)
-        return scope_finder.get_holding_scope(base_scope, self.lineno, self.current_indents)
+        return scope_finder.get_holding_scope(base_scope, self.lineno,
+                                              self.current_indents)
 
     def _get_dotted_completions(self, module_scope, holding_scope):
         result = {}
         if offset > len(source_code):
             return Proposals()
         word_finder = WordRangeFinder(source_code)
-        expression, starting, starting_offset = word_finder.get_splitted_name_before(offset)
+        expression, starting, starting_offset = word_finder.get_splitted_statement_before(offset)
         completions = self._get_code_completions(source_code, offset, expression, starting)
         templates = []
         if expression.strip() == '' and starting.strip() != '':

rope/refactoring.py

         result = []
         module_scope = self.pycore.get_string_scope(source_code)
         word_finder = WordRangeFinder(source_code)
-        old_name = word_finder.get_name_at(offset)
+        old_name = word_finder.get_statement_at(offset)
         pyname_finder = ScopeNameFinder(source_code, module_scope)
         old_pyname = pyname_finder.get_pyname_at(offset)
         if old_pyname is None:

ropetest/codeanalyzetest.py

 
     def test_inside_parans(self):
         word_finder = WordRangeFinder('a_func(a_var)')
-        self.assertEquals('a_var', word_finder.get_name_at(10))
+        self.assertEquals('a_var', word_finder.get_statement_at(10))
 
     def test_simple_names(self):
         word_finder = WordRangeFinder('a_var = 10')
-        self.assertEquals('a_var', word_finder.get_name_at(3))
+        self.assertEquals('a_var', word_finder.get_statement_at(3))
 
     def test_function_calls(self):
         word_finder = WordRangeFinder('sample_function()')
-        self.assertEquals('sample_function', word_finder.get_name_at(10))
+        self.assertEquals('sample_function', word_finder.get_statement_at(10))
     
     def test_attribute_accesses(self):
         word_finder = WordRangeFinder('a_var.an_attr')
-        self.assertEquals('a_var.an_attr', word_finder.get_name_at(10))
+        self.assertEquals('a_var.an_attr', word_finder.get_statement_at(10))
     
     def test_strings(self):
         word_finder = WordRangeFinder('"a string".split()')
-        self.assertEquals('"a string".split', word_finder.get_name_at(14))
+        self.assertEquals('"a string".split', word_finder.get_statement_at(14))
 
     def test_function_calls(self):
         word_finder = WordRangeFinder('file("afile.txt").read()')
-        self.assertEquals('file("afile.txt").read', word_finder.get_name_at(18))
+        self.assertEquals('file("afile.txt").read',
+                          word_finder.get_statement_at(18))
 
     def test_parens(self):
         word_finder = WordRangeFinder('("afile.txt").split()')
-        self.assertEquals('("afile.txt").split', word_finder.get_name_at(18))
+        self.assertEquals('("afile.txt").split',
+                          word_finder.get_statement_at(18))
 
     def test_function_with_no_param(self):
         word_finder = WordRangeFinder('AClass().a_func()')
-        self.assertEquals('AClass().a_func', word_finder.get_name_at(12))
+        self.assertEquals('AClass().a_func', word_finder.get_statement_at(12))
 
     def test_function_with_multiple_param(self):
         word_finder = WordRangeFinder('AClass(a_param, another_param, "a string").a_func()')
         self.assertEquals('AClass(a_param, another_param, "a string").a_func',
-                          word_finder.get_name_at(44))
+                          word_finder.get_statement_at(44))
     
     def test_param_expressions(self):
         word_finder = WordRangeFinder('AClass(an_object.an_attr).a_func()')
-        self.assertEquals('an_object.an_attr', word_finder.get_name_at(20))
+        self.assertEquals('an_object.an_attr',
+                          word_finder.get_statement_at(20))
 
     def test_string_parens(self):
         word_finder = WordRangeFinder('a_func("(").an_attr')
-        self.assertEquals('a_func("(").an_attr', word_finder.get_name_at(16))
+        self.assertEquals('a_func("(").an_attr',
+                          word_finder.get_statement_at(16))
 
     def test_extra_spaces(self):
         word_finder = WordRangeFinder('a_func  (  "(" ) .   an_attr')
-        self.assertEquals('a_func  (  "(" ) .   an_attr', word_finder.get_name_at(26))
+        self.assertEquals('a_func  (  "(" ) .   an_attr',
+                          word_finder.get_statement_at(26))
 
-    def test_splitted_name(self):
+    def test_splitted_statement(self):
         word_finder = WordRangeFinder('an_object.an_attr')
-        self.assertEquals(('an_object', 'an_at', 10), word_finder.get_splitted_name_before(15))
+        self.assertEquals(('an_object', 'an_at', 10),
+                          word_finder.get_splitted_statement_before(15))
 
-    def test_empty_splitted_name(self):
+    def test_empty_splitted_statement(self):
         word_finder = WordRangeFinder('an_attr')
-        self.assertEquals(('', 'an_at', 0), word_finder.get_splitted_name_before(5))
+        self.assertEquals(('', 'an_at', 0),
+                          word_finder.get_splitted_statement_before(5))
 
-    def test_empty_splitted_name2(self):
+    def test_empty_splitted_statement2(self):
         word_finder = WordRangeFinder('an_object.')
-        self.assertEquals(('an_object', '', 10), word_finder.get_splitted_name_before(10))
+        self.assertEquals(('an_object', '', 10),
+                          word_finder.get_splitted_statement_before(10))
 
-    def test_empty_splitted_name3(self):
+    def test_empty_splitted_statement3(self):
         word_finder = WordRangeFinder('')
-        self.assertEquals(('', '', 0), word_finder.get_splitted_name_before(0))
+        self.assertEquals(('', '', 0),
+                          word_finder.get_splitted_statement_before(0))
 
-    def test_empty_splitted_name4(self):
+    def test_empty_splitted_statement4(self):
         word_finder = WordRangeFinder('a_var = ')
-        self.assertEquals(('', '', 8), word_finder.get_splitted_name_before(8))
+        self.assertEquals(('', '', 8),
+                          word_finder.get_splitted_statement_before(8))
 
 
 def suite():
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.