Skip to content

Commit 4d87dfc

Browse files
committed
Renamed things in destructuring.
1 parent d18914b commit 4d87dfc

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

TODO.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Fix multiple defn bodies problem (map over defn bodies)
88

99
Watch files for reloading (using something like lazytest's watcher)
1010

11-
0.5
11+
0.5 DONE
1212
---
1313

1414
Rename not to rename shadowed var names.

src/clojure_refactoring/destructuring.clj

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
[clojure-refactoring.ast :only [defparsed-fn]])
77
(:require [clojure-refactoring.ast :as ast]))
88

9-
(defn parsley-map-lookup? [ast]
9+
(defn map-lookup? [ast]
1010
(let [content (ast/relevant-content ast)]
1111
(and (ast/tag= :list ast)
1212
(count= (filter ast/keyword? content) 1)
1313
(count= content 2))))
1414

15-
(defn parsley-key->sym [kw-node]
15+
(defn key->sym [kw-node]
1616
(ast/replace-content kw-node
1717
(list
1818
(str-join ""
1919
(drop 1 (first (:content kw-node)))))))
2020

21-
(defn parsley-find-lookups [node]
21+
(defn find-lookups [node]
2222
"Returns all the map lookups in a node as a set of parsley asts"
2323
(->> (ast/sub-nodes node)
24-
(filter parsley-map-lookup?)
24+
(filter map-lookup?)
2525
set))
2626

2727
(defn- swap-first-with-last [ast]
@@ -34,7 +34,7 @@
3434
(ast/replace-content ast
3535
(swap-first-with-last ast)))
3636

37-
(defn parsley-lookup-to-canoninical-form [lookup-ast]
37+
(defn lookup->canoninical-form [lookup-ast]
3838
(let [[maybe-keyword] (ast/relevant-content lookup-ast)]
3939
(if (ast/keyword? maybe-keyword)
4040
lookup-ast
@@ -52,15 +52,15 @@
5252
~@(drop 1 (:content m)))))
5353

5454
(def relevant-content-from-canoninical-form
55-
(comp ast/relevant-content parsley-lookup-to-canoninical-form))
55+
(comp ast/relevant-content lookup->canoninical-form))
5656

5757
(defn- add-lookup-to-binding-map [binding-map lookup]
5858
"Adds a lookup (a node of the form (:a a)) to a binding map."
5959
(let [[key m] (relevant-content-from-canoninical-form lookup)]
6060
(assoc binding-map m
6161
(add-to-parsley-map
6262
(get binding-map m ast/empty-map)
63-
(parsley-key->sym key) key))))
63+
(key->sym key) key))))
6464

6565
(defn lookups-to-binding-map [lookups]
6666
"Turns a set of lookups to a map of map-symbols to lookups"
@@ -80,7 +80,7 @@
8080
(fn [new-ast lookup]
8181
(ast/tree-replace
8282
lookup
83-
(parsley-key->sym (first (ast/relevant-content (parsley-lookup-to-canoninical-form lookup))))
83+
(key->sym (first (ast/relevant-content (lookup->canoninical-form lookup))))
8484
new-ast))
8585
ast
8686
lookups))
@@ -92,7 +92,7 @@
9292

9393
(defparsed-fn destructure-map [root-ast]
9494
"Destructures all calls to maps"
95-
(let [lookups (parsley-find-lookups root-ast)]
95+
(let [lookups (find-lookups root-ast)]
9696
(ast/ast->string
9797
(replace-lookups-with-destructured-symbols
9898
lookups

test/clojure_refactoring/destructuring_test.clj

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212

1313
(deftest parsley_map_lookup
1414
(testing "map lookups"
15-
(are [s] (parsley-map-lookup? (first (parser/parse s)))
15+
(are [s] (map-lookup? (first (parser/parse s)))
1616
"(:a a)"
1717
"(b :foo)"))
1818

19-
(are [s] (not (parsley-map-lookup? (first (parser/parse s))))
19+
(are [s] (not (map-lookup? (first (parser/parse s))))
2020
"(a (:a a))"
2121
"(:a a a)"
2222
"(:foo :bar)"
2323
"(:foo a :bar b)"))
2424

2525
(deftest parsley_key_to_sym
26-
(is (= (parsley-key->sym '{:tag :atom :content (":a")})
26+
(is (= (key->sym '{:tag :atom :content (":a")})
2727
'{:tag :atom :content ("a")})))
2828

2929
(deftest parsley_find_map_lookups
3030
(is (= (map ast/ast->string
31-
(parsley-find-lookups (parser/parse "(defn a [b] (:a b))")))
31+
(find-lookups (parser/parse "(defn a [b] (:a b))")))
3232
'("(:a b)"))))
3333

3434
(deftest parsley_lookup_to_proper_form
35-
(is (= (ast/ast->string (parsley-lookup-to-canoninical-form
35+
(is (= (ast/ast->string (lookup->canoninical-form
3636
(first (parser/parse "(a :a)"))))
3737
"(:a a)")))
3838

@@ -43,7 +43,7 @@
4343
'{:tag :atom :content ("b")})))))
4444

4545
(deftest parsley_lookups_to_binding_map
46-
(is ((lookups-to-binding-map (parsley-find-lookups (parser/parse "(defn a [b] (:a b))")))
46+
(is ((lookups-to-binding-map (find-lookups (parser/parse "(defn a [b] (:a b))")))
4747
'{:tag :atom :content ("b")})))
4848

4949
;;Integration level tests below here.

0 commit comments

Comments
 (0)