Created
August 27, 2010 05:26
-
-
Save lrenn/552844 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
;; 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