关闭

Eclipse自动生成作者、日期注释等最强功能设置

标签: eclipse自动生成注释
1197人阅读 评论(1) 收藏 举报
分类:

在使用Eclipse 编写Java代码时,自动生成的注释信息都是按照预先设置好的格式生成的。

修改作者、日期注释格式:打开Windows->Preferences->Java->Code Style->Code Templates,点击右边窗口中的import如下codetemplates.xml即可。
这里写图片描述

codetemplates.xml

<?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">
 /**
 * @return 获得 ${bare_field_name}
 */</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">
 /**
 * @param ${param} 设置 ${bare_field_name}
 */</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">/**
* &lt;p&gt;Title: &lt;/p&gt;
* &lt;p&gt;Description: &lt;/p&gt;
* ${tags}
*/</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">/**&#13;
* &lt;p&gt;Title: ${file_name}&lt;/p&gt;&#13;
* &lt;p&gt;Description: &lt;/p&gt;&#13;
* &lt;p&gt;Copyright: Copyright (c) 2007&lt;/p&gt;&#13;
* &lt;p&gt;Company: LTGames&lt;/p&gt;&#13;
* @author linrz&#13;
* @date ${date}&#13;
* @version 1.0&#13;
*/</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">
 /**
 *  Class Name: ${file_name}
 *  Function:
 *  
 *     Modifications:   
 *  
 *  @author DengAo  DateTime ${date} ${time}    
 *  @version 1.0 
 *  ${tags}
 */</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">/** ${field}*/</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">
 /**
 *  Function:
 * &lt;p&gt;Title: ${enclosing_method}&lt;/p&gt;
 * &lt;p&gt;Description: &lt;/p&gt;
 *  @author DengAo  DateTime ${date} ${time}
 *  ${tags}
 */</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">/* (非 Javadoc)
* &lt;p&gt;Title: ${enclosing_method}&lt;/p&gt;
* &lt;p&gt;Description: &lt;/p&gt;
* ${tags}
* ${see_to_overridden}
*/</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">
 /**
 * ${tags}
 * ${see_to_target}
 */</template><template autoinsert="false" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">${filecomment}   
${package_declaration}   
/**   
* Filename:    ${file_name}   
* Copyright:   Copyright (c)2010  
* Company:     com  
* @version:    1.0   
* @since:  JDK 1.6.0_21  
* Create at:   ${date} ${time}   
* Description:  
*   
* Modification History:   
* Date    Author      Version     Description   
* ----------------------------------------------------------------- 
* ${date} daniel      1.0     1.0 Version   
*/   
${typecomment}   
${type_declaration}  
${filecomment}
${package_declaration}
/**
* Filename:    ${file_name}
* Copyright:   Copyright (c)2010
* Company:     com
* @version:    1.0
* @since:       JDK 1.6.0_21
* Create at:   ${date} ${time}
* Description:
*
* Modification History:
* Date     Author           Version           Description
* ------------------------------------------------------------------
* ${date}       daniel             1.0          1.0 Version
*/
${typecomment}
${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">
</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">
</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">
</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">
</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
${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
${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}
// ${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>

注意:

使用快捷键 shift + alt + j 添加注释,如果想添加函数功能注释,需要先将光标放到需要添加注释的地方,然后在使用shift + alt + j

这样再创建 .java 文件时,eclipse 就会为我们自动将注释写好。你还可以通过“导出”、“导入”功能,把自己的模板导出来,方便在其他机器上使用。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:59228次
    • 积分:1296
    • 等级:
    • 排名:千里之外
    • 原创:71篇
    • 转载:0篇
    • 译文:0篇
    • 评论:32条