您的位置:首页 > 编程语言 > Java开发

在Eclipse中为新建java文件自动添加文件头

2011-07-08 16:53 537 查看
1. 打开菜单:"Window->Preferences->Java->Code Style->Code Templates",在右侧可以配置代码和注释的格式;
2. 选择其中的"Code->New Java files", 在"Pattern:"文本框中可以看到如下内容:
${filecomment}
${package_declaration}

${typecomment}
${type_declaration}
这4个都是变量,我最关心的是$(filecomment),如何知道这个变量代表什么内容呢?这一点Eclipse做的不好,没有在明显的地方的说明,不过你可以按照如下操作找到各个变量代表的实际内容:在"Configure generated code and comments"文本框中随便选中一项,比如选择"New Java files",点击“Edit...”,在出现的对话框中选择"Insert Variable..."会出现一个下拉菜单,其中每个变量都在右侧有个浮动的窗口显示其内容说明。
3. 我想在${filecomment}中配置文件头的内容,因此根据该变量的内容提示,找到真正的编辑位置为"Comments->Files",编辑其中的内容,使其符合我的需要,比如我编辑的文件头如下:
/**
* Filename : ${file_name}
* Author : xxxxxxx
* Creation time : ${time} - ${date}
* Description :
*/
其中${file_name},${time} ,${date}都是eclipse的内置变量
4. 最后使定制的文件头生效,勾选页面下方的"Automatically add comments for new methods and types"(老版Eclipse的这个选项在上一层菜单中:"Code Style")

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: