eclipse/plugins/org.eclipse.jdt.ui_*.jar为如下版本的也可跳过此步
3.8.2.v20130107-165834java
用git下载源码git://git.eclipse.org/gitroot/jdt/eclipse.jdt.ui.gitgit
将版本历史切换到eclipse/plugins/org.eclipse.jdt.ui_*.jar包打包以前的最新版本eclipse
将其中的四个项目(org.eclipse.jdt.core.manipulation、org.eclipse.jdt.ui、 org.eclipse.ltk.core.refactoring、org.eclipse.ltk.ui.refactoring)导入 workspaceui
切换到项目org.eclipse.jdt.ui,配置Build Path,切换到Libraries,点击Add External JARs,找到eclipse/plugins目录,找到其中的org.eclipse.jdt.core_*.jar和 org.eclipse.jface.text_*.jar添加到项目依赖包中。(此时项目可能依然有类报错,不要紧,只要咱们要改的类不报错就好了)this
而后打开core extension源码目录,找到其中的org.eclipse.jdt.internal.corext.codemanipulation.GetterSetterUtil类spa
搜索关键字"CodeGeneration.getSetterComment"和"CodeGeneration.getGetterComment",分别在这两个查找到的内容下面一行中加入如下代码:.net
ISourceRange sr= field.getJavadocRange(); if (null != sr) { String filedComment= field.getSource(); filedComment= filedComment.substring(0, sr.getLength()) .replaceAll("[\n,\r,*,/,\t]", "") .trim(); //$NON-NLS-1$ //$NON-NLS-2$ comment= comment.replace("#{bare_field_comment}", filedComment); //$NON-NLS-1$ }
修改完GetterSetterUtil后保存,以后到项目的bin目录下找到该类编译后的class文件复制出来。code
GetterSetterUtil$20130107-165834.classip
GetterSetterUtil$3.9.50.v20140317-1811.class
GetterSetterUtil$3.10.0.v20140604-1403.class
注:下载后,将文件名修改成GetterSetterUtil.class便可使用
导入前关闭eclipse
用winrar或相似解压缩软件打开eclipse/plugins/org.eclipse.jdt.ui_*.jar,找到 org.eclipse.jdt.internal.corext.codemanipulation.GetterSetterUtil类,将复制的 class拖入替换
启动eclipse
模板下载及导入方法参看 Eclipse for Jee的安装与配置
定义属性如:
private String uuserid
在属性上方输入代码"/**",而后回车,添加相关注释如,用户ID
/** * 用户ID */ private String uuserid
使 用快捷键 shift+alt+s 打开源码控制面板,选择Generate Getters and Setters...,而后勾选要生成的get/set方法,Insertion point选择Last member(意为将方法生成在类的末尾),勾选Generate method comments,点击OK
便可在类的最后生成代码以下:
/** * 获取 用户ID * @return uuserid */ public String getUuserid() { return uuserid; } /** * 设置 用户ID * @param uuserid 用户ID */ public void setUuserid(String uuserid) { this.uuserid = uuserid; }