Eclipse plugin 在执行操作之前检查项目错误

Eclipse plugin 在执行操作之前检查项目错误,eclipse-plugin,Eclipse Plugin,我有一个eclipse插件,它提供了一个菜单项,可以选择该菜单项在当前活动文件上运行命令。如果当前活动的文件有任何错误(如Problems视图中所报告的),我希望插件显示一条警告消息,类似于当您尝试运行带有错误的java项目时Eclipse的操作方式。错误通常保存为资源上的iMarker(在您的情况下为IFile),因此,您可以在IFile中查询要查找的标记 在查找之前,您需要知道标记的类型(通过调试并获取所有当前标记,或者通过查看在文件验证过程中贡献它们的代码) 希望对您有所帮助。错误通常保存

我有一个eclipse插件,它提供了一个菜单项,可以选择该菜单项在当前活动文件上运行命令。如果当前活动的文件有任何错误(如Problems视图中所报告的),我希望插件显示一条警告消息,类似于当您尝试运行带有错误的java项目时Eclipse的操作方式。

错误通常保存为资源上的iMarker(在您的情况下为IFile),因此,您可以在IFile中查询要查找的标记

在查找之前,您需要知道标记的类型(通过调试并获取所有当前标记,或者通过查看在文件验证过程中贡献它们的代码)


希望对您有所帮助。

错误通常保存为资源上的iMarker(在您的案例中为IFile),因此您可以在IFile中查询您要查找的标记

在查找之前,您需要知道标记的类型(通过调试并获取所有当前标记,或者通过查看在文件验证过程中贡献它们的代码)


希望这能有所帮助。

我知道这是一个老问题,但我找到了一个类似于建议的解决方案。执行您描述的操作的代码位于
org.eclipse.debug.core.model.LaunchConfigurationDelegate
中。它检查项目是否有错误,并在需要时显示对话框。以下是Eclipse Luna的相关代码:

/**
 * Returns whether the given project contains any problem markers of the
 * specified severity.
 *
 * @param proj the project to search
 * @return whether the given project contains any problems that should
 *  stop it from launching
 * @throws CoreException if an error occurs while searching for
 *  problem markers
 */
protected boolean existsProblems(IProject proj) throws CoreException {
    IMarker[] markers = proj.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    if (markers.length > 0) {
        for (int i = 0; i < markers.length; i++) {
            if (isLaunchProblem(markers[i])) {
                return true;
            }
        }
    }
    return false;
}

/**
 * Returns whether the given problem should potentially abort the launch.
 * By default if the problem has an error severity, the problem is considered
 * a potential launch problem. Subclasses may override to specialize error
 * detection.
 *
 * @param problemMarker candidate problem
 * @return whether the given problem should potentially abort the launch
 * @throws CoreException if any exceptions occur while accessing marker attributes
 */
protected boolean isLaunchProblem(IMarker problemMarker) throws CoreException {
    Integer severity = (Integer)problemMarker.getAttribute(IMarker.SEVERITY);
    if (severity != null) {
        return severity.intValue() >= IMarker.SEVERITY_ERROR;
    }

    return false;
}
/**
*返回给定项目是否包含项目的任何问题标记
*指定的严重性。
*
*@param proj要搜索的项目
*@return给定项目是否包含应
*阻止它发射
*@如果搜索时出错,则会引发CoreException
*问题标记
*/
受保护的布尔存在问题(IProject proj)引发CoreException{
IMarker[]markers=proj.findMarkers(IMarker.PROBLEM,true,IResource.DEPTH\u INFINITE);
如果(markers.length>0){
for(int i=0;i=IMarker.severity\u错误;
}
返回false;
}
相同的代码可以在任何
IResource
上运行,而不是在
IProject
上运行


当显示对话框时,我通过暂停调试器并在相关类上设置断点并从那里追溯,很容易找到它。

我知道这是一个老问题,但我找到了一个类似于建议的解决方案。执行您描述的操作的代码位于
org.eclipse.debug.core.model.LaunchConfigurationDelegate
中。它检查项目是否有错误,并在需要时显示对话框。以下是Eclipse Luna的相关代码:

/**
 * Returns whether the given project contains any problem markers of the
 * specified severity.
 *
 * @param proj the project to search
 * @return whether the given project contains any problems that should
 *  stop it from launching
 * @throws CoreException if an error occurs while searching for
 *  problem markers
 */
protected boolean existsProblems(IProject proj) throws CoreException {
    IMarker[] markers = proj.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    if (markers.length > 0) {
        for (int i = 0; i < markers.length; i++) {
            if (isLaunchProblem(markers[i])) {
                return true;
            }
        }
    }
    return false;
}

/**
 * Returns whether the given problem should potentially abort the launch.
 * By default if the problem has an error severity, the problem is considered
 * a potential launch problem. Subclasses may override to specialize error
 * detection.
 *
 * @param problemMarker candidate problem
 * @return whether the given problem should potentially abort the launch
 * @throws CoreException if any exceptions occur while accessing marker attributes
 */
protected boolean isLaunchProblem(IMarker problemMarker) throws CoreException {
    Integer severity = (Integer)problemMarker.getAttribute(IMarker.SEVERITY);
    if (severity != null) {
        return severity.intValue() >= IMarker.SEVERITY_ERROR;
    }

    return false;
}
/**
*返回给定项目是否包含项目的任何问题标记
*指定的严重性。
*
*@param proj要搜索的项目
*@return给定项目是否包含应
*阻止它发射
*@如果搜索时出错,则会引发CoreException
*问题标记
*/
受保护的布尔存在问题(IProject proj)引发CoreException{
IMarker[]markers=proj.findMarkers(IMarker.PROBLEM,true,IResource.DEPTH\u INFINITE);
如果(markers.length>0){
for(int i=0;i=IMarker.severity\u错误;
}
返回false;
}
相同的代码可以在任何
IResource
上运行,而不是在
IProject
上运行

当对话框显示时,我通过从调试器挂起,在相关类上设置断点并从那里进行跟踪,很容易找到它