|
6964 | 6964 |
|
6965 | 6965 | ;; TODO: kwargs on supertypes |
6966 | 6966 | ;; TODO: check interface/superclass method membership |
6967 | | -;; TODO: check if duplicate methods |
6968 | 6967 | (defmacro proxy |
6969 | 6968 | "Create a new proxy class instance. |
6970 | 6969 |
|
|
7000 | 6999 | (let [formatted-single (fn [method-name [arg-vec & body]] |
7001 | 7000 | [(munge method-name) |
7002 | 7001 | (apply list 'fn method-name (vec (concat ['this] arg-vec)) body)]) |
7003 | | - formatted-multi (fn [method-name & arities] |
7004 | | - [(munge method-name) |
7005 | | - (apply list |
7006 | | - 'fn |
7007 | | - method-name |
7008 | | - (map (fn [[arg-vec & body]] |
7009 | | - (apply list (vec (concat ['this] arg-vec)) body)) |
7010 | | - arities))]) |
7011 | | - methods (mapcat (fn [[method-name & body]] |
7012 | | - (if (vector? (first body)) |
7013 | | - (formatted-single method-name body) |
7014 | | - (apply formatted-multi method-name body))) |
7015 | | - fs)] |
| 7002 | + formatted-multi (fn [method-name & arities] |
| 7003 | + [(munge method-name) |
| 7004 | + (apply list |
| 7005 | + 'fn |
| 7006 | + method-name |
| 7007 | + (map (fn [[arg-vec & body]] |
| 7008 | + (apply list (vec (concat ['this] arg-vec)) body)) |
| 7009 | + arities))]) |
| 7010 | + methods (map (fn [[method-name & body]] |
| 7011 | + (if (vector? (first body)) |
| 7012 | + (formatted-single method-name body) |
| 7013 | + (apply formatted-multi method-name body))) |
| 7014 | + fs) |
| 7015 | + method-map (reduce* (fn [m [method-name method]] |
| 7016 | + (if-let [existing-method (get m method-name)] |
| 7017 | + (throw |
| 7018 | + (ex-info "Cannot define proxy class with duplicate method" |
| 7019 | + {:method-name method-name |
| 7020 | + :impls [existing-method method]})) |
| 7021 | + (assoc m method-name method))) |
| 7022 | + {} |
| 7023 | + methods)] |
7016 | 7024 | #_(println methods) |
7017 | | - `((get-proxy-class ~@class-and-interfaces) ~(apply hash-map methods) ~@args))) |
| 7025 | + `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7018 | 7026 |
|
7019 | 7027 | (defmacro proxy-super |
7020 | 7028 | "Macro which expands to a call to the method named ``meth`` on the superclass |
|
0 commit comments