Java – IDE-Eclipse下的comment设置

IDE-Eclipse下的Comment设置

1. 设置方式:

注释样式
Preference -> Java -> Code Style -> Code Template
Task Tags
Java -> Compiler -> Task Tags

Task Tags:标签管理功能。如常见的<TODO>标签是用来提示未完成操作,也可以在关键代码上添加标签,方便以后的代码维护。

2. Comment样式

Files
/**
* Copyright ${year} (C) , All Rights Reserved.
* Company: China.
*
* Create At ${date}.
*
*/
Types
/**
* <pre> <CLASS_DESC>.
*
* Modification Historty:
* Date Author Version Action
* ${date} ${user} v1.0 Create
* </pre>
*
* ${tags}
*/
Fields
/**
* <pre> <FIELD_DESC>. </pre>
*/
Constructors
/**
* <pre> <CTOR_DESC>. <pre>
*
* ${tags}
*/
Methods
/**
* <pre> <METHOD_DESC>.
*
* Modification Historty:
* Date Author Action
* ${date} ${user} Create
* </pre>
*
* ${tags}
*/

注:其中醒目颜色标注的内容应该添加至Task Tag中。

Task Tag的使用主要依赖Task View。(Window -> Show View -> Tasks

${user}长度可能有些不同,所以以上格式需做少量调整。

3. 日期格式

变量${date}默认日期格式为YYYY-MM-DD(可能和系统区域设置有关),如2010-4-15、2010-11-08。

这会使日期变量${date}长度不固定,影响到注释排版。

修改方式:

修改架包org.eclipse.text中的org.eclipse.jface.text.templates.GlobalTemplateVariables.java

Eclipse源码下载地址

修改样例:

  1. // 修改前  
  2. /** 
  3.  * The date variable evaluates to the current date. 
  4.  */  
  5. public static class Date extends SimpleTemplateVariableResolver {  
  6.     /** 
  7.      * Creates a new date variable 
  8.      */  
  9.     public Date() {  
  10.         super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$  
  11.     }  
  12.     protected String resolve(TemplateContext context) {  
  13.         return DateFormat.getDateInstance().format(new java.util.Date());  
  14.     }  
  15.   
  16. }  
  1. // 修改后  
  2. /** 
  3.  * The date variable evaluates to the current date. 
  4.  */  
  5. public static class Date extends SimpleTemplateVariableResolver {  
  6.     /** 
  7.      * Creates a new date variable 
  8.      */  
  9.     public Date() {  
  10.         super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$  
  11.     }  
  12.     protected String resolve(TemplateContext context) {  
  13.         //return DateFormat.getDateInstance().format(new java.util.Date());  
  14.         // 这里做了修改  
  15.         final SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");  
  16.         return df.format(new java.util.Date());  
  17.     }  
  18. }  

因这个类比较基础,一般不会有什么变动,所以我一般都是把编译好的Class覆盖到新版本的Jar包中就可以了。

编译后Class文件:GlobalTemplateVariables_class (145)

覆盖到架包org.eclipse.text中的org.eclipse.jface.text.templates路径下即可(可以用解压软件打开)。

4. 修改用户变量

可以添加Eclipse启动参数(我在使用Myeclipse时,使用如下参数好像导致Myeclipse不大稳定,寒!)

-vmargs -Duser.name=”huangys

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

最土老杨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值