在学习Java的过程中,用MyEclipse这个工具时,自动生成的注释十分方便快捷,养成一个加注释这个规范的习惯是最好的。以后回过头重新看自己当初学习时的代码,还能很快明白当初自己写的是什么。
如何自动生成一些自己想要的注释?下面介绍如何修改MyEclipse注释模版。
具体操作:
在MyEclipse中,打开Window--> Preferences --> Java --> Code Style --> Code Templates
然后展开Comments节点就是所有需设置注释的元素
例如下面是修改Types的模版,也就是类的注释的模版
选择Types 点右边的Edit按钮,出现编辑的窗口。
然后点Insert Variable 加一些自己想要的注释。之后保存就OK
效果如下:
/**
*
* @author随心
* @date 2014-7-28 下午8:07:03
*/
其他的注释:
(1)类型(Types)注释标签(类的注释):
/**
*@ClassName: ${type_name}
*@Description: ${todo}(这里用一句话描述这个类的作用)
*@author: Android_Robot
*@date: ${date} ${time}
* $ {tags}
*/
(2)字段(Fields)注释标签:
/**
*@Fields ${field} : ${todo} (用一句话描述这个变量表示什么)
*/
(3)构造函数标签:
/**
*@Title: ${enclosing_type}
*@Description: ${todo}(这里用一句话描述这个方法的作用)
*@param: ${tags}
*@throws
*/
(4)方法(Methods)标签:
/**
*@Title: ${enclosing_method}
*@Description: ${todo}(这里用一句话描述这个方法的作用)
*@param: ${tags}
*@return: ${return_type}
*@throws
*/
(5)覆盖方法(Overriding Methods)标签:
/**
*<p>Title: ${enclosing_method}</p>
*<p>Description: </p>
*${tags}
*${see_to_overridden}
*/
(6)代表方法(Delegate Methods)标签:
/**
*${tags}
*${see_to_target}
*/
(7)getter方法标签:
/**
*@Title: ${enclosing_method}<BR>
*@Description: please write your description <BR>
*@return: ${field_type} <BR>
*/
(8)setter方法标签:
/**
*@Title: ${enclosing_method} <BR>
*@Description: please write your description <BR>
*@return: ${field_type} <BR>
*/