重构类和方法时,为什么 JDT 不更改引用的资源?
重构类和方法时,JDT 不会更改引用的资源,而重构包时会更改。我使用以下代码:
RefactoringContribution contrib = RefactoringCore.getRefactoringContribution(IJavaRefactorings.RENAME_COMPILATION_UNIT);
RenameJavaElementDescriptor desc = (RenameJavaElementDescriptor)contrib.createDescriptor();
desc.setUpdateReferences(true);
desc.setJavaElement(classToRename);
desc.setNewName(newName);
Refactoring ref = desc.createRefactoring(new RefactoringStatus());
IProgressMonitor monitor = new NullProgressMonitor();
Change change = refactoring.createChange(monitor);
change.perform(monitor);
建议会有所帮助:
When refactoring classes and methods JDT doesn't change referenced resources, while it does when refactoring packages. I use the following code:
RefactoringContribution contrib = RefactoringCore.getRefactoringContribution(IJavaRefactorings.RENAME_COMPILATION_UNIT);
RenameJavaElementDescriptor desc = (RenameJavaElementDescriptor)contrib.createDescriptor();
desc.setUpdateReferences(true);
desc.setJavaElement(classToRename);
desc.setNewName(newName);
Refactoring ref = desc.createRefactoring(new RefactoringStatus());
IProgressMonitor monitor = new NullProgressMonitor();
Change change = refactoring.createChange(monitor);
change.perform(monitor);
an advice will help:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,我彻底研究了 JDT 并得出以下结论:
方法
方法,因为它们不像包那样被引用,即
my.package.util 很容易,其中 MyClass 没有引用,可以
存在于多个包装中。
但如果JDT开发人员愿意花一些时间,那么它可以从已知的java框架(如spring,hibernate *iBatis*资源文件中完成)它,但这仍然需要花费大量的工作和时间。
解决方案是通过 IO 流进行重构,添加替换/更改条件,但这也会需要大量工作。
Well, I investigated JDT thoroughly and came to the following conclusion:
methods
methods because they are not referenced like packages i.e.
my.package.util is easy where MyClass has no reference and can be
present in more than one package.
But it can be done coming out of the known java frameworks like spring, hibernate *iBatis* resource files if JDT developers would give some time to it, but it will be still a whole lot of work and time spending.
The solution is to refactor yourself through IO streams by putting replacement/change conditions, but also it will be a lot of work.