获取给定 IProject 的所有依赖 IProject 引用

发布于 2024-10-06 11:11:14 字数 642 浏览 0 评论 0原文

我有一个 IProject,它也是一个 IJavaProject。我需要在工作区中查找引用此 IProject 的所有其他项目。

计算此值的一种简单且低效的方法是遍历工作区中的所有项目并跟踪对当前项目的引用。像这样的事情:

IProject currentProject = ...;

IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
List<IProject> interestingProjects = ...;
for (IProject project : allProjects) {
  if (refersToCurrentProject(project)) {
    interestingProjects.add(project);
  }
}
doSomething(interestingProjects);

注意-我还没有编译这段代码,而是从内存中编写的,所以它可能无法完全正常工作,我只是想表达我想要做什么。

另一种可能性是仅计算一次依赖关系,然后通过 IResourceChangedListener 更新依赖关系。但是,这也很混乱,我需要为此编写自己的(容易出错的)逻辑。

任何建议将不胜感激。

I have an IProject that is also an IJavaProject. I need to find all other projects in the workspace that refer to this IProject.

One simple and inefficient way of calculating this is to trawl through all projects in the workspace and keep track of references to the current project. Something like this:

IProject currentProject = ...;

IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
List<IProject> interestingProjects = ...;
for (IProject project : allProjects) {
  if (refersToCurrentProject(project)) {
    interestingProjects.add(project);
  }
}
doSomething(interestingProjects);

Note- I haven't compiled this code and I wrote it from memory, so it may not work exactly, I am only trying to give an idea of what I want to do.

Another possibility is to calculate the dependencies only once and then update the dependencies through an IResourceChangedListener. But, this is messy too and I need to write my own (error-prone) logic for that.

Any suggestions would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

祁梦 2024-10-13 11:11:14

我知道当您右键单击特定项目时,有一个上下文菜单选项可以关闭不相关的项目。你看过那个吗?

I know that there is a context menu option to close unrelated projects when you right click a particular project. Have you looked at that?

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