intellj idea 如何设置类头注释和方法注释

ntellj idea 如何设置类头注释和方法注释html

 

          intellj idea的强大之处就很少说了,相信每一个用过它的人都会体会到,可是咱们也会被他的复杂搞的晕头转向,尤为刚从eclipse转过来的童鞋,相信刚开始的那段经历都是不堪回首的,我也是一步步这么走过来的。程序员

         今天讲的一个主题是如何实现相似eclipse的Code Templates那样的功能,进行文件级别的方法级别注释的实现。网络

         一:文件级别的注释eclipse

         文件级别的注释网上已经不少介绍了,本文不作多介绍,主要是经过File--》Setting--》File and Code Template中来设置ide

         二:方法级别的注释函数

         文件级别的注释网上其实已经有不少了,可是方法级别的注释讲解的却不多,不少人不知道如何实现。我分享的这种方法也是我的在使用Intellj过程当中本身的一些技巧,若是你有更好的方式,能够在评论中给予更多的思路。主要就是经过intellj强大的Live Template来作。ui

         下面简单介绍一下Live Template(下面这段话摘自网络,点击这里进入原文-- 更为详细的Live Template的使用介绍和高级进阶,请参考文章底部连接 ):编码

            用惯了Eclipse快捷键的人可能会不习惯,sysout、foreach等快捷方式找不到了,main方法也没法自动补全了,其实这个在IntelliJ中有一个异常强大的模块Live Template来实现。idea

例如,在class中尝试psvm+tab,则会发现main方法产生了;输入iter+tab,则生成了foreach语句。 
live template还有一个surround的用法,选中某个变量,键入ctl+alt+j两次,则会出现自动补全的菜单。spa

此外,还能够自定义Live Template。Code Snippet技术应用也挺广泛的,IntelliJ的Live Template优势是内置了一些智能的变量和函数,能够作到一些语义级别的分析和运用

    下面为具体步骤:

         一、点击File--》Setting--》Live Template,点击右侧的+号,选择Template Group

         二、输入MyGroup(你也能够输入其余自定义的名称),而后点击OK。

         三、选中MyGroup以后,再次点击右侧的+号,选择Live Template

其中abbreviation

         四、点击第四步的Define,选择EveryWhere

         五、点击右边的Edit variables

        六、点击OK,Apply,退出,大功告成。在方法前面按 Ctrl+J ,而后选择自定义的方法注解,进行体验吧

         

个人上面的这个小技巧只是我的在使用Intellj时的一个小技巧而已,Live Template的使用,能够参考如下连接,建议你们仔细阅读,对本身的经常使用编码颇有帮助。

 

IntelliJ下使用Code/Live Template加快编码速度:程序员的工做不是写程序,而是写程序解决问题

IntelliJ Live Template进阶使用

Intellj Live Template中的预约义函数列表

备注:

注意点:

 

不知道怎样能够带回参数和返回值等信息,可是我知道为啥不显示了。

user()和date()能显示内容,是由于这两个方法在其有效的做用域执行。

而关于Method的方法(如methodName()、methodParameters()、methodReturnType())没有起做用是由于你在方法外执行的mc快捷操做,这些方法的做用域是在方法内。

看下methodName()方法的解释:Returns the name of the embracing method (where the template is expanded).返回起做用的方法的名称。

 

This is a built-in template. It contains a code fragment that can be included into file templates (Templates tab) with the help of the #parsedirective.
The template is editable. Along with static text, code and comments, you can also use predefined variables that will then be expanded like macros into the corresponding values.

 

Predefined variables will take the following values:
${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
${HOUR}   current hour
${MINUTE}   current minute
${PROJECT_NAME}   the name of the current project

 

 

 

注意点二:多个参数换行,可使用 groovyScript

 

其中脚本值:

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\\b' : '')}; return result", methodParameters())

 

 

后续有不少开发填坑的文章发布,若是对你有帮助,请支持和加关注一下

http://e22a.com/h.05ApkG?cv=AAKHZXVo&sm=339944

https://shop119727980.taobao.com/?spm=0.0.0.0 

相关文章
相关标签/搜索