Finding number of errors in an eclipse project

后端 未结 1 1747
情歌与酒
情歌与酒 2021-02-05 15:35

How to find the number of errors(marked in red) in an eclipse project programmatically?

1条回答
  •  长情又很酷
    2021-02-05 16:04

    There are two major steps:

    1. You need an access to Eclipse API - write your own plugin for Eclipse or use a scripting plugin like Groovy Monkey

    2. Using Eclipse API get problem markers for resource you intrested in - check this link: How to work with resource markers

    If you want to retrieve only JDT error markers you should write something like this:

    public static IMarker[] calculateCompilationErrorMarkers(IProject project)
    {
        ArrayList  result = new ArrayList ();
        IMarker[] markers = null;
        markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
        for (IMarker marker: markers)
        {
            Integer severityType = (Integer) marker.getAttribute(IMarker.SEVERITY);
            if (severityType.intValue() == IMarker.SEVERITY_ERROR)
                    result.add(marker);
        }
        return result.toArray(new IMarker[result.size()]);
    }
    

    0 讨论(0)
提交回复
热议问题