Java源代码生成框架 [英] Java source code generation frameworks

查看:168
本文介绍了Java源代码生成框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组带有旧式Doclet标签,注释和批注的Java 5源文件。基于此,我想为另一组Java类编写一个生成器。

I have a set of Java 5 source files with old-style Doclet tags, comments and annotations. And based on that I would like to write a generator for another set of Java classes.

做到这一点的最佳方法是什么?在Java中是否有用于代码分析/生成的好的独立库?

What is the best way to do that? And are there any good standalone libraries for code analysis/generation in Java? Any shared exprience in this field is appreciated.

因此,到目前为止,我已经找到了这些:

So, far I have found these:

  • JaxME's Java Source Reflection - seems good, but it does not seem to support annotations. Also it had no release since 2006.

Annogen -使用JDK的Doclet生成器,该生成器在1.5 JDK以下存在一些错误。而且很长一段时间都没有发布。

Annogen - uses JDK's Doclet generator, which has some bugs under 1.5 JDK. Also it had no releases for a long time.

Javaparser -看起来也不错,而且很新,但是仅支持单个类的Visitor模式,即没有像上面两个软件包中那样的查询机制。

Javaparser - seems good as well and pretty recent, but only supports Visitor pattern for a single class i.e. no query mechanism like in the 2 above packages.

推荐答案

NetBeans IDE和Eclipse JDT项目都具有大量的Java代码分析/生成逻辑。我不知道它们的依赖关系是什么(即,您可以将它们用作独立的库),但是除此之外,我还要仔细看一下这两个:不太可能需要更深入的开发以及更多的Java代码分析库

Both the NetBeans IDE and Eclipse JDT projects have considerable Java code analysis/generation logic. I don't know what their dependencies are (i.e., can you use them as standalone libs), but other than that, I would take a good look at those two: it's unlikely there's a java code analysis library under more intensive development and more up to date.

更新:

PMD 也可能会引起关注:


PMD扫描Java源代码并查找可能的问题,例如:

PMD scans Java source code and looks for potential problems like:

* Possible bugs - empty try/catch/finally/switch statements
* Dead code - unused local variables, parameters and private methods
* Suboptimal code - wasteful String/StringBuffer usage
* Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
* Duplicate code - copied/pasted code means copied/pasted bugs


此外,此博客条目讨论了各种静态代码分析工具。

Additionally, this blog entry discusses various static code analysis tools.

这篇关于Java源代码生成框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆