current position:Home>Are you still writing comment templates manually? Idea can generate annotation templates of classes and methods with one click. Click in if you don't know

Are you still writing comment templates manually? Idea can generate annotation templates of classes and methods with one click. Click in if you don't know

2022-05-15 07:44:25Dream~~

IDEA Configuration of : Shortcut keys generate annotation templates for classes and methods

1, Generate the annotation template of the class

        step1 , open IDEA, Open the pop-up frames in turn ,File–>settings–>Editor–>File and Code Templates–>Files–>Class, As shown in the figure below :
 Insert picture description here
 Insert picture description here

         The blue box in the figure indicates the template , The green box indicates the code block contained by the reference . You can see a Class The template will have two lines of code by default , The first line is the path where the new class is automatically introduced , The second line is used #parse(“File Header.java”) Refer to the “Includes” Part of , however File Header.java There is no content , So when we create a new class , Always automatically introduce the path where this class is located .

        step2, Thus we can see that , If we want to add some comments when creating a new class , Can be in “Includes” Medium ‘File Header’ Add content to , Or write the comments you need to add in #parse(“File Header.java”) Below . As shown in the figure below :

 Insert picture description here
 Insert picture description here
         Be careful : Two ways of the above two pictures , Choose one of them to use .

        step3, The annotation template is self fetched .

/** * @program: ${PROJECT_NAME} * @description: ${description} * @author: lmh * @create: ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE} **/

        @program: Get the name of the project
        @description: A description of this class . So every time you create a class, there will be two pop ups , The first time is to enter the name of the class , The second time is to enter a description of this class .
        @author: founder , You can customize your name .
        @create:: When the class was created , Formats can be defined by themselves .

         Here are some sample pictures .
 Insert picture description here
 Insert picture description here
 Insert picture description here

         This sets the annotation template for the class .

2, Generate the annotation template of the method

        step1, In turn, open file->setting->Editor->LiveTemplates, As shown in the figure below :
 Insert picture description here
        step2, Click... On the right side of the above figure + Number , choice Template Group double-click , Then a window pops up , Just add a name , What I'm adding here is myTemplatesGroup, And then click OK
 Insert picture description here

        step3, Find the name you just added ( I am myTemplatesGroup), Then click on the one above the right + Number , choice LiveTemplate double-click .
 Insert picture description here

        step4, Enter your settings in the pop-up box that appears .
 Insert picture description here

         The following two pictures are 4、5 The expansion of .
 Insert picture description here
 Insert picture description here

        step5, Method annotation template

*
 * @Decription
 * @Param   null
 * @Return  $return$
 * @Author  lmh
 * @Date    $date$ $time$ 
 */

         Text description of method annotation , Dream is shown in the picture , Not much here , Directly demonstrate the results .
         Knock out... In one way /**, Then press Enter Key to see the effect .
 Insert picture description here
 Insert picture description here

         Okay , That's it , Let's have a try .

copyright notice
author[Dream~~],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/131/202205102126259689.html

Random recommended