Created
January 2, 2012 17:57
-
-
Save jxa/1551540 to your computer and use it in GitHub Desktop.
REPL tools for looking up docs and listing an object's methods. Put this file in ~/.lein
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.repl) | |
(use 'clojure.java.javadoc) | |
(use '[clojure.reflect :only [reflect]]) | |
(use '[clojure.string :only [join]]) | |
(defn inspect [obj] | |
"nicer output for reflecting on an object's methods" | |
(let [reflection (reflect obj) | |
members (sort-by :name (:members reflection))] | |
(println "Class:" (.getClass obj)) | |
(println "Bases:" (:bases reflection)) | |
(println "---------------------\nConstructors:") | |
(doseq [constructor (filter #(instance? clojure.reflect.Constructor %) members)] | |
(println (:name constructor) "(" (join ", " (:parameter-types constructor)) ")")) | |
(println "---------------------\nMethods:") | |
(doseq [method (filter #(instance? clojure.reflect.Method %) members)] | |
(println (:name method) "(" (join ", " (:parameter-types method)) ") ;=>" (:return-type method))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment