Commits

Ali Gholami Rudi  committed 541a5f4

renamed CheckingFinder to SimilarFinder

  • Participants
  • Parent commits 2df8846

Comments (0)

Files changed (4)

File rope/refactor/extract.py

 
     def _find_matches(self, collector):
         regions = self._where_to_search()
-        finder = similarfinder.CheckingFinder(self.info.pymodule)
+        finder = similarfinder.SimilarFinder(self.info.pymodule)
         matches = []
         for start, end in regions:
             matches.extend((finder.get_matches(collector.body_pattern,

File rope/refactor/restructure.py

 
     def get_changes(self, checks=None, imports=None,
                     task_handle=taskhandle.NullTaskHandle()):
-        """Get the changes needed by this restructuring
-        
-        `checks` is the checks that should hold for changing an
-        occurrence.  `imports` are the imports that should be added
-        modules that have at least one occurrence.
-
-        """
+        """Get the changes needed by this restructuring"""
         if checks is not None:
             warnings.warn(
                 'The use of checks parameter is deprecated; '
         for resource in files:
             job_set.started_job('Working on <%s>' % resource.path)
             pymodule = self.pycore.resource_to_pyobject(resource)
-            finder = similarfinder.CheckingFinder(pymodule)
+            finder = similarfinder.SimilarFinder(pymodule,
+                                                  wildcards=self.wildcards)
             computer = _ChangeComputer(pymodule, self.template,
                                        list(finder.get_matches(self.pattern,
                                                                self.args)))

File rope/refactor/similarfinder.py

     pass
 
 
-class CheckingFinder(object):
-    """A `RawSimilarFinder` that can perform object and name checks
-
-    The constructor takes a `checks` dictionary.  This dictionary
-    contains checks to be performed.  As an example::
-
-      pattern: '${?a}.set(${?b})'
-      checks: {'?a.type': type_pyclass}
-
-      pattern: '${?c} = ${?C}())'
-      checks: {'C': c_pyname}
-
-    This means only match expressions as '?a' only if its type is
-    type_pyclass.  Each matched expression is a `PyName`.  By using
-    nothing, `.object` or `.type` you can specify a check.
-
-    """
+class SimilarFinder(object):
+    """`SimilarFinder` can be used to find similar pieces of code"""
 
     def __init__(self, pymodule, wildcards=None):
-        """Construct a CheckingFinder"""
+        """Construct a SimilarFinder"""
         self.source = pymodule.source_code
         self.raw_finder = RawSimilarFinder(
             pymodule.source_code, pymodule.get_ast(), self._does_match)

File ropetest/refactor/similarfindertest.py

     def _create_finder(self, source, **kwds):
         self.mod.write(source)
         pymodule = self.project.pycore.resource_to_pyobject(self.mod)
-        return similarfinder.CheckingFinder(pymodule, **kwds)
+        return similarfinder.SimilarFinder(pymodule, **kwds)
 
     def test_trivial_case(self):
         finder = self._create_finder('')
     def test_trivial_case(self):
         self.mod1.write('')
         pymodule = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymodule)
+        finder = similarfinder.SimilarFinder(pymodule)
         self.assertEquals([], list(finder.get_matches('10', {})))
 
     def test_simple_finding(self):
         self.mod1.write('class A(object):\n    pass\na = A()\n')
         pymodule = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymodule)
+        finder = similarfinder.SimilarFinder(pymodule)
         result = list(finder.get_matches('${anything} = ${A}()', {}))
         self.assertEquals(1, len(result))
 
     def test_not_matching_when_the_name_does_not_match(self):
         self.mod1.write('class A(object):\n    pass\na = list()\n')
         pymodule = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymodule)
+        finder = similarfinder.SimilarFinder(pymodule)
         result = list(finder.get_matches('${anything} = ${C}()',
                                          {'C': 'name=mod1.A'}))
         self.assertEquals(0, len(result))
     def test_not_matching_unknowns_finding(self):
         self.mod1.write('class A(object):\n    pass\na = unknown()\n')
         pymodule = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymodule)
+        finder = similarfinder.SimilarFinder(pymodule)
         result = list(finder.get_matches('${anything} = ${C}()',
                                          {'C': 'name=mod1.A'}))
         self.assertEquals(0, len(result))
         source = 'class A(object):\n    pass\nNewA = A\na = NewA()\n'
         self.mod1.write(source)
         pymodule = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymodule)
+        finder = similarfinder.SimilarFinder(pymodule)
         result = list(finder.get_matches('${anything} = ${A}()',
                                          {'A': 'object=mod1.A'}))
         self.assertEquals(1, len(result))
                  'a = A()\nb = a.f()\n'
         self.mod1.write(source)
         pymodule = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymodule)
+        finder = similarfinder.SimilarFinder(pymodule)
         result = list(finder.get_matches('${anything} = ${inst}.f()',
                                          {'inst': 'type=mod1.A'}))
         self.assertEquals(1, len(result))
     def test_checking_the_type_of_an_ass_name_node(self):
         self.mod1.write('class A(object):\n    pass\nan_a = A()\n')
         pymodule = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymodule)
+        finder = similarfinder.SimilarFinder(pymodule)
         result = list(finder.get_matches('${a} = ${assigned}',
                                          {'a': 'type=mod1.A'}))
         self.assertEquals(1, len(result))
         self.mod1.write('from mod2 import A\nan_a = A()\n')
         pymod2 = self.pycore.resource_to_pyobject(mod2)
         pymod1 = self.pycore.resource_to_pyobject(self.mod1)
-        finder = similarfinder.CheckingFinder(pymod1)
+        finder = similarfinder.SimilarFinder(pymod1)
         result = list(finder.get_matches('${a_class}()',
                                          {'a_class': 'name=mod2.A'}))
         self.assertEquals(1, len(result))