Anonymous avatar Anonymous committed ed10a82

occurrences: cleaning up

Comments (0)

Files changed (1)

rope/refactor/occurrences.py

 
 
 def _cacheit(func):
-    name = '_' + func.__name__ + '_cache'
+    name = '_' + func.__name__
     def _wrapper(self, *args, **kwds):
         if not hasattr(self, name):
             setattr(self, name, func(self, *args, **kwds))
         self.pycore = pycore
         self.resource = resource
         self.pymodule = pymodule
-        self._name_finder = None
-        self._source_code = None
-        self._word_finder = None
 
-    def get_name_finder(self):
-        if self._name_finder is None:
-            if self.pymodule is None:
-                self.pymodule = self.pycore.resource_to_pyobject(self.resource)
-            self._name_finder = evaluate.ScopeNameFinder(self.pymodule)
-        return self._name_finder
+    @property
+    @_cacheit
+    def name_finder(self):
+        if self.pymodule is None:
+            self.pymodule = self.pycore.resource_to_pyobject(self.resource)
+        return evaluate.ScopeNameFinder(self.pymodule)
 
-    def get_source_code(self):
-        if self._source_code is None:
-            if self.resource is not None:
-                self._source_code = self.resource.read()
-            else:
-                self._source_code = self.pymodule.source_code
-        return self._source_code
+    @property
+    @_cacheit
+    def source_code(self):
+        if self.resource is not None:
+            return self.resource.read()
+        else:
+            return self.pymodule.source_code
 
-    def get_word_finder(self):
-        if self._word_finder is None:
-            self._word_finder = codeanalyze.WordRangeFinder(
-                self.get_source_code())
-        return self._word_finder
-
-    name_finder = property(get_name_finder)
-    word_finder = property(get_word_finder)
-    source_code = property(get_source_code)
+    @property
+    @_cacheit
+    def word_finder(self):
+        return codeanalyze.WordRangeFinder(self.source_code)
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.