Forked from semperos/clojure-deftype-scaffolding.clj
Last active
May 29, 2022 13:18
-
-
Save artfuldev/b2f0e46f4bd96654e2d9659d1453e62f 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
This file contains 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
;; 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.IPersistentStack) | |
;; clojure.lang.IPersistentStack | |
;; (peek [this]) | |
;; (pop [this]) | |
;; clojure.lang.IPersistentCollection | |
;; (count [this]) | |
;; (empty [this]) | |
;; (cons [this G__7960]) | |
;; (equiv [this G__7961]) | |
;; clojure.lang.Seqable | |
;; (seq [this]) | |
;;nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment