Is it possible to change IntelliJ's code generation template for equals() and hashCode()

前端 未结 4 1303
生来不讨喜
生来不讨喜 2020-12-17 08:54

Is it possible to change the code generation template for equals() and hashCode()?

I would like the generated code to use the Java 7

4条回答
  •  清歌不尽
    2020-12-17 09:30

    Yes it is possible, but with some small hack. Locate your idea.jar file in app folder. Look inside and find files like:

    • apacheEqualsBuilder3.vm
    • apacheHashCodeBuilder3.vm

    and other .vm files..

    These template files reuse some macros from equalsHelper.vm.

    Change these files inside JAR carefully as you like restart app and check result in Idea under

    generate->equals() and hashCode()->Template (... three dots on the right)->read only preview on the right side.

    I think installing update of Idea may overwrite this JAR with your custom template changes.

    It works! Checked in Idea 15. Enjoy. :-)

提交回复
热议问题