在执行操作之前检查项目错误
我有一个 Eclipse 插件,它提供了一个菜单项,可以选择该菜单项来对当前活动文件运行命令。我希望插件在当前活动文件有任何错误时显示警告消息(如问题视图中报告的那样),类似于当您尝试运行有错误的 java 项目时 Eclipse 的行为方式。
I have an eclipse plug-in which provides a menu item which can be selected to run a command on the currently active file. I would like the plug-in to display a warning message if the currently active file has any errors on it (as reported in the Problems view), similar to how Eclipse acts when you try to run a java project with errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个老问题,但我找到了与提议的解决方案类似的解决方案。执行您所描述的操作的代码位于 org.eclipse.debug.core.model.LaunchConfigurationDelegate 中。它检查项目是否有错误并在需要时显示对话框。以下是来自 Eclipse Luna 的相关代码:
相同的代码可以在任何
IResource
而不是IProject
上运行。当显示对话框时,我通过从调试器挂起并在相关类上设置断点并从那里追溯来轻松找到它。
I know it's an old question, but I found a solution similar to the one proposed. The code that does what you descrive is in
org.eclipse.debug.core.model.LaunchConfigurationDelegate
. It checks if the project has errors and show the dialog if needed. Here is the relevant code, from Eclipse Luna:The same code can run on any
IResource
instead of anIProject
.I managed to find it easily by suspending from the debugger when the dialog was shown and setting a breakpoint on the relevant class and tracing back from there.
错误通常在资源上保存为 IMarkers(在您的情况下为 IFile),因此您可以在 IFile 中查询您要查找的标记。
您需要在查找之前了解标记的类型(通过调试并获取所有当前标记,或者通过查看在文件验证过程中贡献它们的代码)。
希望有帮助。
Errors are usually saved as IMarkers on a resource (IFile in your case), so you can query the IFile for the markers you are looking for.
You'll need to know the type of the markers before the look-up (either by debugging and get all the current markers, or by looking at the code the contributed them in the validation process of the file).
Hope that helps.