Can IntelliJ generate getters without the "get" prefix?
If I understood right you cannot modify getters/setters in idea now. Issue on youtrack
P.S. Ok, now Fix version is 14.1, from this version of idea you can create and choose getter/setter template directly in Alt-Insert
menu.
Neat question! Just to clarify @Danny Dan's answer since IntelliJ 15 has been released...
To set this up:
- Alt+Insert
- Select Getter
- Open the template configuration from '...' on the RHS
- Create a new template from the LHS - see example below
- Ok and select your new template
Example Template: fluent-getter
public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
${field.name}() {
return $field.name;
}
Why would you want to do this?
Checkout Implementing Domain-Driven Design:
The simple but effective approach to object design keeps the Value Object faithful to the Ubiquitous Language. The use of
getValuePercentage()
is a technical computer statement, butvaluePercentage()
is a fluent human-readable language expression.
Here are some slightly improved templates based on @Ed .'s previous answer:
fluent-getter:
public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
${field.name}() {
return ##
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
$field.name;
}
fluent-setter:
#set($paramName = $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
static ##
#end
void ##
${field.name}($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
}