用于解析java源代码的clojure的任何工具?

时间:2012-09-27 06:35:47

标签: parsing clojure

  

可能重复:
  How to analyze Java source files with Clojure

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&middot;e<sup>i&middot;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获取thetaclojure.reflect会很好,但我不确定它是否可行....我认为它只提供类型签名但是不是名字本身。

0 个答案:

没有答案