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;
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"->"Generate Getters and Setters".
The result is
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?
Getter blocks are expressions that get the current value of the property. Setter blocks are commands that change the value associated with the property.
To achieve this, you must: declare class variables/attributes as private. provide public get and set methods to access and update the value of a private variable.
For the prefix m
, you add the letter m
to your list of prefixes in the Java Code Style.
Follow these steps:
You will see a list with Fields, Static Fields, etc. This is what you need to modify.
Set m
against Fields.
Set p
against the Parameter.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With