1. The introduction

During team development, the clearer the business module allocation, the more perfect the code annotation management, the more conducive to the later maintenance, the later management is also more convenient. It also acts as a word brick, you know. Comments don’t need to be very detailed, just a brief description of the code block method block function. Otherwise, after march, I will scold when I look back. After I scold, I find it is written by myself.

Three common Java annotations

    // Declare constants
    int number;
Copy the code
    /* * class main function */
    public static void main(String[] args) {}Copy the code
    / * * *@paramMasterId brand Id *@paramShopId Store Id *@paramSkuId Commodity skuId *@description: Verify the ownership relationship between the product identification code and the store *@return: net.jdcloud.APIECRM.model.ValidateSkuUsingGETResponse
     * @author: niaonao
     * @date: 2020/01/13 * /
    public static ValidateSkuUsingGETResponse validateSkuUsing(String masterId, String shopId, String skuId){
        return null;
    }
Copy the code

2. Customize a comment template

2.1 Class comment templates

2.1.1 Configuring a Template

Add a comment template under file-settings-editor-file and Code Templates- incudes-file Header and click Apply OK to configure the template.

Custom comment templates

/ * * *@className: ${NAME}
 * @descriptionTODO class description *@author: niaonao
 * @date:  ${DATE}
 **/
Copy the code

Creating a new interface file automatically generates a comment with the following effect

/ * * *@className: CrowdService
 * @description: Crowd object business *@author: niaonao
 * @date: 2020/1/13 * * /
public interface CrowdService {}Copy the code

2.1.2 User-defined Annotation Template Incomplete variable Reference table

Predefined variable Description information
${NAME} the name of the current file
${PACKAGE_NAME} name of the package in which the new file is created
${USER} current user system login name
${DATE} current system date
${TIME} current system time
${YEAR} current year
${MONTH} current month
${MONTH_NAME_SHORT} first 3 letters of the current month name. Example: Jan, Feb, etc.
${MONTH_NAME_FULL} full name of the current month. Example: January, February, etc.
${DAY} current day of the month
${DAY_NAME_SHORT} first 3 letters of the current day name. Example: Mon, Tue, etc.
${DAY_NAME_FULL} full name of the current day. Example: Monday, Tuesday, etc.
${HOUR} current hour
${MINUTE} current minute
${PROJECT_NAME} the name of the current project

2.2 Method Annotation Template

2.2.1 Configuring a Template

Add a new template group named custom JavaTemplateGroup under file-settings-editor-live Templates. Select a template group and click Add on the right to create a template.

  • The Abbreviation is *.
  • Description Indicates the user-defined Description.
  • Template Text User-defined Template
*
 $param$
 * @description: TODO
 * @return: $return$*@author: niaonao
 * @date: $date$
 */
Copy the code

Edit variables Edit variables

  • The return variable is methodReturnType()
  • The variable date expression is date()
  • The variable param is expressed as
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()) 
Copy the code

If there is a warning message for No Applicable Context, click Define to select Java.

Expend With is configured as the Enter key to generate a shortcut for annotation, depending on personal habits, or the Tab key can be used.

Click Apply OK to Apply the configuration. Results the following

    / * * *@param: masterId
     * @param: shopId
     * @param: skuId
     * @description: TODO
     * @return: net.jdcloud.APIECRM.model.ValidateSkuUsingGETResponse
     * @author: niaonao
     * @date: 2020/1/13 * /
    public static ValidateSkuUsingGETResponse validateSkuUsing(String masterId, String shopId, String skuId) {
        return null;
    }
Copy the code

2.2.2 Supplementary notes

Method annotation template is not available outside the method, if used outside the method @param not available, annotation @param null;

Method comment templates take up /**. When used in variable declarations, you can type an extra space after /** and press Enter to not trigger the method template

A class comment template is generated when a file is created. The method comment template is triggered instead of the created file.

Power By niaonao, The End, Thanks