Just checking, if I want to get all of the "methods as values" for a particular class, is there some shortcut to doing that without making a string + read/eval? This works, just wondering if there's a better way
(let [clazz clojure.lang.PersistentHashMap]
(->> (.getDeclaredMethods clazz)
(filter #(let [m (.getModifiers %)]
(and (not (Modifier/isStatic m))
(Modifier/isPublic m))))
(map (fn [m]
(eval
(with-meta
(read-string
(str
(-> (.getDeclaringClass m)
.getCanonicalName)
"/."
(.getName m)))
{:param-tags (mapv #(symbol
(.getCanonicalName %))
(.getParameterTypes m))}))))
))you can use the symbol function to make a symbol and then with-meta to attach metadata
I guess you still need eval at the end to evaluate a symbol to method value
oh yeah, that was a slip. But there's no built in way to enumerate them all for some class right?
well, you can use clojure.reflect if you want to work in data
(clojure.reflect/reflect clojure.lang.PersistentMap)
will give you a set of members like:
{:name valAt,
:return-type java.lang.Object,
:declaring-class clojure.lang.PersistentHashMap,
:parameter-types [java.lang.Object java.lang.Object],
:exception-types [],
:flags #{:public}}yeah that's working for me now and get's the job done. Just was wondering if there was a shortcut to get the method values themselves without building them
which you can filter etc
I think the only way to get to a method value is by evaling a qualified method symbol