show(clojure.contrib.repl-utils)

With one arg prints all static and instance members of x or (class x). Each member is listed with a number which can be given as 'selector' to return the member object -- the REPL will print more details for that member.

The selector also may be a string or regex, in which case only members whose names match 'selector' as a case-insensitive regex will be printed.

Finally, the selector also may be a predicate, in which case only members for which the predicate returns true will be printed. The predicate will be passed a single argument, a map that includes the :text that will be printed and the :member object itself, as well as all the properies of the member object as translated by 'bean'.

Examples: (show Integer) (show []) (show String 23) (show String "case")

; clojure/contrib/repl_utils.clj:59
(defn show
  ([x] (show x (constantly true)))
  ([x selector]
      (let [c (if (class? x) x (class x))
            members (sort-by :sort-val
                             (map member-details
                                  (concat (.getFields c)
                                          (.getMethods c)
                                          (.getConstructors c))))]
        (if (number? selector)
          (:member (nth members selector))
          (let [pred (if (ifn? selector)
                       selector
                       #(re-find (re-pattern (str "(?i)" selector)) (:name %)))]
            (println "=== " (Modifier/toString (.getModifiers c)) c " ===")
            (doseq [[i m] (indexed members)]
              (when (pred m)
                (printf "[%2d] %s\n" i (:text m)))))))))

Copyright (c) Rich Hickey. All rights reserved.

The use and distribution terms for this software are covered by the Eclipse Public License 1.0, which can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.