Eclipse getter/setter格式

Mar*_*eon 10 eclipse

有没有人知道Eclipse插件或方法让Eclipse在一行上生成getter/setter,如下所示:

public String getAbc() { return abc; }
Run Code Online (Sandbox Code Playgroud)

代替

public String getAbc() {
   return abc;
}
Run Code Online (Sandbox Code Playgroud)

我在Eclipse v.3.2.2上.

谢谢.

Hos*_*Aly 12

我不知道如何让Eclipse以你想要的格式生成它们,但是你可以在生成方法后使用这些正则表达式进行搜索/替换:

找:

(?m)((?:public |private |protected )?[\w$]+) (get|set|is)([\w$]+)\(([\w$]+(?:\[\])? [\w$]+)?\) \{\s+(return [\w$]+;|this.[\w$]+ = [\w$]+;)\s+\}
Run Code Online (Sandbox Code Playgroud)

替换为:

$1 $2$3($4) { $5 }
Run Code Online (Sandbox Code Playgroud)

此表达式将生成的getter和setter转换为一行.不要担心使用转换和新生成的方法混合运行它; 它会工作得很好.