我是eclipse插件开发的新手。我想自定义项目的重命名。我需要验证新名称。那么如何覆盖 eclipse 的重命名/重构方法呢?
看到RenameParticipant相关的东西,但是没看明白。如果有人可以向我解释覆盖重命名功能的步骤,那就太好了。
非常感谢,
安
最佳答案
重命名重构有几个处理器子类 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>
关于Eclipse 重命名/重构覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6618495/