Eclipse Java注释模板设置详解

From: http://blog.csdn.net/ahhsxy/archive/2009/09/11/4542682.aspx

 

设置注释模板的入口: 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  
*/

类型(Types)注释标签(类的注释):

/**
* @ClassName: ${type_name}
* @Description: ${todo}(这里用一句话描述这个类的作用)
* @author A18ccms a18ccms_gmail_com
* @date ${date} ${time}
*
* ${tags}
*/


字段(Fields)注释标签:

/**
* @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
*/
构造函数标签:

/**
* <p>Title: </p>
* <p>Description: </p>
* ${tags}
*/


方法(Constructor & Methods)标签:

/**
* @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}
*/


代表方法(Delegate Methods)标签:

/**
* ${tags}
* ${see_to_target}
*/
getter方法标签:

/**
* @return ${bare_field_name}
*/

setter方法标签:

/**
* @param ${param} 要设置的 ${bare_field_name}
*/

简单模板例子:

view plain copy to clipboard print ?
  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  

<?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">/** * @Fields ${field} : ${todo}(用一句话描述这个变量表示什么) */ </template><template autoinsert="true" context="gettercomment_context" deleted="false" description="getter 方法的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/** * @return ${bare_field_name} */ </template><template autoinsert="true" context="constructorcomment_context" deleted="false" description="创建的构造函数的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/** * <p>Title:${file_name} </p> * <p>Description: 构造函数</p> * ${tags} */ </template><template autoinsert="true" context="filecomment_context" deleted="false" description="已创建的 Java 文件的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/** * @Title: ${file_name} * @Package ${package_name} * @Description: ${todo}(用一句话描述该文件做什么) * @author DAIGUANGJIU * @date ${date} ${time} * @version V1.0 */ </template><template autoinsert="true" context="settercomment_context" deleted="false" description="setter 方法的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/** * @param ${param} 要设置的 ${bare_field_name} */</template><template autoinsert="true" context="typecomment_context" deleted="false" description="创建的类型的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/** * @author ${user} * * ${tags} */</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="代表方法的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/** * ${tags} * ${see_to_target} */</template><template autoinsert="true" context="overridecomment_context" deleted="false" description="覆盖方法的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/** (非 Javadoc) * <p>Title: ${enclosing_method}</p> * <p>Description: </p> * ${tags} * ${see_to_overridden} */</template><template autoinsert="true" context="methodcomment_context" deleted="false" description="非覆盖方法的注释" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/** * ${tags} */</template></templa

例子2:

view plain copy to clipboard print ?
  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2. < templates >   
  3.       
  4.     < template    
  5.                 autoinsert = "false"    
  6.                 context = "constructorcomment_context"    
  7.                 deleted = "false"    
  8.                 description = "Comment for created constructors"    
  9.                 enabled = "true"    
  10.                 id = "org.eclipse.jdt.ui.text.codetemplates.constructorcomment"   
  11.                 name = "constructorcomment" >   
  12.     /**  
  13.      * 创建一个新的实例 ${enclosing_type}.  
  14.      *  
  15.      * ${tags}  
  16.      */  
  17.     </ template >   
  18.       
  19.     < template    
  20.                 autoinsert = "true"    
  21.                 context = "settercomment_context"   
  22.                 deleted = "false"    
  23.                 description = "Comment for setter method"    
  24.                 enabled = "true"    
  25.                 id = "org.eclipse.jdt.ui.text.codetemplates.settercomment"    
  26.                 name = "settercomment" >   
  27.     /**  
  28.      * @param ${param} the ${bare_field_name} to set  
  29.      */  
  30.     </ template >   
  31.       
  32.       
  33.     < template   
  34.                 autoinsert = "false"    
  35.                 context = "methodcomment_context"    
  36.                 deleted = "false"    
  37.                 description = "Comment for non-overriding methods"    
  38.                 enabled = "true"    
  39.                 id = "org.eclipse.jdt.ui.text.codetemplates.methodcomment"    
  40.                 name = "methodcomment" >   
  41.     /**  
  42.      * 此方法描述的是:  
  43.      * @author: [email protected]  
  44.      * @version: ${date} ${time}  
  45.      */  
  46.     </ template >   
  47.       
  48.       
  49.     < template    
  50.                 autoinsert = "true"    
  51.                 context = "delegatecomment_context"    
  52.                 deleted = "false"    
  53.                 description = "Comment for delegate methods"    
  54.                 enabled = "true"    
  55.                 id = "org.eclipse.jdt.ui.text.codetemplates.delegatecomment"    
  56.                 name = "delegatecomment" >   
  57.     /**  
  58.      * ${tags}  
  59.      * ${see_to_target}  
  60.      */  
  61.     </ template >   
  62.       
  63.       
  64.     < template   
  65.                 autoinsert = "false"    
  66.                 context = "filecomment_context"    
  67.                 deleted = "false"    
  68.                 description = "Comment for created Java files"    
  69.                 enabled = "true"    
  70.                 id = "org.eclipse.jdt.ui.text.codetemplates.filecomment"    
  71.                 name = "filecomment" >   
  72.     /**  
  73.      * 文件名:${file_name}  
  74.      *  
  75.      * 版本信息:  
  76.      * 日期:${date}  
  77.      * Copyright 足下 Corporation ${year}   
  78.      * 版权所有  
  79.      *  
  80.      */  
  81.     </ template >   
  82.       
  83.       
  84.     < template    
  85.                 autoinsert = "false"    
  86.                 context = "gettercomment_context"    
  87.                 deleted = "false"    
  88.                 description = "Comment for getter method"    
  89.                 enabled = "true"    
  90.                 id = "org.eclipse.jdt.ui.text.codetemplates.gettercomment"    
  91.                 name = "gettercomment" >   
  92.     /**  
  93.      * ${bare_field_name}  
  94.      *  
  95.      * @return  the ${bare_field_name}  
  96.      * @since   CodingExample Ver(编码范例查看) 1.0  
  97.     */  
  98.     </ template >   
  99.   
  100.     < template    
  101.                 autoinsert = "true"    
  102.                 context = "overridecomment_context"    
  103.                 deleted = "false"    
  104.                 description = "Comment for overriding methods"    
  105.                 enabled = "true"    
  106.                 id = "org.eclipse.jdt.ui.text.codetemplates.overridecomment"    
  107.                 name = "overridecomment" >   
  108.     /* (non-Javadoc)  
  109.      * ${see_to_overridden}  
  110.      */  
  111.     </ template >   
  112.       
  113.       
  114.     < template    
  115.                 autoinsert = "false"    
  116.                 context = "fieldcomment_context"    
  117.                 deleted = "false"    
  118.                 description = "Comment for fields"    
  119.                 enabled = "true"    
  120.                 id = "org.eclipse.jdt.ui.text.codetemplates.fieldcomment"    
  121.                 name = "fieldcomment" >   
  122.     /**  
  123.      * ${field}:${todo}(用一句话描述这个变量表示什么)  
  124.      *  
  125.      * @since Ver 1.1  
  126.      */  
  127.     </ template >   
  128.       
  129.       
  130.     < template    
  131.                 autoinsert = "false"    
  132.                 context = "typecomment_context"    
  133.                 deleted = "false"    
  134.                 description = "Comment for created types"    
  135.                 enabled = "true"    
  136.                 id = "org.eclipse.jdt.ui.text.codetemplates.typecomment"    
  137.                 name = "typecomment" >   
  138.     /**  
  139.      * 此类描述的是:  
  140.      * @author: [email protected]  
  141.      * @version: ${date} ${time}   
  142.      */  
  143.     </ template >   
  144.    
  145.  </ templates >  

你可能感兴趣的:(java,eclipse,Date,javadoc,tags,encoding)