eclipse自定义模版快捷添加注释
2016-12-13 本文已影响445人
一涯
有时候我们想给变量、方法或者类添加块注释(即/***/
这种样式的),但是实际操作中,往往需要切换输入法,符号的输入又需要shift键的配合,输入完后又需要切换回中文,按来按去,可能输入法就乱了,来回切换很麻烦。
eclipse里面提供了一种快捷模版的功能,利用这种功能可以非常方便的给文档添加注释。按步骤打开菜单:window-->preferences-->java-->editor-->templates,
![](https://img.haomeiwen.com/i2923115/e723e18c857c0f2f.png)
点击new,
![](http://upload-images.jianshu.io/upload_images/2923115-6fb4a7a0dfc588c6.png)
Name这里添加key,比如我想打入“注释”时候就自动转换成/***/
,那么
![](http://upload-images.jianshu.io/upload_images/2923115-0be9129831a74d52.png)
其中${cursor}表示光标停留的位置,点击Insert Variable找到cursor也可以添加
![](http://upload-images.jianshu.io/upload_images/2923115-dac28e648cc38aaa.png)
添加完成后,在代码中打入“注释”,然后按住 Alr+/
联想,
![](http://upload-images.jianshu.io/upload_images/2923115-129783e61fb26791.png)
选择带有comments描述的那个,描述在上图Description中自己添加。回车,你就发现
注释
两个字变成了/***/
。这就是简单的注释模版的添加,当然也可以复杂点,比如可以按照上面的方法给类添加注释模版,注释中可以带有作者信息,时间,预留字段之类的,步骤就不一一添加了,类的pattern可以这样写:
/**
*${cursor}
*@author:ZXM
* ${date} ${time}
*/
带参数方法的注释:
/**
* @param ${param} the ${bare_field_name} to set
*/
带返回值方法的注释:
/**
* @return the ${bare_field_name}
*/
以上可以自由组合,当然这些东西可以在eclipse中找到,
![](http://upload-images.jianshu.io/upload_images/2923115-011f6357e39fec9c.png)
以上参考http://www.cnblogs.com/ggws/archive/2013/05/17/3083689.htm