Eclipse为域对象和具有'm'后缀的类成员生成getter / setter [英] Eclipse generate getter/setter for domain objects and classmembers with 'm' suffix

查看:121
本文介绍了Eclipse为域对象和具有'm'后缀的类成员生成getter / setter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在我的域对象中生成的getter和setter方法的小问题。
我想为我的源代码使用通用的样式指南。该风格指南的一部分说,我启动每个成员名称,前缀m为成员。

I have a small question regarding generated getter and setter methods in my domain objects. I want to use a common style guide for my source code. One part of that style guide says that I start each class member name with the prefix 'm' for member.

class User{
String mName;
List<Call> mAllCall;
List<Geo> mAllGeo;

不幸的是,我有几个类有更多的成员变量。我的问题是,我是一个非常懒惰的开发人员,而且我在Eclipse中创建了getter和setter方法,其中

Unfortunately I have a couple of classes with many more member variables. The problem I have is that I am a very lazy developer, and that I create the getter and setter methods in Eclipse with


Source - >生成Getters和Setter。

"Source"->"Generate Getters and Setters".

结果是

public String getmName() {
    return mName;
}
public void setmName(String mName) {
    this.mName = mName;
}
public List<Call> getmAllCall() {
    return mAllCall;
}
public void setmAllCall(List<Call> mAllCall) {
    this.mAllCall = mAllCall;
}
public List<Geo> getAllGeo() {
    return mAllGeo;
}
public void setmAllGeo(List<Geo> mAllGeo) {
    this.mAllGeo = mAllGeo;
}

这不是我想要的结果。我需要这样:

That is not the result I want. I need this:

public String getName() {
    return mName;
}
public void setName(String pName) {
    this.mName = pName;
}
public List<Call> getAllCall() {
    return mAllCall;
}
public void setAllCall(List<Call> pAllCall) {
    this.mAllCall = pAllCall;
}
public List<Geo> getAllGeo() {
    return mAllGeo;
}
public void setmAllGeo(List<Geo> pAllGeo) {
    this.mAllGeo = mAllGeo;
}

我目前正在手动删除和替换方法名称中的前缀。有更简单的方法吗?

I currently remove and replace the prefix in the method names by hand. Is there an easier way to do this?

推荐答案

对于前缀 m ,您可以在 Java代码样式中将字母 m 添加到您的前缀列表中。

For the prefix m, you add the letter m to your list of prefixes in the Java Code Style.

按照以下步骤操作:


  1. 打开首选项

  2. 在左侧面板中,展开 Java

  3. 展开代码样式

  4. 右侧面板您现在应该查看

  1. open Preferences,
  2. in left panel, expand Java,
  3. expand Code Style,
  4. right panel is where you should now be looking at

您将看到一个包含字段,静态字段等的列表。这是您需要修改的内容

You will see a list with Fields, Static Fields, etc. This is what you need to modify.

设置 m 针对字段

根据参数设置 p

作为名称现在将不同于参数的名称,这个。资格将不再被自动添加。但是,您可以检查选项使用此限定所有生成的字段访问权限。

As the name of the field will now be different from the name of the argument, the this. qualification will no longer be added automatically. However, you can check the option Qualify all generated field accesses with 'this.' to have it again.

我想你知道在窗口左上角和右侧的启用项目特定设置配置工作区设置... 之间的区别

I suppose that you know the difference between Enable project specific settings and Configure Workspace Settings... in the upper left and right of the window?

这篇关于Eclipse为域对象和具有'm'后缀的类成员生成getter / setter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆