I want to create an object of a class in and then set all the properties in it using setter methods. There are more than 150 setter methods and I do want to type each one of them or even type in the object instance name Object instance
type in dot .
and then hit the spacebar for Eclipse to give me suggestions and then go and select the setter method. I do not want to do that 150 times.
Thus, I was looking for some sort of shortcut in Eclipse that allows you to call all the setters on the method. So like you type in the instance name and Eclipse calls all the setter methods e.g.
I cannot create another constructor in the the class, I am not allowed to do so
The shortcut key is Ctrl+Shift+D. In the dialog select getters and setters for which you want to generate Javadocs and click "OK" button. Javadocs are generated for the selected getters and setters.
To open call hierarchy in Eclipse, select a method, click on Navigate on the main menu and select Open Call Hierarchy. Alternatively use a keyboard shortcut Ctrl+Alt+H.
From my experience last time , I cannot find eclipse has such feature .The most that I can do is open the Type Hierarchy
View (by pressing F4 when viewing that class ), and then sort by the method name of that class and copy all the setters for further edit.
Or , you can use reflection to find out all the methods of this class , and print out the setter calls . Suppose this class is called Foo
, you can have something like this:
for (Method m : Foo.class.getMethods()) { if (m.getName().startsWith("set")) { System.out.println(String.format("instanceName.%s(\"valOne\");", m.getName())); } }
See this question: Generate all setXXX calls of a POJO in Eclipse?
It has a great and simple way of doing what you want to do.
Oh and try to ignore the haters!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With