Commits

Anonymous committed 75551d9

occurrences: added UnsureFilter

Comments (0)

Files changed (1)

rope/refactor/occurrences.py

 class PyNameFilter(object):
     """For finding occurrences of a name"""
 
-    def __init__(self, pynames, unsure=None):
-        self.pynames = pynames
-        self.unsure = unsure
+    def __init__(self, pyname):
+        self.pyname = pyname
 
     def __call__(self, occurrence):
         try:
             new_pyname = occurrence.get_pyname()
         except evaluate.BadIdentifierError:
-            return False
-        for pyname in self.pynames:
-            if same_pyname(pyname, new_pyname):
-                return True
-            elif self.unsure is not None and occurrence.is_unsure():
-                return self.unsure(occurrence)
-        return False
+            return
+        if same_pyname(self.pyname, new_pyname):
+            return True
+
+
+class UnsureFilter(object):
+
+    def __init__(self, unsure):
+        self.unsure = unsure
+
+    def __call__(self, occurrence):
+        if occurrence.is_unsure() and self.unsure(occurrence):
+            return True
 
 
 class NoImportsFilter(object):
             filters.append(CallsFilter())
         if not imports:
             filters.append(NoImportsFilter())
-        filters.append(PyNameFilter(pynames, unsure))
+        for pyname in pynames:
+            filters.append(PyNameFilter(pyname))
+        if unsure:
+            filters.append(UnsureFilter(unsure))
         self.finder = Finder(pycore, name, filters=filters, docs=docs)
 
     def find_occurrences(self, resource=None, pymodule=None):
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.