Eclipse generates getter / setter for domain objects and class members with suffix 'm'

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

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

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

Source β†’ Generate Recipients and Setters.

Result

 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; } 

This 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 am currently deleting and replacing the prefix in the method names manually. Is there an easier way to do this?

+6
source share
3 answers

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

Follow these steps:

  • open Settings ,
  • in the left pane, expand Java ,
  • expand Code Style ,
  • The right panel is where you should now look

You will see a list with fields, static fields, etc. This is what you need to change.

Set m to the Fields field.

Set p for parameter .

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

I believe that you know the difference between Enable special project settings and Configure workspace settings ... in the upper left and right corner of the window?

+24
source

I don’t like this idea at all, but ..

You can write elements without the m prefix, let Eclipse create getters and setters, rename the elements later (Shift-Alt-R); Eclipse will change the links, but not (unless you explicitly communicate this) getter / setter signature.

+3
source

The getter and setter method names are produced on behalf of the field. If you use a prefix or suffix for fields (e.g. fValue, _value, val_m), you can specify suffixes and prefixes on the code style preferences page (Windows> Preferences> Java> Code Style).

link here

+1
source

All Articles