Java – IDE-Eclipse下的comment设置

来源:互联网 发布:淘宝客会推新店铺吗 编辑:程序博客网 时间:2024/06/15 06:03
转载请注明:KNOO博客
文章链接: http://www.knoo.info/blog/2010/09/java-eclipse-comment-setting/

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 (66)

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

4. 修改用户变量

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

-vmargs -Duser.name=”huangys

原创粉丝点击