Eclipse代码生成器生成mapper类
我正在尝试编写一个代码生成器,以使用 Eclipse 在任意两个类之间进行映射。这个想法是提供一个向导,用户可以在其中选择两个需要映射其属性的类。然后显示所有潜在的匹配项,如果用户没问题,则创建一个 ClassMapper 类,其中我们只有一个方法映射来执行所需的 Class1.setXXX(Class2.getXXX());
有关我们如何做到这一点的任何指示?
谢谢
I am trying to write a code generator do to Mapping between any two classes using Eclipse. The idea is to present a Wizard where users selects two classes whose properties need to be mapped. Then display all the potential matches and if user is okay then create a ClassMapper class where we will have only one method map which will do the required Class1.setXXX(Class2.getXXX());
Any pointers on how can we do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要做的就是提供与 Dozer 类似的功能,但静态代码具有这种优势,它更快,它仅在代码中包含逻辑,并且更容易通过 IDE 中的调用层次结构找到字段用法。
一般来说,Eclipse 插件是最好的开始方式,因为您只能投影 GUI,并且显示是由 Eclipse 本身完成的,而且您还可以访问它的强大工具来处理 java 代码。
然而,我认为最糟糕的部分是配置部分。 Dozer 有其原始映射器(原始映射器在原始类型和本机 java 类型之间进行转换;),它处理标准类型之间最典型的转换,但是经常需要配置它。例如,表示布尔值的字符串可以是“t”和“f”,或者“true”和“false”,或者“1”和“0”,或者来自其他语言的单词。日期可以有各种格式等。因此,您需要在此插件中配置各种映射器,可能是通过定义自己的代码片段来处理特定转换的方式。
但是,如果您这样做,我们将非常感激您。
我最近正在寻找一些东西,它会做更多的事情,我的意思是它既可以创建映射,也可以创建代码将匹配的 dto,当对象子类型由各种类表示时,可以合并类层次结构以进行设计,以平面化单个类,更适合 json 传输,但是没有结果。
This what you're going to do offers similar functionality as Dozer, but static code has this superiority, that it is faster, it contains logic only in code, and it is easier to find field usage via call hierarchy in IDE.
Generally the Eclipse plugin would be the best way to start, because you can only project GUI and the displaying is done by Eclipse itself, and also you hava access to its great tools to work with java code.
I think, however, the worse part would be the configuration one. Dozer has its primitive mapper (primitive in the way it converts between primitive and native java types ;) which handles most typical conversions between standard types, however there is ofted need to configure it. For example, the strings representing booleans can be either 't' and 'f', or 'true' and 'false' or '1' and '0', or words from other language. Dates can have various formats etc. So you would need to configure in this plugin various mappers, propably by the means of defining own code snippets to handle specific conversion.
However, if you do this, you will be greatly appreciated.
I was recently searching for something, that would do even more, I mean it could both create mapping AND the dto's to which code will be matched, with possibility to merge class hierarchy for design, when object subtypes are represented by various classes, to flat single class, better for json transport, however, without result.