Bug 148885 - [getter setter] code template option for chained setters
Summary: [getter setter] code template option for chained setters
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P5 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-27 16:08 EDT by John Troxel CLA
Modified: 2017-10-13 19:00 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Troxel CLA 2006-06-27 16:08:32 EDT
I think many programmers like to use chained setters, or "fluent interfaces" [Fowler].  It would be nice to have a generator, or an option in Generate Getters and Setters, to create a chainable setter method.  E.g.:

Public <type> <field_name>(<field_type> new<field_name>) {
   set<field_name>(new<field_name>);
   return this;
}
Comment 1 John Troxel CLA 2006-06-27 16:10:53 EDT
> It would be nice to have a generator, or an option in Generate
> Getters and Setters, to create a chainable setter method. 
... in *addition* to the normal void setter.
Comment 2 Martin Aeschlimann CLA 2006-06-28 04:52:57 EDT
Not the first request for more configurability of getter/setter templates. To make this happen we have to rewrite our code how code templates for getter/setters are used. We will have to see if we find time to do that:

- Allow to define more than one getter/setter template, and let the user choose one in the getter/setter wizard. Other features that generate a getter/setters (code assist, refactorings) might have to just take the default template if we don't have the possibility to show a UI

- change from getter/setter body and comment templates to templates for the full signature.

I'll add this as a plan candidate item.
Comment 3 Jeffery Yuan CLA 2017-10-13 19:00:56 EDT
We can just add a new option: return this or not to the "Generate Getters and Setters" dialog.

This feature is low-hanging fruit, but quite useful to our developers.
People been asked for it multiple times in stackoverflow.

https://stackoverflow.com/questions/12294627/generate-setters-that-return-self-in-eclipse
https://stackoverflow.com/questions/12294627/generate-setters-that-return-self-in-eclipse