设置注释模板的入口: Window->Preference->Java->Code Style->Code Template 然后展开Comments节点就是所有需设置注释的元素。
文件(Files)注释标签:
/**
* @Title: ${file_name}
* @Package ${package_name}
* @Description: ${todo}(用一句话描述该文件做什么)
* @author A18ccms A18ccms_gmail_com
* @date ${date} ${time}
* @version V1.0
*/
* @Title: ${file_name}
* @Package ${package_name}
* @Description: ${todo}(用一句话描述该文件做什么)
* @author A18ccms A18ccms_gmail_com
* @date ${date} ${time}
* @version V1.0
*/
类型(Types)注释标签(类的注释):
/**
* @ClassName: ${type_name}
* @Description: ${todo}(这里用一句话描述这个类的作用)
* @author A18ccms a18ccms_gmail_com
* @date ${date} ${time}
*
* ${tags}
*/
* @ClassName: ${type_name}
* @Description: ${todo}(这里用一句话描述这个类的作用)
* @author A18ccms a18ccms_gmail_com
* @date ${date} ${time}
*
* ${tags}
*/
字段(Fields)注释标签:
/**
* @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
*/
* @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
*/
构造函数标签:
/**
* <p>Title: </p>
* <p>Description: </p>
* ${tags}
*/
* <p>Title: </p>
* <p>Description: </p>
* ${tags}
*/
方法(Constructor & Methods)标签:
/**
* @Title: ${enclosing_method}
* @Description: ${todo}(这里用一句话描述这个方法的作用)
* @param ${tags} 设定文件
* @return ${return_type} 返回类型
* @throws
*/
* @Title: ${enclosing_method}
* @Description: ${todo}(这里用一句话描述这个方法的作用)
* @param ${tags} 设定文件
* @return ${return_type} 返回类型
* @throws
*/
覆盖方法(Overriding Methods)标签:
/*
(非 Javadoc)
* <p>Title: ${enclosing_method}</p>
* <p>Description: </p>
* ${tags}
* ${see_to_overridden}
*/
* <p>Title: ${enclosing_method}</p>
* <p>Description: </p>
* ${tags}
* ${see_to_overridden}
*/
代表方法(Delegate Methods)标签:
/**
* ${tags}
* ${see_to_target}
*/
* ${tags}
* ${see_to_target}
*/
getter方法标签:
/**
* @return ${bare_field_name}
*/
* @return ${bare_field_name}
*/
setter方法标签:
/**
* @param ${param} 要设置的 ${bare_field_name}
*/
* @param ${param} 要设置的 ${bare_field_name}
*/
简单模板例子:
1
<?
xml version="1.0" encoding="UTF-8"
?>
<
templates
><
template
autoinsert
="true"
context
="fieldcomment_context"
deleted
="false"
description
="字段的注释"
enabled
="true"
id
="org.eclipse.jdt.ui.text.codetemplates.fieldcomment"
name
="fieldcomment"
>
/**
2 * @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
3 */
4 </ template >< template autoinsert ="true" context ="gettercomment_context" deleted ="false" description ="getter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name ="gettercomment" > /**
5 * @return ${bare_field_name}
6 */
7 </ template >< template autoinsert ="true" context ="constructorcomment_context" deleted ="false" description ="创建的构造函数的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name ="constructorcomment" > /**
8 * < p > Title:${file_name} </ p >
9 * < p > Description: 构造函数 </ p >
10 * ${tags}
11 */
12 </ template >< template autoinsert ="true" context ="filecomment_context" deleted ="false" description ="已创建的 Java 文件的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.filecomment" name ="filecomment" > /**
13 * @Title: ${file_name}
14 * @Package ${package_name}
15 * @Description: ${todo}(用一句话描述该文件做什么)
16 * @author DAIGUANGJIU
17 * @date ${date} ${time}
18 * @version V1.0
19 */
20 </ template >< template autoinsert ="true" context ="settercomment_context" deleted ="false" description ="setter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.settercomment" name ="settercomment" > /**
21 * @param ${param} 要设置的 ${bare_field_name}
22 */ </ template >< template autoinsert ="true" context ="typecomment_context" deleted ="false" description ="创建的类型的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.typecomment" name ="typecomment" > /**
23 * @author ${user}
24 *
25 * ${tags}
26 */ </ template >< template autoinsert ="true" context ="delegatecomment_context" deleted ="false" description ="代表方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name ="delegatecomment" > /**
27 * ${tags}
28 * ${see_to_target}
29 */ </ template >< template autoinsert ="true" context ="overridecomment_context" deleted ="false" description ="覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name ="overridecomment" > /** (非 Javadoc)
30 * < p > Title: ${enclosing_method} </ p >
31 * < p > Description: </ p >
32 * ${tags}
33 * ${see_to_overridden}
34 */ </ template >< template autoinsert ="true" context ="methodcomment_context" deleted ="false" description ="非覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name ="methodcomment" > /**
35 * ${tags}
36 */ </ template ></ templa
37 <?xml version="1.0" encoding="UTF-8"? >< templates >< template autoinsert ="true" context ="fieldcomment_context" deleted ="false" description ="字段的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name ="fieldcomment" > /**
38 * @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
39 */
40 </ template >< template autoinsert ="true" context ="gettercomment_context" deleted ="false" description ="getter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name ="gettercomment" > /**
41 * @return ${bare_field_name}
42 */
43 </ template >< template autoinsert ="true" context ="constructorcomment_context" deleted ="false" description ="创建的构造函数的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name ="constructorcomment" > /**
44 * < p > Title:${file_name} </ p >
45 * < p > Description: 构造函数 </ p >
46 * ${tags}
47 */
48 </ template >< template autoinsert ="true" context ="filecomment_context" deleted ="false" description ="已创建的 Java 文件的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.filecomment" name ="filecomment" > /**
49 * @Title: ${file_name}
50 * @Package ${package_name}
51 * @Description: ${todo}(用一句话描述该文件做什么)
52 * @author DAIGUANGJIU
53 * @date ${date} ${time}
54 * @version V1.0
55 */
56 </ template >< template autoinsert ="true" context ="settercomment_context" deleted ="false" description ="setter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.settercomment" name ="settercomment" > /**
57 * @param ${param} 要设置的 ${bare_field_name}
58 */ </ template >< template autoinsert ="true" context ="typecomment_context" deleted ="false" description ="创建的类型的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.typecomment" name ="typecomment" > /**
59 * @author ${user}
60 *
61 * ${tags}
62 */ </ template >< template autoinsert ="true" context ="delegatecomment_context" deleted ="false" description ="代表方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name ="delegatecomment" > /**
63 * ${tags}
64 * ${see_to_target}
65 */ </ template >< template autoinsert ="true" context ="overridecomment_context" deleted ="false" description ="覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name ="overridecomment" > /** (非 Javadoc)
66 * < p > Title: ${enclosing_method} </ p >
67 * < p > Description: </ p >
68 * ${tags}
69 * ${see_to_overridden}
70 */ </ template >< template autoinsert ="true" context ="methodcomment_context" deleted ="false" description ="非覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name ="methodcomment" > /**
71 * ${tags}
72 */ </ template ></ template >
2 * @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
3 */
4 </ template >< template autoinsert ="true" context ="gettercomment_context" deleted ="false" description ="getter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name ="gettercomment" > /**
5 * @return ${bare_field_name}
6 */
7 </ template >< template autoinsert ="true" context ="constructorcomment_context" deleted ="false" description ="创建的构造函数的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name ="constructorcomment" > /**
8 * < p > Title:${file_name} </ p >
9 * < p > Description: 构造函数 </ p >
10 * ${tags}
11 */
12 </ template >< template autoinsert ="true" context ="filecomment_context" deleted ="false" description ="已创建的 Java 文件的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.filecomment" name ="filecomment" > /**
13 * @Title: ${file_name}
14 * @Package ${package_name}
15 * @Description: ${todo}(用一句话描述该文件做什么)
16 * @author DAIGUANGJIU
17 * @date ${date} ${time}
18 * @version V1.0
19 */
20 </ template >< template autoinsert ="true" context ="settercomment_context" deleted ="false" description ="setter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.settercomment" name ="settercomment" > /**
21 * @param ${param} 要设置的 ${bare_field_name}
22 */ </ template >< template autoinsert ="true" context ="typecomment_context" deleted ="false" description ="创建的类型的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.typecomment" name ="typecomment" > /**
23 * @author ${user}
24 *
25 * ${tags}
26 */ </ template >< template autoinsert ="true" context ="delegatecomment_context" deleted ="false" description ="代表方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name ="delegatecomment" > /**
27 * ${tags}
28 * ${see_to_target}
29 */ </ template >< template autoinsert ="true" context ="overridecomment_context" deleted ="false" description ="覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name ="overridecomment" > /** (非 Javadoc)
30 * < p > Title: ${enclosing_method} </ p >
31 * < p > Description: </ p >
32 * ${tags}
33 * ${see_to_overridden}
34 */ </ template >< template autoinsert ="true" context ="methodcomment_context" deleted ="false" description ="非覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name ="methodcomment" > /**
35 * ${tags}
36 */ </ template ></ templa
37 <?xml version="1.0" encoding="UTF-8"? >< templates >< template autoinsert ="true" context ="fieldcomment_context" deleted ="false" description ="字段的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name ="fieldcomment" > /**
38 * @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
39 */
40 </ template >< template autoinsert ="true" context ="gettercomment_context" deleted ="false" description ="getter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name ="gettercomment" > /**
41 * @return ${bare_field_name}
42 */
43 </ template >< template autoinsert ="true" context ="constructorcomment_context" deleted ="false" description ="创建的构造函数的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name ="constructorcomment" > /**
44 * < p > Title:${file_name} </ p >
45 * < p > Description: 构造函数 </ p >
46 * ${tags}
47 */
48 </ template >< template autoinsert ="true" context ="filecomment_context" deleted ="false" description ="已创建的 Java 文件的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.filecomment" name ="filecomment" > /**
49 * @Title: ${file_name}
50 * @Package ${package_name}
51 * @Description: ${todo}(用一句话描述该文件做什么)
52 * @author DAIGUANGJIU
53 * @date ${date} ${time}
54 * @version V1.0
55 */
56 </ template >< template autoinsert ="true" context ="settercomment_context" deleted ="false" description ="setter 方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.settercomment" name ="settercomment" > /**
57 * @param ${param} 要设置的 ${bare_field_name}
58 */ </ template >< template autoinsert ="true" context ="typecomment_context" deleted ="false" description ="创建的类型的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.typecomment" name ="typecomment" > /**
59 * @author ${user}
60 *
61 * ${tags}
62 */ </ template >< template autoinsert ="true" context ="delegatecomment_context" deleted ="false" description ="代表方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name ="delegatecomment" > /**
63 * ${tags}
64 * ${see_to_target}
65 */ </ template >< template autoinsert ="true" context ="overridecomment_context" deleted ="false" description ="覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name ="overridecomment" > /** (非 Javadoc)
66 * < p > Title: ${enclosing_method} </ p >
67 * < p > Description: </ p >
68 * ${tags}
69 * ${see_to_overridden}
70 */ </ template >< template autoinsert ="true" context ="methodcomment_context" deleted ="false" description ="非覆盖方法的注释" enabled ="true" id ="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name ="methodcomment" > /**
71 * ${tags}
72 */ </ template ></ template >