Skip to content

Commit 9d70021

Browse files
vemvbbatsov
authored andcommitted
Remove unused code from refactor-nrepl.ns.slam.hound.regrow
1 parent 99889ca commit 9d70021

File tree

2 files changed

+16
-80
lines changed

2 files changed

+16
-80
lines changed

src/refactor_nrepl/ns/slam/hound/regrow.clj

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
;;;; Distributed under the Eclipse Public License, the same as Clojure.
44
(ns refactor-nrepl.ns.slam.hound.regrow
55
(:require
6-
[clojure.set :as set]
76
[nrepl.middleware.interruptible-eval :refer [*msg*]]
8-
[refactor-nrepl.ns.slam.hound.search :as search])
9-
(:import
10-
(clojure.lang IMapEntry IRecord)))
7+
[refactor-nrepl.ns.slam.hound.search :as search]))
118

129
(def ^:dynamic *cache* (atom {}))
1310
(def ^:dynamic *dirty-ns* (atom #{}))
@@ -20,15 +17,6 @@
2017

2118
(alter-var-root #'clojure.main/repl wrap-clojure-repl)
2219

23-
(defmacro ^:private caching [key & body]
24-
`(if *cache*
25-
(if-let [v# (get @*cache* ~key)]
26-
v#
27-
(let [v# (do ~@body)]
28-
(swap! *cache* assoc ~key v#)
29-
v#))
30-
(do ~@body)))
31-
3220
(defn cache-with-dirty-tracking
3321
"The function to be cached, f, should have two signatures. A zero-operand
3422
signature which computes the result for all namespaces, and a two-operand
@@ -59,11 +47,6 @@
5947
(defn- all-ns-imports []
6048
(cache-with-dirty-tracking :all-ns-imports all-ns-imports*))
6149

62-
(defn- ns->symbols []
63-
(caching :ns->symbols
64-
(let [xs (all-ns)]
65-
(zipmap xs (mapv (comp set keys ns-publics) xs)))))
66-
6750
(defn- symbols->ns-syms*
6851
([]
6952
(symbols->ns-syms* {} (all-ns)))
@@ -79,43 +62,6 @@
7962
(defn- symbols->ns-syms []
8063
(cache-with-dirty-tracking :symbols->ns-syms symbols->ns-syms*))
8164

82-
(defn- walk
83-
"Adapted from clojure.walk/walk and clojure.walk/prewalk; this version
84-
preserves metadata on compound forms."
85-
[f form]
86-
(-> (cond
87-
(list? form) (apply list (map f form))
88-
(instance? IMapEntry form) (vec (map f form))
89-
(seq? form) (doall (map f form))
90-
(instance? IRecord form) (reduce (fn [r x] (conj r (f x))) form form)
91-
(coll? form) (into (empty form) (map f form))
92-
:else form)
93-
(as-> form (if-let [m (meta form)]
94-
(with-meta form m)
95-
form))))
96-
97-
(defn- prewalk [f form]
98-
(walk (partial prewalk f) (f form)))
99-
100-
(defn- symbols-in-body [body]
101-
(filter symbol? (remove coll? (rest (tree-seq coll? seq body)))))
102-
103-
(defn- remove-var-form
104-
"Remove (var symbol) forms from body"
105-
[expr]
106-
(if (and (coll? expr) (= (first expr) 'var))
107-
nil
108-
expr))
109-
110-
(def ^:private ns-qualifed-syms
111-
(memoize
112-
(fn [body]
113-
(apply merge-with set/union {}
114-
(for [ss (symbols-in-body body)
115-
:let [[_ alias var-name] (re-matches #"(.+)/(.+)" (str ss))]
116-
:when alias]
117-
{(symbol alias) #{(symbol var-name)}})))))
118-
11965
(defn- ns-import-candidates
12066
"Search (all-ns) for imports that match missing-sym, returning a set of
12167
class symbols. This is slower than scanning through the list of static
@@ -128,33 +74,10 @@
12874
s))
12975
#{} (vals (all-ns-imports))))
13076

131-
(defn- alias-candidates [_type missing body]
132-
(set
133-
(let [syms-with-alias (get (ns-qualifed-syms body) missing)]
134-
(when (seq syms-with-alias)
135-
(let [ns->syms (ns->symbols)]
136-
(for [ns (all-ns)
137-
:when (set/subset? syms-with-alias (ns->syms ns))]
138-
(ns-name ns)))))))
139-
14077
(defn candidates
14178
"Return a set of class or ns symbols that match the given constraints."
142-
[type missing body old-ns-map]
79+
[type missing _body _old-ns-map]
14380
(case type
14481
:import (into (ns-import-candidates missing)
14582
(get @search/available-classes-by-last-segment missing))
146-
:alias (let [cs (alias-candidates type missing body)]
147-
(if (seq cs)
148-
cs
149-
;; Try the alias search again without dynamically resolved vars
150-
;; in case #' was used to resolve private vars in an aliased ns
151-
(let [body' (prewalk remove-var-form body)]
152-
(if (= body' body)
153-
cs
154-
(alias-candidates type missing body')))))
155-
:refer (get (symbols->ns-syms) missing)
156-
:rename (reduce-kv
157-
(fn [s ns orig->rename]
158-
(cond-> s
159-
(some #{missing} (vals orig->rename)) (conj ns)))
160-
#{} (:rename old-ns-map))))
83+
:refer (get (symbols->ns-syms) missing)))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(ns refactor-nrepl.ns.slam.hound.regrow-test
2+
(:require
3+
[refactor-nrepl.ns.slam.hound.regrow :as sut]
4+
[clojure.test :refer [deftest is]]))
5+
6+
(deftest works
7+
(is ('#{#{java.lang.Thread sun.jvm.hotspot.runtime.Thread}
8+
#{java.lang.Thread}}
9+
(sut/candidates :import 'Thread [] {})))
10+
11+
(is ('#{#{clojure.core}
12+
#{clojure.core cljs.core}}
13+
(sut/candidates :refer 'areduce [] {}))))

0 commit comments

Comments
 (0)