6

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.

MusicLovingIndianGirl
  • 5,909
  • 9
  • 34
  • 65
lakme.1989
  • 163
  • 2
  • 6
  • Not a bad idea but I think eclipse does not support this. It is your business logic some one want to var++ and some one var+=2 .. If you wish you can write your own plugin. Eclipse supports plugin development. check the link to know basic about eclipse plugin development. http://www.vogella.com/tutorials/EclipsePlugIn/article.html – Naveen Ramawat Mar 04 '14 at 08:41
  • Yes .. I was planning to go forward by developing plugins by extending the popupMenus, but my doubt is , is there a way to insert code pieces, here in my case the increment code, into the current active editor,just like it is happening as in case of generate getters and setters. – lakme.1989 Mar 04 '14 at 08:44
  • i think concept of reverse engineering ??????? – Maheshbabu Jammula Mar 04 '14 at 08:47
  • Heya, @lakme.1989 I am trying to achieve the same what you're looking for. I just made a simple plugin as given in the link provided by Naveen. I am not sure how can we extend that popUpMenu which contains "Source" option. If you know anything tell me , I'll try it too. found it pretty interesting :) – TheLittleNaruto Mar 06 '14 at 05:02
  • Heya, I used popupmenu template, but it's not working Man. I dint add any action event yet. But added one more option only in the popup menu. But I am not able to see that :( – TheLittleNaruto Mar 06 '14 at 05:35
  • Hi @TheLittleNaruto, found this question on on stackoverflow, i think it is the same thing that we are looking for. Havenot tried it yet. Do let me know, if you get through it. (http://stackoverflow.com/questions/2512916/generating-custom-methods-in-eclipse). Also found this link from Vogella, while trying to understand more about JDT. (http://www.vogella.com/tutorials/EclipseJDT/article.html) – lakme.1989 Mar 06 '14 at 09:01
  • and sorry about the formatting.. i am still getting to know the hang of it. :) – lakme.1989 Mar 06 '14 at 09:07

1 Answers1

1

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

maczikasz
  • 1,113
  • 5
  • 12