java代码模板
我正在尝试制作一个代码模板,它将生成 tostring、字段构造函数和默认构造函数。
我已经查看了 有用的 Eclipse Java 代码模板 和 http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-tostring-templates.htm 但这不是我正在寻找。
我尝试了这个插件 http://eclipse-jutils.sourceforge.net/ 但我仍然需要手动选择菜单中的一个选项(并且它没有“字段的构造函数”选项)。
我需要为超过 100 个类生成这些方法和构造函数,所以这是我发现的最好方法,因为 Eclipse 不提供为多个类执行此操作的工具,而对于他提供此工具的这一类,我需要通过以下方式执行此操作:其中之一(从字段生成 tostring 、构造函数以及默认构造函数)
我很乐意获得一些帮助或建议,以帮助我自动为我的所有类创建这些方法。 提前致谢。
I'm trying to make a code template that will generate tostring, constructor from field, and a default constructor.
I already looked at Useful Eclipse Java Code Templates and in http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-tostring-templates.htm but it was not what I was looking for.
I tried this plugin http://eclipse-jutils.sourceforge.net/ but I still need to manually select an option in the menu (and it doesn't have a "constructor from fields" option).
I need to generate these methods and constructors for more then 100 classes so this the best way i found coz eclipse dont give tool to do it for more then one class and for this one class that he give this tool i need to do it one by one the (generate tostring ,constructor from field and also default constructor)
i will love to some help or some advice on a way to create these methods for all my classes, automatically.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有哪个插件可以为多个类执行此操作。
我只是手动完成,尽管这需要时间。
您还可以使用反射和脚本语言,如 Groovy/JRuby/等。创建构造函数,并依赖 Commons 的 ToStringBuilder 创建一个
toString
,或者再次使用反射。(一个问题是,如果您不想要在构造函数或
toString
中使用属性,则需要有一种机制来告诉生成器同样多的信息。)I don't know of a plugin that will do this for multiple classes.
I'd just do it manually, even though it'd take time.
You could also use reflection and a scripting language like Groovy/JRuby/etc. to create the constructors, and rely on something like Commons' ToStringBuilder to create a
toString
, or just use reflection again.(One problem is if you don't want a property in the constructor or
toString
you need to have a mechanism to tell the generator as much.)我刚刚使用了实用宏,在安装后几分钟内市场,我可以生成 *构造函数*、getters / setters、toString、hashcode和等于(基本上是链接标准 Eclipse 命令)在单个命令中。正是我正在寻找的东西,并为我节省了大量时间。我还可以看到它的更多用途,Earnst(创建者)做得很好。
I have just used Practically Macros, within a few minutes of install from the market place, I could generate *constructors*, getters / setters, toString, hashcode and equals (basically chaining the standard eclipse commands) in a single command. Just what I was looking for and saved me loads of time. I can also see a lot more uses for it, well done to Earnst (the creator).