我正在寻找一种在构建过程中从Java类生成aspectJ方面的方法。 目标是生成一个类型间声明方面,其中包含 java 类的每个属性的 String 常量。
Java 类:
public class CarDTO {
private String vendor;
private String name;
public String getVendor() {}
public String getName() {}
[..]
}
这是应该生成的方面:
aspect CarAspect
{
public static final String CarDTO.VENDOR = "vendor";
public static final String CarDTO.NAME = "name";
}
是否有任何obne知道maven等的工具或插件我可以实现这种行为?
谢谢
马丁
最佳答案
您可以使用 CodeSmith Generator 生成此代码。如果您在 Visual Studio 内使用 JScript (Microsoft)您可以使用我们的 GenerateOnBuild or MSBuild ( see this document aswell ) 支持。否则,您可以从构建过程中对 CodeSmith Generator 可执行文件进行脱壳,并让它也以这种方式生成代码。
需要构建自定义模板来解析文件并生成代码。开箱即用,我们支持Parsing Visual Basic or CSharp Code Files并从 Visual Basic 或 CSharp 生成(这对您没有帮助,但它向您表明它已完成并受支持)。这是一些documentation on creating a custom template .
另外,我知道您可以调用 compiled jar file and convert it to a .NET assembly 。从这里您可以使用 reflection在模板中并生成您的 Java 代码。
这可能不是最好的选择,因为您没有 Eclipse 集成(取决于您的编辑器,但它是一个可以轻松解决此问题的替代解决方案。您也可以使用 JScript、CSharp 或 Visual Basic 编写模板)
谢谢 -Blake Niemyjski(CodeSmith 员工)
关于java - 从 Java 类生成切面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5404851/