Custom Getter/Setter Templates for Intellij IDEA

Omindu
2 min readMay 2, 2020

--

This post demonstrates how you can customize the Getter Setter templates in Intellij IDEA.

If you are starting with a new project, chances are that you have to create a lot of model classes with getters and setters for the fields. IDEA already provides a way to auto generate the getters and setters. However, in my case I wanted to add an extra new line after the getter/setter declaration. Luckily IDEA has given the feature to customizes these getter and setter templates to suit our needs.

The below gif demonstrates how you can do this easily with a few clicks.

Customizing Getter and Setter Templates

In case the gif is not visible. Below is a step by step guide in text.

Once you create your class with necessary fields, Select Code > Generate from the top menu bar. You will be prompted to select the code generate options. From that select Getter and Setter. Then you will get the option to select the fields you want to generate getters and setters.

From the prompt, select the fields you want to generate getters and setters. Then, on the top of the prompt window you should see drop down menus to select the getter setter templates.

In front of the drop down menus. You should see buttons with 3 dots. Click the button in front of getter dropdown. You will be prompted with the template editor. As the default template cannot be edited, make a copy of the template and change the template as you want. Once the changes are made, press ‘Ok’.

Follow the same steps to modify the setter template. Once the templates are saved, press ‘Ok’ again and you will see the getters and setters generated according to your new template.

Hope this helps :)

--

--

No responses yet