IDEA自定义生成注释与作者版权信息

Terwer 后端开发 技术分享评论245字数 843阅读2分48秒阅读模式

生成类注释

1、打开 Preferences文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

2、Editor -> File and Code Templates -> Files -> Class文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

在此添加的话你每次创建类的时候会弹两次框,第二次是让你输入 description 的内容了文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

代码如下文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

/**
 * ${description}
 *
 * @name: ${NAME}
 * @author: ${USER}
 * @date: ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}
 **/

接口(Interface)、枚举(Enum)、注解(Annotation)的注释同理。  生成效果文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

IDEA自定义生成注释与作者版权信息文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

IDEA 中其他类的查看效果文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

IDEA自定义生成注释与作者版权信息文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

  • 备注:为什么不用下面的格式:因为下面的格式在另一个类无法查看注释。
/**
* @name: ${NAME}
* @description: ${description}
* @author: ${USER}
* @date: ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}
**/

PS:其实还有更好的办法,直接添加到 File Header 里面。文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

IDEA自定义生成注释与作者版权信息文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

生成方法注释

打开 Preferences文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

Editor -> Live Templates -> 点击右边加号为自己添加一个 Templates Group -> 然后选中自己的 Group 再次点击加号添加 Live Templates文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

新建模板:命名为 c文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

因为 IDEA 生成注释的默认方式是:/*+ 模板名 + 快捷键(比如若设置模板名为 c 快捷键用 Tab,则生成方式为 /*c+Tab ),如果不采用这样的生成方式 IDEA 中没有内容的方法将不可用,例如获取方法参数的 methodParameters()、获取方法返回值的 methodReturnType()文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html


* @description: $description$ * @param: $params$ * @return: $returns$ * @author: $user$ * @date: $date$ */

文章更新历史文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

2022/07/05 feat:提供更好的办法,直接添加到 file header 里面。 文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

文章源自浅海拾贝-https://blog.terwergreen.com/idea-customized-annotation-and-author-copyright-information.html

相关文章
  • 扫码加我微信
  • 验证消息请输入:来自你的博客
  • weinxin
  • 我的微信公众号
  • 微信扫一扫与我交流吧
  • weinxin
Terwer
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: