Permalink
Browse files

Renaming no longer renames shadowed vars.

  • Loading branch information...
1 parent 2fc30c9 commit 812d2fd1a3f779d1ba1aa15e061d0f0f52df40ec @tcrayford tcrayford committed Sep 13, 2010
Showing with 13 additions and 10 deletions.
  1. +6 −0 src/clojure_refactoring/ast/zip.clj
  2. +7 −10 src/clojure_refactoring/rename.clj
@@ -16,3 +16,9 @@
(-> (find-node (ast-zip ast) expr)
zip/path))
+(defn zip-walk [zipper f]
+ "Performs a depth first walk over zipper, calling f on each sub-node."
+ (loop [loc zipper]
+ (if (zip/end? loc)
+ (zip/root loc)
+ (recur (zip/next (f loc))))))
@@ -24,20 +24,17 @@
loc
(zip/replace loc (ast/symbol new-name))))
+(defn rename-non-shadowed-in-ast [new-sym node old-name]
+ (zip-walk (ast-zip node)
+ #(if (= (zip/node %) (ast/symbol old-name))
+ (rename-node % new-sym) %)))
+
(defn renaming-fn [old-var new-sym]
"Returns a function for renaming nodes"
(fn [node]
- (loop [loc (ast-zip node)]
- (cond (zip/end? loc)
- (zip/root loc)
-
- (= (zip/node loc) (ast/symbol (.sym old-var)))
- (recur (zip/next (rename-node loc new-sym)))
-
- :else
- (recur (zip/next loc))))))
+ (rename-non-shadowed-in-ast new-sym node (.sym old-var))))
(defn global-rename [ns old-name new-name]
- "Sends a list of alists to emacs for processing as renames"
+ "Sends a list of alists to emacs for processing as renames."
(let [old-var (ns-resolve ns old-name)]
(replace-callers old-var (renaming-fn old-var new-name))))

0 comments on commit 812d2fd

Please sign in to comment.