IntelliJ has the cool feature to generate Java getters. For example, for a field private final String foo
, it will generate a getter getFoo()
.
Is there any way I can configure IntelliJ to generate getters in the format String foo()
? I am working mainly with immutable objects and prefer this syntax.
Here are some slightly improved templates based on @Ed .'s previous answer:
public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
${field.name}() {
return ##
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
$field.name;
}
#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;
}
Neat question! Just to clarify @Danny Dan's answer since IntelliJ 15 has been released...
fluent-getter
public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
${field.name}() {
return $field.name;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With