Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to get the java markers (IMarker) as Eclipse editor sees them?
icon4.gif  How to get the java markers (IMarker) as Eclipse editor sees them? [message #666965] Mon, 25 April 2011 07:16 Go to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi all,

Currently to get the compilation error markers in a file (or project), I use the following code:

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()]);
    }


The above code works well, however the problem with this code is that it requires all files in the project to be saved and project to be built before requesting the markers.
Q1: Does building the project create the markers?
Q2: Is there any other way to create the markers without saving or building the project (actually Eclipse itself does this since it show me compilation error markers (and quick fixes) even before I save my file)?

What I need is to get the most recent marker information as Eclipse editor (and user) sees it without saving or building the user project. Is this possible? If yes, I would appreciate a starting point or an API very much.

Thanks in advance, best regards,
Re: How to get the java markers (IMarker) as Eclipse editor sees them? [message #667767 is a reply to message #666965] Mon, 02 May 2011 07:09 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 25.04.2011 09:16, Kivanc Muslu wrote:
> Hi all,
>
> Currently to get the compilation error markers in a file (or project),
> I use the following code:
>
>
> public static IMarker [] calculateCompilationErrorMarkers(IProject
> project)
> {
> ArrayList <IMarker> result = new ArrayList <IMarker>();
> IMarker [] markers = null;
> markers =
> project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARK ER, 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()]);
> }
>
>
> The above code works well, however the problem with this code is that
> it requires all files in the project to be saved and project to be
> built before requesting the markers.
> Q1: Does building the project create the markers?
Yes, the builder keeps track of the markers.
> Q2: Is there any other way to create the markers without saving or
> building the project
You can create markers without building a project, e.g. search result
markers but the official way to manage problem markers is via builders.
> (actually Eclipse itself does this since it show me compilation error
> markers (and quick fixes) even before I save my file)?
Those are not markers but lightweight annotations created by the editor
from the result of the Java reconciler.
>
> What I need is to get the most recent marker information as Eclipse
> editor (and user) sees it without saving or building the user project.
> Is this possible? If yes, I would appreciate a starting point or an
> API very much.
If you are only interested in the current state (marker/annotations) in
the editor then you might want to take a look at:
org.eclipse.jface.text.source.IAnnotationModelExtension2.get AnnotationIterator(int,
int, boolean, boolean)

Dani
>
> Thanks in advance, best regards,
Previous Topic:#
Next Topic:programmatically searching file with file name
Goto Forum:
  


Current Time: Tue Mar 19 14:00:19 GMT 2024

Powered by FUDForum. Page generated in 0.02700 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top