1

The question

How do I configure automatically generated setter stuff in Eclipse?

Specifically, how do I configure stuff in the following list?

  1. Make the setter parameter final.
  2. Use the name newValue as the parameter name.
  3. Don't use this. when in the assignment.

Explanation

Currently, Eclipse generates setters like this:

private String blammo;

public void setBlammo(String blammo)
{
  this.blammo = blammo;
}

I would like to configure Eclipse to generate setters like this:

private String hooty;

public void setHooty(final String newValue)
{
  hooty = newValue;
}

Edit:

Why, you say?

This is strictly my opinion.

  1. Final parameters = good. Not final parameters = careless.
  2. newValue makes sense and fits well with #3 below. Do you really need to identify the value that the setHooty method will be setting? If yes, then your code has issues.
  3. this.hooty; why use this to reference my own menbers? I believe it adds no value and thus serves only to obfuscate the code.
DwB
  • 37,124
  • 11
  • 56
  • 82
  • possible duplicate of [How do I modify the set method signature that Eclipse auto generates?](http://stackoverflow.com/questions/1291625/how-do-i-modify-the-set-method-signature-that-eclipse-auto-generates). I can't delete the question because there are answers; so I voted to close it. my bad on the duplication. – DwB Jan 20 '12 at 20:05
  • As an aside, why do you want to do this? – Garrett Hall Jan 20 '12 at 20:36

2 Answers2

0

You can't do that specifically for getters and setters, but you can configure most of this in Window > Preferences > Java > Editor > Save Actions > Additional Actions

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
0

Unfortunately eclipse will not do that for you but there is a workaround. You can create a template for your setter and getter method and perform actions using Window->Preferences->Java->Editor-Save Actions.

You can see existing and create new template using Window->Preferences->Java->Editor->Templates.

This question is discussed here in detail.

Community
  • 1
  • 1
RanRag
  • 48,359
  • 38
  • 114
  • 167