Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 319506 - Allow renaming class via constructor
Summary: Allow renaming class via constructor
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 9.5.0   Edit
Assignee: Ian Leslie CLA
QA Contact: Sergey Prigogin CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-12 02:57 EDT by Dmitry Matveev CLA
Modified: 2018-04-08 01:19 EDT (History)
5 users (show)

See Also:


Attachments
Swtich the binding for renaming of ctor's and dtor's to rename the class (2.44 KB, patch)
2013-02-08 22:14 EST, Ian Leslie CLA
no flags Details | Diff
Update patch to include test cases (6.30 KB, patch)
2013-02-19 11:10 EST, Ian Leslie CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Matveev CLA 2010-07-12 02:57:46 EDT
Build Identifier: I20100608-0911

struct ClassWithCCtor {
	ClassWithCCtor();

	ClassWithCCtor(const ClassWithCCtor&);
};

For above code "Rename refactoring" for type ClassWithCCtor should be executed when "Rename refactoring" is called with cursor standing on any "ClassWithCCtor" token. It can be type identifier in struct declaration, type reference in copy constructor parameter declaration, or the constructor declarations. The later case isn't working and there are "constructor cannot be renamed" message box appearing instead. Being formally correct this message box is useless and it will be much better to just open refactoring dialog for "ClassWithCCtor" type.

Reproducible: Always
Comment 1 Ian Leslie CLA 2013-02-08 22:14:41 EST
Created attachment 226804 [details]
Swtich the binding for renaming of ctor's and dtor's to rename the class

Since the CRenameMethodProcessor processor delegate will not rename a constructor or a destructor for a class I added some code to CRenameProcessor to change the argument's IBinding to point to the class instead.  Using ICPPMember.getClassOwner() method to update the binding before the processor delegate is created means that CRenameProcessor will create a CRenameClassProcessor processor delegate instead and the class will be renamed.

I added a private method updateBinding to handle this update (and any future updates) but if anyone has a better name please suggest one.  The new updateBinding method is being called from CRenameProcessor.checkInitialConditions just before the processor delegate factory method is invoked.

I have tested renaming all the tokens mentioned in the defect in both the .h and .cpp files.  I have also checked that the dialog and the preview works as well.  Please let me know if there are any other areas I should test in addition.
Comment 2 Sergey Prigogin CLA 2013-02-09 19:31:16 EST
(In reply to comment #1)
Thank you for providing the patch. Could you please add a test case to org.eclipse.cdt.ui.tests.refactoring.rename.RenameTypeTests and push the updated change to Gerrit (http://wiki.eclipse.org/CDT/git#Using_Gerrit_for_CDT).
Comment 3 Ian Leslie CLA 2013-02-19 11:10:47 EST
Created attachment 227265 [details]
Update patch to include test cases

I am unable to connect to Gerrit from my dev environment at the moment.  I can access it via the web but neither https nor ssh connections work from in Eclipse.  While I am working on sorting that out here is an updated patch with test cases.
Comment 4 Martin Oberhuber CLA 2018-03-13 20:59:36 EDT
This is still an issue with 9.4.2 / Photon M6.

See also https://github.com/LegalizeAdulthood/refactor-test-suite Rename.cpp 
testcases R2 and R32.

The workaround is obviously press F3 to navigate to the class declaration, then refactor from there. 

But other tools (like Visual Studio 2017) can apparently handle the case, it would be nice to get the patch applied. See https://github.com/LegalizeAdulthood/refactor-test-suite/blob/master/results/VisualStudio2017Results.md
Comment 5 Nathan Ridge CLA 2018-03-15 11:41:57 EDT
Ian, have you had any luck getting Gerrit to work?

If you're still having trouble, please let us know what error you are seeing, and we can try to help.
Comment 6 Eclipse Genie CLA 2018-03-23 21:35:08 EDT
New Gerrit change created: https://git.eclipse.org/r/120112
Comment 7 Nathan Ridge CLA 2018-03-23 21:36:30 EDT
Ian indicated to me over email that he no longer has a development environment for this set up, so I submitted the patch to Gerrit on his behalf.
Comment 9 Nathan Ridge CLA 2018-04-08 01:19:15 EDT
Fixed for 9.5.