Summary: | Code Generation for Builder and Factory classes | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Michael Knapp <michaelscottknapp> | ||||||
Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> | ||||||
Status: | ASSIGNED --- | QA Contact: | |||||||
Severity: | enhancement | ||||||||
Priority: | P3 | CC: | daniel_megert, helospark, jarthana, pyvesdev | ||||||
Version: | 4.5 | Keywords: | helpwanted | ||||||
Target Milestone: | --- | ||||||||
Hardware: | PC | ||||||||
OS: | Linux | ||||||||
Whiteboard: | |||||||||
Attachments: |
|
Description
Michael Knapp
2015-01-25 15:57:38 EST
If we were to consume this, I think the support should start from the UI. Moving to JDT UI for consideration. This bug hasn't received much attention, probably due to the fact that it's quite hard to find via the Bugzilla search and it does't seem to be referenced in Google. Nevertheless, it looks like quite a popular feature, at least according to this StackOverflow thread: https://stackoverflow.com/questions/29493898/automatically-create-builder-for-class-in-eclipse Is Builder class generation still a desirable feature to integrate into the JDT UI codebase? I have had a dig through the code of existing refactoring actions, and I would be happy to have a go at implementing this. (In reply to Pierre-Yves B. from comment #2) Can you provide an example in this bug here, so that one does not look at external resources? Created attachment 275530 [details]
Class before and after the builder is introduced
What I have in mind would be an "Introduce Builder..." tool, which would work similarly to the existing "Introduce Factory..." one. When selecting a constructor in a given class and using "Introduce Builder...", Eclipse would automatically generate a nested builder class which would make use of that constructor.
The Builder class would follow Joshua Bloch's popular builder pattern, as demonstrated in the attached example.
Some obvious user options that come to mind:
- allow customising the prefix of the builder methods (instead of "withSomeString" some users may want "addSomeString" or simply "someString".
- allow customising the name of the builder class.
- optionally switch the constructor for which the builder is introduced to private.
(In reply to Pierre-Yves B. from comment #4) Thanks. I have no objections if you want to work on this. To avoid duplicated efforts here consider, that I have created a standalone builder generator Eclipse plugin a while back: https://marketplace.eclipse.org/content/spark-builder-generator It can mostly do what was discussed, but cannot (yet) create builder for certain constructor. It is open source with a permissive licence, so feel free to reuse part of it, or integrate into that. (In reply to Helo Spark from comment #6) > To avoid duplicated efforts here consider, that I have created a standalone > builder generator Eclipse plugin a while back: > https://marketplace.eclipse.org/content/spark-builder-generator > > It can mostly do what was discussed, but cannot (yet) create builder for > certain constructor. > > It is open source with a permissive licence, so feel free to reuse part of > it, or integrate into that. I haven't had the time to properly look into this as I've been busy with quite a few other contributions. @Helo Spark maybe you can push this forward as you've already written most of the code to achieve the desired functionality? :) |