(ns de.clojure-buch.api-search (use [clojure.walk :only (postwalk)]) (use [clojure.repl :only (source-fn)])) (defn source-as-sexpr [sym] (let [src (source-fn sym)] (binding [*read-eval* false] (if (nil? src) '() (read-string src))))) (defn walk-source [sym-to-scan sym] (let [found-symbol (atom false)] (postwalk (fn [x] (if (= sym x) (swap! found-symbol #(or % true))) x) (source-as-sexpr sym-to-scan)) (when @found-symbol sym-to-scan))) (defn- symbol-usage [sym syms-to-scan-seq] (filter identity (pmap #(walk-source % sym) syms-to-scan-seq))) ;; Alternative ohne Parallelisierung ;; (defn- symbol-usage [sym syms-to-scan-seq] ;; (filter #(walk-source % sym) syms-to-scan-seq)) (defn find-usage-in-ns ([^Symbol s] (symbol-usage s (keys (ns-publics 'clojure.core)))) ([^Symbol ns #^Symbol s] (require ns) (symbol-usage s (keys (ns-publics ns)))))