Fixed fi macro.

This commit is contained in:
Daniel Ziltener 2017-07-19 16:56:32 +00:00
parent 45eb96960b
commit cd5d092ed3

View file

@ -16,14 +16,19 @@
(defmacro fi (defmacro fi
[interface args & code] [interface args & code]
(let [interface-type (.getMapping *ns* interface) (debug "interface:" interface)
(let [iface-ref (reflect/type-reflect interface)
methods (-> (.getMethods interface-type) bogus (debug "iface-ref:" iface-ref)
seq) methods (filter #(instance? clojure.reflect.Method %) (:members iface-ref))
method-sym (.getName (first methods))] bogus (debug "methods:" (pr-str methods))
method-sym (:name (first methods))]
(debug "method-sym:" method-sym)
(when-not (= (count methods) 1) (when-not (= (count methods) 1)
(throw (new Exception "can't take an interface with more then one method."))) (throw (new Exception (str "can't take an interface with more then one method:" (pr-str methods)))))
(debug (pr-str `(proxy [~interface] []
(~method-sym ~args ~@code))))
`(proxy [~interface] [] `(proxy [~interface] []
(~method-sym ~args (~method-sym ~args
@ -57,14 +62,14 @@
(defn by-id [root id] (defn by-id [root id]
(try (try
(cond (cond
(not (instance? clojure.lang.IFn root)) (do (debug "Raw input confirmed. Starting.") (not (instance? clojure.lang.IFn root)) (do (trace "Raw input confirmed. Starting.")
(by-id (sgzipper root) id)) (by-id (sgzipper root) id))
(zip/end? root) (do (debug "Search ended without result.") (zip/end? root) (do (trace "Search ended without result.")
nil) nil)
(nil? (zip/node root)) (by-id (zip/next root) id) (nil? (zip/node root)) (by-id (zip/next root) id)
(= id (.getId (zip/node root))) (do (debug "Found item:" (zip/node root)) (= id (.getId (zip/node root))) (do (debug "Found item:" (zip/node root))
(zip/node root)) (zip/node root))
:else (do (info "id of" (zip/node root) "does not match, proceeding to" (zip/node (zip/next root))) :else (do (trace "id of" (zip/node root) "does not match, proceeding to" (zip/node (zip/next root)))
(by-id (zip/next root) id))) (by-id (zip/next root) id)))
(catch Exception e (error e)))) (catch Exception e (error e))))