Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] CDT Refactoring Question

Disclaimer:  I'm still learning how CDT does refactoring and have not worked with its rename action, so be skeptical of anything I say here. :-)

From looking at the source, it appears that CRenameProcessor creates and uses a CRenameProcessorDelegate to do the actual work for different kinds of elements.  I think you can use this to your advantage by defining your own RefactoringProcessor subclass which is similar to CRenameProcessor but calls your own delegate class.  That delegate creates separate CRenameProcessorDelegate instances for each of your multiple elements.  In your delegate's checkInitialConditions() method, it calls each element-specific delegate's checkInitialConditions() and combining their statuses.  In checkFinalConditions(), it calls each element-specific delegate to store its changes in the shared CRenameProcessorDelegate.fChanges array.  A single call to CRenameProcessorDelegate.createChange() should then combine all those changes into a single Change object.

The advantage to this approach is that you have more control over the refactoring's lifecycle via the LTK, and just use the CDT rename refactoring package as a library.  If you don't want to run this from within the IDE, you can still lift code from the LTK's RefactoringProcessor framework to directly drive your refactoring.  Because the LTK was designed to work with multiple language plug-ins, it should be easier to use outside of the IDE than CDT.


On Thu, Jan 8, 2009 at 6:03 AM, Adam Neal <Adam_Neal@xxxxxxxxxx> wrote:

Hi Tom, thanks for the reply. A couple follow up questions.

To start, I am only interested in using the Change result from the rename refactoring. I found the code to invoke the CDT renaming, but its all internal. I'm using the following (which was taken from one of the tests)

CRefactoringArgument iarg = ...
CRenameProcessor processor = new CRenameProcessor(CRefactory.getInstance(), iarg);
processor.setSelectedOptions(-1); // ? - not sure what this does
CRenameRefactoring refactor = new CRenameRefactoring(processor);
RefactoringStatus stat = refactor.checkAllConditions(pm);
if (!stat.hasErrors()) {
cdtChange = refactor.createChange(pm);

Everything from CDT is internal though.

My two questions are as follows:
1) Is there a public way for me to invoke the refactoring? (and get the Change object)
2) Is there a better way of invoking the refactoring on multiple elements than calling the above code in a loop for each element?
- I would assume it would be done by having the CRefactoringArgument specify the different elements, but I don't see a way to chain CRefactoringArgument elements together or to specify more than one location....


Adam Neal

Inactive hide details for Tom Ball <tball@xxxxxxxxxx>Tom Ball <tball@xxxxxxxxxx>


"CDT General developers list." <cdt-dev@xxxxxxxxxxx>



Re: [cdt-dev] CDT Refactoring Question

On Thu, Dec 18, 2008 at 3:58 AM, Adam Neal <Adam_Neal@xxxxxxxxxx> wrote:
    Hi, I tried asking this on the newsgroup, but to no avail.

    I would like to reuse the CDT refactor engine to implement a feature I am working on (in non CDT source). A few quick questions while I am investigating:
    1) Is it possible for me to invoke the refactor engine programmatically rather than just through the UI?

Yes, check out org.eclipse.cdt.ui.tests.refactoring.RefactoringTest and its subclasses.
    2) Can we provide multiple elements to refactor rather than one at a time? (e.g. a pair of method's)

That's up to the refactoring you write. Rename, for example, may appear to only change one element, but it has a ripple effect as it changes the dependencies to that element.
    3) Can we suppress the UI during the refactor if we want?

Again, that's up to your refactoring. User feedback is an important part of any good refactoring tool's design, however.
    4) Where is a good starting point in the source for me to accomplish this?

Look at the simpler refactorings, such as ExtractConstant, to get your feet wet. If that's too complicated for your needs, consider using LTK instead. LTK is the common refactoring support which JDT, CDT, and other language support modules extend.

Tom _______________________________________________
cdt-dev mailing list

cdt-dev mailing list

GIF image

GIF image

Back to the top