重构类和方法时,为什么 JDT 不更改引用的资源?

发布于 2025-01-08 16:29:01 字数 595 浏览 1 评论 0原文

重构类和方法时,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆依然 2025-01-15 16:29:01

嗯,我彻底研究了 JDT 并得出以下结论:

  1. 当前的 JDT API 在类和
    方法
  2. 在类和方法的情况下很难更改引用
    方法,因为它们不像包那样被引用,即
    my.package.util 很容易,其中 MyClass 没有引用,可以
    存在于多个包装中。

但如果JDT开发人员愿意花一些时间,那么它可以从已知的java框架(如springhibernate *iBatis*资源文件中完成)它,但这仍然需要花费大量的工作和时间。
解决方案是通过 IO 流进行重构,添加替换/更改条件,但这也会需要大量工作。

Well, I investigated JDT thoroughly and came to the following conclusion:

  1. The current JDT API has this maximum potential regarding classes and
    methods
  2. It's difficult to change the references in case of classes and
    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文