13

I am new to eclipse plug-in development. I want to customize the renaming of a project. I need to validate the new name. So how can I override eclipse's rename/refactoring method?

I saw something related to RenameParticipant, but didn't understand clearly. It would be great if someone could explain me steps to override the renaming functionality.

Many Thanks, Ann

Ann
  • 231
  • 1
  • 4
  • 9

1 Answers1

15

The rename refactoring has several processors that subclass org.eclipse.ltk.core.refactoring.participants.RenameProcessor and are responsible for renaming different elements. For example, there is a processor for renaming Java projects org.eclipse.jdt.internal.corext.refactoring.rename.RenameJavaProjectProcessor. A refactoring participant can participate in the condition checking and change creation of a refactoring processor. For example, to check some conditions during a rename refactoring, you should subclass org.eclipse.ltk.core.refactoring.participants.RenameParticipant, override the method org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant.checkConditions(IProgressMonitor, CheckConditionsContext) and register the participant via the extension point org.eclipse.ltk.core.refactoring.renameParticipants. The participant org.eclipse.jdt.internal.corext.refactoring.nls.NLSAccessorFieldRenameParticipant gives you a good example of how to participate in a rename refactoring.

When you declare your extension of the org.eclipse.ltk.core.refactoring.renameParticipants extension point, you should specify the element you'd like your participant to get notified about. For example, see how the following use of the org.eclipse.ltk.core.refactoring.renameParticipants extension point in org.eclipse.jdt.ui/plugin.xml involves the participant in renaming fields.

<extension point="org.eclipse.ltk.core.refactoring.renameParticipants">
  <renameParticipant class="org.eclipse.jdt.internal.corext.refactoring.nls.NLSAccessorFieldRenameParticipant" id="org.eclipse.jdt.ui.NLSFieldRenameParticipant" name="%Refactoring.NLSFieldRenameParticipant">
    <enablement>
      <with variable="affectedNatures">
        <iterate operator="or">
          <equals value="org.eclipse.jdt.core.javanature"/>
        </iterate>
      </with>
      <with variable="element">
        <instanceof value="org.eclipse.jdt.core.IField"/>
      </with>
    </enablement>
  </renameParticipant>
</extension>
reprogrammer
  • 14,298
  • 16
  • 57
  • 93
  • Hi, Thanks for your reply. I subclassed RenameParticipant. Overrid method checkConditions. And registered the participant via extension point. Now it does validation for everything(ie for projects, files etc). I want validation only for project name. I didnt understand where I can place the RenameJavaProjectProcessor. Thanks, – Ann Jul 11 '11 at 00:12
  • `RenameJavaProjectProcessor` is in JDT and you don't have to worry about it. You just need to specify the element your participant works on when you declare your extension point in `plugin.xml`. See my updated answer on how to specify the element on which your participant operates. – reprogrammer Jul 11 '11 at 00:45
  • @reprogrammer I am stuck with similar problem now. I followed your steps and I get to update each time refactor happens, but I have my own custom editor and in this editor the refactor option is disabled and hence I am unable to perform refactor in this editor. – Destructor Aug 10 '14 at 13:33