如何以编程方式查找Eclipse项目中的错误数量(红色标记)?
最佳答案
有两个主要步骤:
如果您只想检索JDT错误标记,则应编写如下内容:
public static IMarker[] calculateCompilationErrorMarkers(IProject project)
{
ArrayList <IMarker> result = new ArrayList <IMarker>();
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()]);
}