我正在编写自定义重构,用于在Eclipse RCP应用程序中重命名项目/文件夹/文件。我已经扩展了Refactoring类并编写了我自己的ResourceChange类,我通过调用IProject.move()方法来更新项目资源。
重命名工作正常,但项目下的资源路径未更新。
任何指针都会有所帮助。
感谢。
更新
重构类代码:
@Override
public Change createChange(IProgressMonitor pm) {
pm.beginTask("Renaming", 1);
CompositeChange change = new CompositeChange("Renaming");
if(resource instanceof IProject) {
return new CustomResourceChange((IProject)resource, resourceName);
}
pm.done();
return change;
}
CustomResourceChange类代码:
protected IPath createNewPath() {
return modifiedResourcePath.removeLastSegments(1).append(resourceNewName);
}
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask("Renaming Project", 1);
Change change = new CustomResourceChange(modifiedResource, createNewPath(), resourceOldName, resourceNewName);
IProject project = (IProject)ResourcesPlugin.getWorkspace().getRoot().findMember(modifiedResourcePath);
if (project != null) {
IProjectDescription description = project.getDescription();
description.setName(resourceNewName);
project.move(description, IResource.FORCE, new SubProgressMonitor(pm, 1));
}
return change;
} finally {
pm.done();
}
}