(analyze-ns ns)
(analyze-ns ns env)
(analyze-ns ns env opts)
Analyzes a whole namespace, returns a vector of the ASTs for all the
top-level ASTs of that namespace.
Evaluates all the forms.
Source
(defn analyze-ns
"Analyzes a whole namespace, returns a vector of the ASTs for all the
top-level ASTs of that namespace.
Evaluates all the forms."
([ns] (analyze-ns ns (empty-env)))
([ns env] (analyze-ns ns env {}))
([ns env opts]
(env/ensure (global-env)
(let [res ^URL (ns-url ns)]
(assert res (str "Can't find " ns " in classpath"))
(let [filename (str res)
path (.getPath res)]
(when-not (get-in (env/deref-env) [::analyzed-clj path])
(binding [*ns* *ns*
*file* filename]
(with-open [rdr (io/reader res)]
(let [pbr (readers/indexing-push-back-reader
(java.io.PushbackReader. rdr) 1 filename)
eof (Object.)
read-opts {:eof eof :features #{:clj :t.a.jvm}}
read-opts (if (.endsWith filename "cljc")
(assoc read-opts :read-cond :allow)
read-opts)]
(loop []
(let [form (reader/read read-opts pbr)]
(when-not (identical? form eof)
(swap! *env* update-in [::analyzed-clj path]
(fnil conj [])
(analyze+eval form (assoc env :ns (ns-name *ns*)) opts))
(recur))))))))
(get-in @*env* [::analyzed-clj path]))))))