How can I configure Eclipse to generate getters and setters with some prefix for argument variable?
Example:
private String someVariable;
public void setSomeVariable(String aSomeVariable) {
this.someVariable = aSomeVariable;
}
How can I configure Eclipse to generate getters and setters with some prefix for argument variable?
Example:
private String someVariable;
public void setSomeVariable(String aSomeVariable) {
this.someVariable = aSomeVariable;
}
You can select the variable(s) and right click > source > Generate getters and setters. If you only want setters uncheck the getVariable() option.
You can update all generated variables with a prefix by going to preferences > java > Code Style and selecting Parameters then edit. You can add a prefix/suffix for all generated variable names.
there are two thing that you need to do to effect the setter in your example.
first, as others have mentioned, you will need to go to the Preferences dialog and go to Java/Code Style/Code Templates/Code/Setter body. in the Pattern box, you should make the value to look like this:
this.${field} = ${param};
second, still in the Preferences dialog, go up a level to Code Style. Here you will see a table 'Conventions for variable names.' Select the Parameters row and select edit. add the letter a
to the prefix field.
Once all of that is saved, you should be able to automatically generate setters as you have defined above, using the Generate Getter and Setter" command.