Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse rename/refactoring override

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

like image 754
Ann Avatar asked Jul 07 '11 23:07

Ann


People also ask

How do I undo refactoring in Eclipse?

Ctrl + z have you tried?

How do I Refactor a name in Eclipse?

Refactoring a method name is just as easy. For example, select the printem method and then select Refactor→ Rename, or right-click the variable and select Refactor→ Rename. This opens the Rename Method dialog shown in Figure 4-3, in which we're renaming the method to display .

What is Rename refactoring?

Use the Rename refactoring to change names of symbols, files, directories, packages, modules and all the references to them throughout code. Renaming local variables or private methods can be done easily inline since only the limited scope is affected.

How do I change multiple variable names in Eclipse?

Select the variable you with to change, right click, and select Refactor->Rename. This will highlight all instances of the variable. Changing the variable name is automatically propagated to all of the instances. Thanks.


1 Answers

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>
like image 186
reprogrammer Avatar answered Oct 07 '22 01:10

reprogrammer