views:

127

answers:

4

I am new to java. I was wondering if there is a tool to copy fields and method easily. E.g if I have

private String foo;   // with getter/setters

I should be able to select foo and type bar car in a textbox and the tool should generate fields bar and car with their getter/setters.

EDIT : I use eclipse and know how to use the ide. But I would like to be able type any number of names in a textbox and the tool should the fields and along with their getter/setters. Creating each field and their getter/setters take some time.

A: 

Alt+Ins would generate setters/getters for selected fields in IntelliJ IDEA (can even do more things).

You can also have keystrokes in IntelliJ, e.g. psfs Tab makes it public static final String. Google for IDEA cheat sheet for more.

mindas
+3  A: 

Any decent IDE provides tools for this. The popular Java IDE's Eclipse, Netbeans and IntelliJ IDEA can all autogenerate "bean properties" and "getters and setters".

Here's an example how to do it with Eclipse:

Define fields, Rightclick > Source > Getters and Setters > If necessary select some options > Finished!

BalusC
Nice screenshots, but it is not what he wanted!
fastcodejava
Yeah, excellant screenshots.
javaguy
+1  A: 

What you want/need is an IDE. I prefer NetBeans, but Eclipse is also widely used. IntelliJ IDEA is a commercial IDE that has recently introduced a "Community Edition" that is free, but with less features than the commercial version.

Devon_C_Miller
+2  A: 

If you don't like getter/setters you could look into lombok project.

For your problem, you could look into fast code plugin for eclipse. It allows one to create bunch of fields in one shot. When invoked it pops up simple textbox as below : alt text

You can type foo, bar, car as you said and the fields will be created.

fastcodejava
Great job, this is what I was looking for.
javaguy