How can I force eclipse to generate my setters with a return statement

1.1k views Asked by At

I want my eclipse to return this in a generated setter. This would be very useful for the Builder-Pattern

What eclipse does by default:

public void set{uppercase_field_name}({field_type} {field_name}) {
    this.name = name;
}

What i want eclipse to do:

public {class_type} set{uppercase_field_name}({field_type} {field_name}) {
    this.name = name;
    return this;
}

I found some templates that can be modified under:

Preferences -> Java -> Code Style -> Code Templates

But it is only possible to edit the body of the setter and not the setter signature.

1

There are 1 answers

0
Philipp Sander On

I found the answer very quickly after i googled some more:

Generate setters that return self in Eclipse

I find this approach even better, because i don't have to apply the build pattern every time i generate setters. Which by convention should always be void.