My aim is to programmatically call the Refactor >> Rename
Eclipse command for a method inside a Java Source File. Renaming a method as such should also apply the change to all the instances where this method is being used/referred.
I believe that JDT has a Refactoring API, but not able to find any documents or tutorials for the same.
Can somebody point me in the right direction.
Edit: The change is not needed at runtime.
I think your most promising approach is to go to the eclipse source code.
The starting point corresponding to
Refactor >> Rename
isorg.eclipse.jdt.ui.actions.RenameAction
. That's for the overall rename refactoring though, it can rename anything from methods to files. More relevant for you isRenameSupport.create(IMethod, String, int)
.You can see there that a
RenameRefactoring
class is created around either a processor, either aRenameVirtualMethodProcessor
or aRenameNonVirtualMethodProcessor
, and then sent to a new instance ofRenameSupport
.RenameSupport
handles all the UI to configure your refactoring, but since you're doing it programatically you just need theRenameRefactoring
and the processor, configured using the variousprocessor.set*()
methods.Now you have a configured instance of
RenameRefactoring
. Now what? The actual operation in Eclipse is executed across two Job implementations. Take a look atRefactoringExecutionHelper.Operation
andPerformChangeOperation
for the details.What does this all boil down to? Leaving aside all the fine details of exception handling, having an undo stack, and workspace checkpoints, you could rename a 'virtual' method using these steps:
There's a lot of support code in there for undo, progress bars, async execution, workspace checkpoints etc, which you may or may need depending on how you want to run this. But that's the guts of how to run the refactoring.
i think this will help you if that what you are looking for.