Modify template used in generating `toString` method in Java code editor in IntelliJ

Viewed 1660

I have seen some documentation such as this and some Stack Overflow questions like this which talk about templates, perhaps Velocity templates, used by IntelliJ when generating a toString method in a Java class.

But no where can I find where this template lives, or how to access it from within IntelliJ.

➥ Exactly how does one find and edit the toString generation template in IntelliJ 2018?

1 Answers

Go to Code -> Generate and select toString() from the contextual menu:

enter image description here

Next, click the Settings button in upper corner.

In the toString() Generation Settings window that appears, select Templates tab.

enter image description here

Add template:

enter image description here

Finally, add the Velocity code then click apply:

enter image description here

Tip: You can duplicate an existing template rather than create an empty one. Click the "double sheets of paper" icon next to the plus and minus icons.

Related