Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto generating methods for variables in eclipse

Tags:

java

eclipse

In right click menu have Source-> generate Getters and Setters.On selecting the option, the user can select the variables for which getter and setter need to be generated. I want something similar. Source-> generate increment code. User can select the variable names from a list populated from his class attributes. the generated method will look like

private Integer abc;
public void incrementAbc(){
abc++;
}

I was thinking of extending the popupmenu plugin to create the options in the menus. But how do I make the code to be autogenerated on selection by user. Is using fast code template the answer. I new to plugins and I am confused. PLease do help.

like image 332
lakme.1989 Avatar asked Mar 04 '14 08:03

lakme.1989


1 Answers

You can define a template in eclipse for that which will create a default variable and implementation, but then it won't bein the source submenu. I think that's the closest you can do. Maybe you could create a template which will create an increment method for the last appropriate class property.

I cannot try without eclipse but this should give you a start: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fconcept-editor-templates.htm&cp=1_2_6

like image 82
maczikasz Avatar answered Sep 27 '22 22:09

maczikasz