码迷,mamicode.com
首页 > 系统相关 > 详细

如何给我们的eclipse新建文件自动生成注释

时间:2015-10-02 00:10:41      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:

有时候,我们需要给我们的文件加载注释,但手动给每一个方法,每一个类添加注释,非常的繁琐,幸好强大的eclipse已经为我们准备好了自动添加注释的配置文件,它就是——codetemplates.xml

如图所示:

  技术分享

  找到Preferences——Java——Code Style——Code Templates——“import”,导入我们所需要的codetemplates.xml文件,即可给我们的方法和类自动生成注释

  codetemplates内容如下:

    

  

  1 <?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
  2 
  3  * getter method
  4  * @return the ${bare_field_name}
  5  */
  6 
  7 </template><template autoinsert="false" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/**
  8 
  9  * setter method
 10  * @param ${param} the ${bare_field_name} to set
 11  */
 12 
 13 </template><template autoinsert="false" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
 14 
 15 
 16 
 17   * 创建一个新的实例 ${enclosing_type}. 
 18   * &lt;p&gt;Title: &lt;/p&gt;
 19   * &lt;p&gt;Description: &lt;/p&gt;
 20   * ${tags}
 21   */
 22 
 23 </template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/**
 24 
 25  * @Title: ${file_name}
 26  * @Package ${package_name}
 27  * @Description: ${todo}
 28  * Copyright: Copyright (c) 2011 
 29  * Company:和达信息系统有限公司
 30  * 
 31  * @author Comsys-${user}
 32  * @date ${date} ${time}
 33  * @version V1.0
 34  */
 35 
 36 </template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
 37 
 38   * @ClassName: ${type_name}
 39   * @Description: ${todo}
 40   * @author Comsys-${user}
 41   * @date ${date} ${time}
 42   *
 43   * ${tags}
 44 
 45   */
 46 
 47 </template><template autoinsert="false" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**
 48 
 49   * @Fields ${field} : ${todo}(用一句话描述这个变量表示什么)
 50 
 51   */
 52 
 53 </template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
 54 
 55   * ${enclosing_method}(这里用一句话描述这个方法的作用)
 56   * ${todo}(这里描述这个方法适用条件 – 可选)
 57   * ${todo}(这里描述这个方法的执行流程 – 可选)
 58   * ${todo}(这里描述这个方法的使用方法 – 可选)
 59   * ${todo}(这里描述这个方法的注意事项 – 可选)
 60   *
 61   * @Title: ${enclosing_method}
 62   * @Description: ${todo}
 63   * @param ${tags}    设定文件
 64   * @return ${return_type}    返回类型
 65   * @throws
 66   */
 67 
 68 
 69 
 70 
 71 
 72 </template><template autoinsert="false" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/*
 73 
 74   * &lt;p&gt;Title: ${enclosing_method}&lt;/p&gt;
 75   * &lt;p&gt;Description: &lt;/p&gt;
 76   * ${tags}
 77   * ${see_to_overridden}
 78   */
 79 
 80 
 81 
 82 </template><template autoinsert="false" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
 83 
 84   * ${tags}
 85   * ${see_to_target}
 86   */
 87 
 88 
 89 
 90 </template><template autoinsert="true" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">${filecomment}
 91 
 92 ${package_declaration}
 93 
 94 
 95 
 96 ${typecomment}
 97 
 98 ${type_declaration}</template><template autoinsert="true" context="classbody_context" deleted="false" description="Code in new class type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.classbody" name="classbody">
 99 
100 </template><template autoinsert="true" context="interfacebody_context" deleted="false" description="Code in new interface type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name="interfacebody">
101 
102 </template><template autoinsert="true" context="enumbody_context" deleted="false" description="Code in new enum type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.enumbody" name="enumbody">
103 
104 </template><template autoinsert="true" context="annotationbody_context" deleted="false" description="Code in new annotation type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name="annotationbody">
105 
106 </template><template autoinsert="true" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.catchblock" name="catchblock">// ${todo} Auto-generated catch block
107 
108 ${exception_var}.printStackTrace();</template><template autoinsert="true" context="methodbody_context" deleted="false" description="Code in created method stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodbody" name="methodbody">// ${todo} Auto-generated method stub
109 
110 ${body_statement}</template><template autoinsert="true" context="constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name="constructorbody">${body_statement}
111 
112 // ${todo} Auto-generated constructor stub</template><template autoinsert="true" context="getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.getterbody" name="getterbody">return ${field};</template><template autoinsert="true" context="setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.setterbody" name="setterbody">${field} = ${param};</template></templates>

 

如何给我们的eclipse新建文件自动生成注释

标签:

原文地址:http://www.cnblogs.com/cyh2009/p/4851739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!