java / clojure中有哪些工具可以解析java源文件以理解java代码结构?
这样做的动机是代码生成......如果我有一个包含java源代码的字符串
(def java-str
"/**
* @param r the modulus of the complex number to create
* @param theta the argument of the complex number to create
* @return <code>r·e<sup>i·theta</sup></code>
* @throws MathIllegalArgumentException if r is negative
* @since 1.1
*/
public static Complex polar2Complex(double r, double theta) {
if (r < 0) {
throw new MathIllegalArgumentException(
LocalizedFormats.NEGATIVE_COMPLEX_MODULE, r);
}
return new Complex(r * FastMath.cos(theta), r * FastMath.sin(theta));
}
")
然后可以编写gen-clj-fn
来生成一个知道java方法,参数名称,类型和顺序的函数定义的clojure字符串:
(gen-clj-fn java-str)
;;=> "(defn polar-to-complex [#^Double r #^Double theta]
;; (Complex/polar2Complex r theta))"
理想情况下,从r
获取theta
和clojure.reflect
会很好,但我不确定它是否可行....我认为它只提供类型签名但是不是名字本身。