Skip to content

Instantly share code, notes, and snippets.

@leifwalsh
Created March 30, 2010 06:14
Show Gist options
  • Save leifwalsh/348817 to your computer and use it in GitHub Desktop.
Save leifwalsh/348817 to your computer and use it in GitHub Desktop.
(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