Bug 306902 - Generate constructor using fields
Summary: Generate constructor using fields
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 enhancement with 8 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-24 00:20 EDT by Marc-André Laperle CLA
Modified: 2020-09-04 15:23 EDT (History)
7 users (show)

See Also:


Attachments
Screenshot of the prototype (168.31 KB, image/png)
2010-03-24 00:20 EDT, Marc-André Laperle CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc-André Laperle CLA 2010-03-24 00:20:30 EDT
Created attachment 162839 [details]
Screenshot of the prototype

In JDT, Source > Generate constructor using fields, is quite useful and saves a lot of time when in the process of creating new classes. I would like to see this in CDT.

I have started work on this and have a working prototype. But I am struggling with performance, as seen with the other refactorings. I have come to the conclusion that the performance problem should be its own bug since the changes necessary are in both in the respective refactorings and the common utitilies code. So, I suggest that I complete this refactoring without addressing the performance problem and try to fix the problem for all refactorings later which will lead to a cleaner solution.

I am attaching a screenshot to give a preview of the options available for the refactoring. If anyone can give me some feedback or suggestions, I would appreciate it. I hope to complete this in time for 7.0, if possible.
Comment 1 Simon Taddiken CLA 2013-05-21 02:44:50 EDT
Your solution looked pretty advanced. Why isn't there any progress on this? I'm interested in solving this too, if you stopped working on this.
Comment 2 Marc-André Laperle CLA 2013-05-21 10:45:24 EDT
(In reply to comment #1)
> Your solution looked pretty advanced. Why isn't there any progress on this?
> I'm interested in solving this too, if you stopped working on this.

I felt like there was not a lot of interest in this feature so it became lower priority to me. I still have the code on github but it's 2 years old. I'll update it and then we can look at finishing the feature.
Comment 3 Marc-André Laperle CLA 2013-05-22 22:52:35 EDT
I updated the code on github. You can find it here:
https://github.com/MarkZ3/Eclipse-CDT-WIP/tree/GenerateConstructor

There are a lot of things left to do:
- Add tests
- Implement the option "Initialize non parameter members"
- Fix the todos
- Automatically select the members that are selected in the editor
- Improve the code quality (I wasn't very familiar with CDT when I wrote the refactoring)

If you could try it and let me know what you think, that would be appreciated!
Comment 4 Scarl N CLA 2014-08-20 07:07:30 EDT
Gz~ I've been wanting it for years! I can't believe it's considered low priority. Think people just didn't voice out.
Comment 5 Stephan Bieband CLA 2017-07-21 15:41:26 EDT
I would really like to see this feature implemented. Is there any chance this will happen?
Comment 6 Marc-André Laperle CLA 2017-07-21 17:07:59 EDT
I will not be working on this but I think the Github branch is a good start, see
https://github.com/MarkZ3/Eclipse-CDT-WIP/tree/GenerateConstructor
Comment 7 Marco Stornelli CLA 2019-05-19 03:23:28 EDT
What's the current status of this patch? I looked at github repository, it seems you added tests for example. Do you need help?
Comment 8 Marc-André Laperle CLA 2019-05-19 22:58:56 EDT
(In reply to Marco Stornelli from comment #7)
> What's the current status of this patch? I looked at github repository, it
> seems you added tests for example. Do you need help?

I don't remember how well it works, it's been a while. If there is interest, I can try to finish it. I might need help testing it on real code bases as I have nothing I can use daily to test CDT with.
I was thinking of removing a lot of the options in order to make it simpler but still keep most of its usefulness. If you look at the screen shot, I was thinking of removing the section for choosing base constructor and just not generate the base constructor call. Also, always pass non-integral types by const-ref and integral (including pointers) as is. For initialization, always initialize with initialization list. Or we could even scrap initialization and it would still be useful to generate all parameters. WDYT?
Comment 9 Marco Stornelli CLA 2019-05-20 01:11:43 EDT
I agree, I think a basic implementation it's good, if requested we have time to add new features later. About base constructor call I see only the problem to call the base if the base has an explicit constructor with parameters. If you don't call it the code won't compile but on the other hand it's true that the code won't compile anyway if we are in this case and the class hasn't a constructor, the user receive a compilation error in both cases. It would be worth to check the behavior of jdt about the "super" call in constructor generation. In Java it's easier of course, just one "super" call.
About initialization list we need to create it with order of fields or the use will receive the reorder warning from compiler if the warning is enabled, I don't know if you already do it, I didn't check.
If you rebase the code on top of current master I test it on my code base.