Skip to content

Instantly share code, notes, and snippets.

@semperos
Created October 4, 2012 18:16
Show Gist options
  • Save semperos/3835392 to your computer and use it in GitHub Desktop.
Save semperos/3835392 to your computer and use it in GitHub Desktop.
Clojure Scaffolding for deftype (Christophe Grand) - Show which methods a class implements and for which interfaces
;; Big thanks to Christophe Grand - https://groups.google.com/d/msg/clojure/L1GiqSyQVVg/m-WJogaqU8sJ
(defn scaffold [iface]
(doseq [[iface methods] (->> iface .getMethods
(map #(vector (.getName (.getDeclaringClass %))
(symbol (.getName %))
(count (.getParameterTypes %))))
(group-by first))]
(println (str " " iface))
(doseq [[_ name argcount] methods]
(println
(str " "
(list name (into ['this] (take argcount (repeatedly gensym)))))))))
;;user=> (scaffold clojure.lang.IPersistentMap)
;; clojure.lang.IPersistentMap
;; (assoc [this G__441 G__442])
;; (without [this G__443])
;; (assocEx [this G__444 G__445])
;; java.lang.Iterable
;; (iterator [this])
;; clojure.lang.Associative
;; (containsKey [this G__446])
;; (assoc [this G__447 G__448])
;; (entryAt [this G__449])
;; clojure.lang.IPersistentCollection
;; (count [this])
;; (cons [this G__450])
;; (empty [this])
;; (equiv [this G__451])
;; clojure.lang.Seqable
;; (seq [this])
;; clojure.lang.ILookup
;; (valAt [this G__452 G__453])
;; (valAt [this G__454])
;; clojure.lang.Counted
;; (count [this])
;; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment