Search code examples
eclipse-jdteclipse-pdeautomated-refactoring

How can I call eclipse refactoring history programmatically?


If you go to Refactor -> History... in Eclipse you will see a Dialog with all the history of refactorings done in your workspace.

I would like to know if there is a way to create a plugin that simply counts how many let's say rename refactorings are in the history. How would you do that?


Solution

  • The IRefactoringHistoryService interface has methods to access the refactoring history.

    Get the interface with:

    IRefactoringHistoryService service = RefactoringCore.getHistoryService();
    

    You can then get the history for a project using:

    IProject project = ... project you are interested in
    
    RefactoringHistory history = service.getProjectHistory(project, progressMonitor);
    

    There are other methods which let you get the workspace history and specify start and end time stamps.

    The history object can return an array of objects representing the refactoring:

    RefactoringDescriptorProxy [] proxies = history.getDescriptors();
    

    You can get the actual refactoring descriptor from the proxy:

    RefactoringDescriptor desc = proxy.getDescription();