Recently, when studying refactoring code, I used many plug-ins of idea, such as CheckStyle, and also downloaded Alibaba's development regulations, which was inspired by a lot.
The rules require that all methods have Javadoc, but we usually use the getter and setter methods generated by idea by default without comment. Of course, we can also set idea to generate templates with Javadoc like MyEclipse. The specific solution is as follows:
For example, we have a pojo class:
/** * Human. * @author eric */public final class People { /** * Name. */ private String name; /** * Age. */ private Integer age;}At this time, we press Alt + Insert (Windows), or Command + N (MacOS) to open the build window:
Here we choose Getter and Setter.
Open the following window:
We click the place shown in the arrow in the figure to open the following view:
Then we create a new Template, click the "+" sign in the figure, and enter the name (of course you can give it a name you like)
Click OK. Then copy and paste the following code in the edit area:
/** * Gets the value of $field.name * @return the value of $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;}Click OK when finished.
The configuration of Setter is the same as above. We just need to change the code in the editing area (of course, the Template Name can also be changed:D):
/** * Sets the $field.name * <p>You can use get$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))() to get the value of $field.name</p> * @param $field.name $field.name */#set($paramName = $helper.getParamName($field, $project))public ###if($field.modifierStatic) static ###endvoid 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;}Let's take a look at the results below:
Here we need to choose the Template we just configured instead of Default.
Click OK.
It's been done here.
Summarize
The above is the graphic tutorial on the IDEA setting to generate annotated getters and setters that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!