开发者

java code template

开发者 https://www.devze.com 2023-04-12 07:10 出处:网络
I\'m trying to make a code template that will generate tostring, constructor from field, and a default constructor.

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 w开发者_Python百科ill love to some help or some advice on a way to create these methods for all my classes, automatically. thanks in advance.


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.)


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消