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
修改样例:
- // 修改前
- /**
- * The date variable evaluates to the current date.
- */
- public static class Date extends SimpleTemplateVariableResolver {
- /**
- * Creates a new date variable
- */
- public Date() {
- super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- protected String resolve(TemplateContext context) {
- return DateFormat.getDateInstance().format(new java.util.Date());
- }
- }
- // 修改后
- /**
- * The date variable evaluates to the current date.
- */
- public static class Date extends SimpleTemplateVariableResolver {
- /**
- * Creates a new date variable
- */
- public Date() {
- super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- protected String resolve(TemplateContext context) {
- //return DateFormat.getDateInstance().format(new java.util.Date());
- // 这里做了修改
- final SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
- return df.format(new java.util.Date());
- }
- }
因这个类比较基础,一般不会有什么变动,所以我一般都是把编译好的Class覆盖到新版本的Jar包中就可以了。
编译后Class文件:GlobalTemplateVariables_class (145)
覆盖到架包org.eclipse.text中的org.eclipse.jface.text.templates路径下即可(可以用解压软件打开)。
4. 修改用户变量
可以添加Eclipse启动参数(我在使用Myeclipse时,使用如下参数好像导致Myeclipse不大稳定,寒!)
-vmargs -Duser.name=”huangys“