From f165e286ac9856781419d4659a0cde088eb79ee1 Mon Sep 17 00:00:00 2001 From: Chouser Date: Sun, 8 Nov 2009 19:18:55 -0500 Subject: repl-utils: (source foo) threw NPE when metadata didn't include :file. Fixed. --- src/clojure/contrib/repl_utils.clj | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/clojure/contrib/repl_utils.clj b/src/clojure/contrib/repl_utils.clj index af694898..2864179b 100644 --- a/src/clojure/contrib/repl_utils.clj +++ b/src/clojure/contrib/repl_utils.clj @@ -104,16 +104,17 @@ Example: (get-source 'filter)" [x] (when-let [v (resolve x)] - (when-let [strm (.getResourceAsStream (RT/baseLoader) (:file ^v))] - (with-open [rdr (LineNumberReader. (InputStreamReader. strm))] - (dotimes [_ (dec (:line ^v))] (.readLine rdr)) - (let [text (StringBuilder.) - pbr (proxy [PushbackReader] [rdr] - (read [] (let [i (proxy-super read)] - (.append text (char i)) - i)))] - (read (PushbackReader. pbr)) - (str text)))))) + (when-let [filepath (:file (meta v))] + (when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)] + (with-open [rdr (LineNumberReader. (InputStreamReader. strm))] + (dotimes [_ (dec (:line ^v))] (.readLine rdr)) + (let [text (StringBuilder.) + pbr (proxy [PushbackReader] [rdr] + (read [] (let [i (proxy-super read)] + (.append text (char i)) + i)))] + (read (PushbackReader. pbr)) + (str text))))))) (defmacro source "Prints the source code for the given symbol, if it can find it. -- cgit v1.2.3-18-g5258