Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the settings to modify the default getter and setter methods provided by Eclipse?

Tags:

java

eclipse

I am using Eclipse Kepler for developing my Java project.I have created one vo and added some properties into the vo.To generate the getter and setter methods for those properties,I right click on one property and go to "Source" then click on the "Generates Getters and Setters". It is showing me the available getter/setter methods for properties. below is the screen shot

enter image description here

As you can see in the above screen shot, Eclipse is providing me getter and setter methods for property sId are

public String getsId() {
        return sId;
}

public void setsId(String sId) {
        this.sId = sId;
}

The first letter after get and set is in small letter (getsId and setsId).

For property uid Eclipse is creating the desired getter and setter methods.

My observation is that any property whose 2nd letter is in capital( For example- sId : 1st letter (s) is in small and 2nd letter (I) is in capital) eclipse is generating the getter and setter in below format

get+property name
set+property name

But if the 2nd letter of the property is in small letter eclipse is generating the getter and setter in below format

get+1st letter in capital letter+ rest of the property name
set+1st letter in capital letter+ rest of the property name

Even, if the 1st letter of the property is in capital letter, eclipse is generating the getter and setter in below format

get+1st letter (which is already in capital) + rest of the property name
get+1st letter (which is already in capital) + rest of the property name

I don't know whether this is an Eclipse bug or not (apart form Kepler, I also checked the same in Eclipse Luna) but I want the getter and setter for property sId (2nd letter is in capital) should be just like below

get+1st letter in capital letter + rest of the property name
set+1st letter in capital letter + rest of the property name

Is there any option available in Eclipse to modify the default getter and setter methods provided by Eclipse?

Or I can not modify the default getter and setter methods provided by Eclipse using any settings and I need to do it manually in the source code after generated by eclipse.

like image 229
Bacteria Avatar asked Jul 24 '15 12:07

Bacteria


1 Answers

There is a bug report for that and it won't be fixed. There you can see the discussion and reasons for the decision.

The gist is that generating a name like you want would actually violate the Java Beans specification, and the Eclipse JDT team has decided that adhering to that specification is more important than adhering to some conventions. You can agree or disagree with them on that importance decision, but it's a difficult catch-22.

like image 186
Florian Schaetz Avatar answered Oct 17 '22 01:10

Florian Schaetz