使用IDEA自定义代码片段

使用IDEA自定义代码片段

1. 打开IDEA,点击 Settings,选择 Live Templates

在这里插入图片描述

2. 点击 Add,选择 2 Template Group

在这里插入图片描述

3. 输入自定义的 Group Name,点击 OK

在这里插入图片描述

4. 选中自定义组,点击 Add,选择 Live Template

在这里插入图片描述

5. 添加自定义头注释:

  • Abbreviation 输入 hh(根据个人习惯设置快捷键)。

  • Template text 输入你喜欢的模板,例如:

    /*
     * Copyright(C) [2023] [com.company]
     *
     * Author: [name]
     * Email: [email]
     *
     * This software is provided by the copyright owner under the terms of the license agreement.
     * Unauthorized use of this software is strictly prohibited.
     *
     * This software is provided under an open-source license without any express or implied warranties.
     * For details, please refer to the license file.
     */
    
  • Expand with 选择 Enter

  • 点击 Apply
    在这里插入图片描述

6. 添加类注释,重复上述步骤:

  • Abbreviation 输入 cc

  • Template text 输入模板,例如:

    /**
     * Description $context$
     * date $DATE$ $TIME$
     * @author author
     * @since JDK 1.8
     */
    
  • Expand with 选择 Enter

  • 点击 Apply
    在这里插入图片描述
    在这里插入图片描述

7. 添加Javadoc注释,重复上述步骤:

  • Abbreviation 输入 /**

  • Template text 输入模板,例如:

    /**
     * Description $context$
     * date $DATE$ $TIME$
     * $params$
     * @author [author]
     * @since JDK 1.8
     */
    
  • Expand with 选择 Enter

  • 点击 Apply
    在这里插入图片描述
    在这里插入图片描述
    params填写:groovyScript(" def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) { if(i==0)result+= '* '; if(i!=0)result+= ' * '; result+='@param ' + params[i] + ((i < (params.size() - 1)) ? '\\n' : ''); }; return result", methodParameters())

8. 最后,点击 OK

在这里插入图片描述

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值