Idea Java code comment specification

1. First, let's set the template of the class in IDEA: (IDEA will automatically add comments when creating the class)

1. Set the class comment template

File > settings > Editor > File and Code Templates > Files

There are four class templates we need to set, Class, Interface, Enum, Annotation.
(1) ${NAME}: Set the class name, which is the same as the following ${NAME} to get the created class name 
(2) TODO: the token of the to-do item, generally the generated class or method needs to add a description 
(3) $ {USER}, ${DATE}, ${TIME}: Set the user who created the class, the date and time of creation, these are the methods built in IDEA, and there are some other methods in the green box, for example, you want to add The project name can use ${PROJECT_NAME} 
(4) 1.0: version number

Class ( The configuration of Class, Interface, Enum, Annotation are all the same ):

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
 
/**
*@ClassName     ${NAME}
*@Description   TODO
*@Author        oyc
*@Date          ${DATE} ${TIME}
*@Version       
*/
public class ${NAME} {
}

Two, setting method annotation template

Idea has no place to directly set the method annotation template, you can borrow Live Templates for basic implementation. The steps are as follows. 

1. Select File–>Settings–>Editor–>Live Templates, first select the plus sign on the right to create a new template group of your own, as shown in the figure, I named the template group oycJavaGroup;

2. Create a new template, select the newly created template group, click on the "+" on the right, and select "Live Template"

/**   
 * @Description: $enclosing_method$
 $params$    
 * @return 
 * @throws   
 */

3. Click Define, check Java 

4. Click Edit variables to edit the variables, set as follows, click Ok–>Apply to complete the setting.

params

groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+='* @param ' + params[i] + ((i < params.size() - 1) ? '\\n ' : '')}; return result", methodParameters())

Other notes  

  • Class annotation:

/**   
 * @ClassName: $ClassName$  
 * @Description: $ClassName$
 * @Author        oyc 
 * @Date $date$ $time$   
 * @Version 1.0
 */

  • logger log

 private Logger logger = LoggerFactory.getLogger(this.getClass());

 

 

Guess you like

Origin blog.csdn.net/u014553029/article/details/109197196