Custom equals/hascode template

Answered

Hello 

is it possible to change template for generating equals and hashCode methods? in example instead of inline 'if' do it with curly braces? Or with usage of class Objects?

3
5 comments

Hello,

It's possible to create custom templates from "Generate" wizard: https://www.jetbrains.com/help/idea/generate-equals-and-hashcode-wizard.html

 

0
Avatar
Pubudu Fernando

I know this is a bit old, but ran in to the same problem and the above link just simply seem to point to verbose documentation and then to the Velocity project for info on additional customizations. Not very helpful when you are looking for a simple customization such as the above. After playing around with it a bit, managed to create a customized template by removing the `#addEqualsPrologue()` line and replacing it with the following template:

if ($paramName == this) {
return true;
}
if (!($paramName instanceof $class.name)) {
return false;
}
2

Templates used for generating getters and setters, as well as equals()hashCode(), and toString() methods are written in the Velocity template language.

More information on using VTL syntax in code templates in the IntelliJ IDEA can be found here:

0
Avatar
Permanently deleted user

How or where can I edit the output of #addEqualsPrologue() ?

1

Please sign in to leave a comment.