Skip to content

Instantly share code, notes, and snippets.

@lrenn
Created August 27, 2010 05:26
Show Gist options
  • Save lrenn/552844 to your computer and use it in GitHub Desktop.
Save lrenn/552844 to your computer and use it in GitHub Desktop.
;; quick and dirty, but that's what needs to be done to support inner classes.
(defn make*
([class attrs]
(let [attrs (merge (defaults class) attrs)]
(doto (make* class)
(set-attributes! attrs))))
([class]
(if-let [parent-class (.getDeclaringClass class)]
(.newInstance (.getConstructor class (into-array [parent-class])) (into-array [(.newInstance parent-class)]))
(let [signature (into-array Class [Project])]
(try (.newInstance (.getConstructor class signature)
(into-array [*ant-project*]))
(catch NoSuchMethodException e
(let [instance (.newInstance class)]
(try (.invoke (.getMethod class "setProject" signature)
instance (into-array [*ant-project*]))
(catch NoSuchMethodException e))
instance)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment