Cherry
Cherry

Reputation: 33618

How change default method name in intellij idea?

When shortkey for extracting new method is pressed Idea show a dialog with method name like that - get + SomeName. Is there a to change this template to create + SomeName?

Note

I have already seen that there is a setting Editor/File and Code templates but it contains only method bodies, not names.

Upvotes: 2

Views: 390

Answers (1)

ChiefTwoPencils
ChiefTwoPencils

Reputation: 13940

The way you can change the template for the getters and setters is through the Generate menu.

Invoke the menu (Alt+insert) and choose Getter and Setter (or one of Getter and Setter). If you click the ... button next to the template selection you can create your own template that does what you want.

In your case you could simply replace the word "get" with "create" like below to get what you want while retaining everything else from the Intellij default template.

public ##
#if($field.modifierStatic)
  static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
  #if ($StringUtil.startsWithIgnoreCase($name, 'is'))
    #set($name = $StringUtil.decapitalize($name))
  #else
    is##
#end
#else
  create##
#end
${name}() {
  return $field.name;
}

Upvotes: 2

Related Questions