Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding number of errors in an eclipse project

Tags:

java

eclipse

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

like image 600
Alok Avatar asked Jun 08 '12 07:06

Alok


People also ask

How do I fix Eclipse errors?

I recommend going to your Problems view, selecting one of the errors, and hitting Ctrl-1 (quick fix). It should offer you the chance to fix all the errors of the selected type, in all files. You can also mouse over the error in the text editor and wait for a popup; it should say "fix 70 other errors of this type".

How do I view logger information in Eclipse?

During development, you can browse and manipulate the platform log file using the Error Log view (Window > Show View > General > Error Log). You can also have the log file mirrored in the Java console by starting Eclipse with the -consoleLog command-line argument.

What does the Problems view show in Eclipse?

The “Problems” view in Eclipse lists errors and warnings in the workspace. In its default settings this view is not entirely helpful, but it is highly customizable. Today I want to show you how you can configure this view to shift the focus to the interesting errors and warnings in your current area of work.


1 Answers

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 <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()]);
}
like image 73
Konstantin V. Salikhov Avatar answered Sep 18 '22 19:09

Konstantin V. Salikhov