I want to generate comments as well when automatically generating getters and setters
Android Studio:
/**
* username
*/
private String name;
public String getName() {
return name;
}
I Want:
/**
* username
*/
private String name;
/**
* Get username
* @return username
*/
public String getName() {
return name;
}
I know the answer has already been accepted for this post but I came across the same issue and though i'll give it a shot as well.
As Mark explained how to create you own custom settings on the getters and setters options,
I tried to use the Intellij's settings
for both getters
and setters
and customized it the way I want to be.
This is how the Getter Template looks like for me:
/**
*@return Gets the value of $field.name and returns $field.name
*/
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
get##
#end
${name}() {
return $field.name;
}
For explanation, I used the $field.name
as a comment value and used a regular comment structure to place the value before the method generation starts.
Eg :
/**
*@return Gets the value of $field.name and returns $field.name
*/
This is how my Setter Template looks like :
/**
* Sets the $field.name
You can use get$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))() to get the value of $field.name
*/
#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;
}
And the value for $field.name
is the same as the one in the getter.
You can always customize the comment structure this way and can use other attributes like $classname.##
as well if required.
This was just a small example on how I did my comments enabling in Android Studio when doing a generate getters and setters for the the fields.
Hope this helps someone in the future. Good Luck.
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