Created
March 30, 2010 06:14
-
-
Save leifwalsh/348817 to your computer and use it in GitHub Desktop.
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
(let [method-for-class | |
(fn [cls name] | |
(first | |
(filter (complement nil?) | |
(map (fn [m] (when (= (. m (getName)) name) m)) | |
(. cls (getMethods))))))] | |
(defn setter | |
"turns a :key-word into a java setKeyWord function" | |
[cls kword] | |
(let [toks (re-seq #"[^-]+" (. (str kword) (substring 1))) | |
name (apply str "set" (map clojure.contrib.string/capitalize toks))] | |
(method-for-class cls name))) | |
(defn getter | |
"same for getters" | |
[cls kword] | |
(let [toks (re-seq #"[^-]+" (. (str kword) (substring 1))) | |
name (apply str "get" (map clojure.contrib.string/capitalize toks))] | |
(method-for-class cls name)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment