9

I am trying to add the final keyword to the parameters in my auto-generated setters in IntelliJ IDEA 14. I know that I can create a copy of the current template which is used for setter methods:

#set($paramName = $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
  static ##
#end
void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {
  #if ($field.name == $paramName)
    #if (!$field.modifierStatic)
      this.##
    #else
      $classname.##
    #end
  #end
  $field.name = $paramName;
}

But even after playing around with it for hours, I can't work out how to add "final" to it and get it to work in IntelliJ.

Makoto
  • 104,088
  • 27
  • 192
  • 230
Fritz Duchardt
  • 11,026
  • 4
  • 41
  • 60

1 Answers1

25

You don't need to do this with templates.

Go to Settings (Windows: Ctrl+Alt+S) / Preferences (Mac: Command+,)

  • Editor | Code Style | Java
  • Select the Code Generation tab
  • Tick Make generated parameters final
Anton Dozortsev
  • 4,782
  • 5
  • 34
  • 69
Trisha
  • 3,891
  • 1
  • 25
  • 39
  • @Gilson I just tried it with IntelliJ IDEA 2021.1 and it worked as expected. What was the problem? – Trisha Apr 16 '21 at 09:02
  • I am also using IntelliJ IDEA 2021.1 and if I press alt+insert and choose setters, the parameter will not be final. My teammates have same issue as well. – Gilson Apr 20 '21 at 11:12