Eclipse重命名/重构覆盖

Ang*_*gel 13 eclipse refactoring overriding rename

我是eclipse插件开发的新手.我想自定义项目的重命名.我需要验证新名称.那么如何覆盖eclipse的重命名/重构方法呢?

我看到了与RenameParticipant有关的东西,但是没有清楚地理解.如果有人可以解释我重写重命名功能的步骤,那就太好了.

非常感谢,安

rep*_*mer 14

重命名重构有几个处理器,它们是子类org.eclipse.ltk.core.refactoring.participants.RenameProcessor并负责重命名不同的元素.例如,有一个用于重命名Java项目的处理器org.eclipse.jdt.internal.corext.refactoring.rename.RenameJavaProjectProcessor.重构参与者可以参与条件检查并更改重构处理器的创建.例如,要在重命名重构期间检查某些条件,您应该子类化org.eclipse.ltk.core.refactoring.participants.RenameParticipant,覆盖方法org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant.checkConditions(IProgressMonitor, CheckConditionsContext)并通过扩展点注册参与者org.eclipse.ltk.core.refactoring.renameParticipants.参与者org.eclipse.jdt.internal.corext.refactoring.nls.NLSAccessorFieldRenameParticipant为您提供了一个如何参与重命名重构的好例子.

当您声明org.eclipse.ltk.core.refactoring.renameParticipants扩展点的扩展名时,您应该指定您希望您的参与者收到通知的元素.例如,请查看org.eclipse.ltk.core.refactoring.renameParticipants扩展点的以下使用如何org.eclipse.jdt.ui/plugin.xml使参与者重命名字段.

<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>
Run Code Online (Sandbox Code Playgroud)