Idea 自动生成注释
使用 IDEA 配置自动生成注释。
1 创建类时自动加注释
点击左上角菜单栏的 file -> Setting -> Editor -> File and Code Templates -> Includes -> File Header

输入如下内容:
复制代码
然后新建一个类 Test,可以看到类头已经有了自动生成的注释:

2 方法名前/属性名前加注释
点击左上角菜单栏的 file -> Setting -> Editor -> live Templates -> 2. Template Group:

输入 MyGroup
,然后确定,即可生成 MyGroup
这一项。选择 MyGroup
,点击 1.Live Template
:

Abbreviation 输入自定义名称add
,Template text 输入自己的模板,Define 选择语言Java
:


模板为:
复制代码
选择 Edit variables,将 date 的 Expression 配置为 date()
,将 time 的 Expression 配置为 time()
:


至此配置完成。
在写代码时,我们在方法前输入自己命名的 add
,然后回车,即可出现自动注释:


学习更多编程知识,请关注我的公众号:

版权声明: 本文为 InfoQ 作者【Geek_7ubdnf】的原创文章。
原文链接:【http://xie.infoq.cn/article/7094bc862db54235bba8762db】。文章转载请联系作者。
评论