How do I make my own commands and shortcuts in Eclipse?

4

What I mean by my question is that, for example, when I use sysout and Ctrl + Space the System.out.println(); method line is ready for me use, reducing my time to type everything.

I would like to know if you can do my own commands using a keyword and Ctrl + Space to call other methods I want. For example, metodoUm and Ctrl + Space calls a particular method I want.

    
asked by anonymous 04.08.2015 / 14:24

1 answer

6

The name of this is "Code Template", to create a go in Window → Prefences → Java → Editor → Templates, to arrive at the following screen:

Click"New" to create your template code. As an example, I created a template to automate the creation of an attribute and a method to make a Singleton class.

Followthecodeifyouwanttocopy:

privatestatic${primary_type_name}instancia;publicstatic${primary_type_name}getInstancia(){if(instancia==null)instancia=new${primary_type_name}();returninstancia;}

Nowinanewlycreatedclass,enterthenameofthetemplatepressCtrl+Space:

ThenconfirmwithEnter,yourclasswilllooklikethis:

Notethatyoucanincreaseyourtemplatepowerverymuchifyouusevariables,suchasintheabovecaseIused${primary_type_name},whichreplacesthepartofthecodewiththeclassname.Byclickingon"Insert Variable" you will have an extensive list of variables that you can use.

    
04.08.2015 / 14:40