Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Detecting Changes about Compilation Errors (and related IMarkers)
icon5.gif  Detecting Changes about Compilation Errors (and related IMarkers) [message #781391] Sat, 21 January 2012 05:13 Go to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi all,

Let's say that I have a project with one compilation error. In my plug-in, I retrieve its marker with the following code:
    private static IMarker [] findJavaProblemMarkers(IProject project)
    {
        IMarker [] markers = null;
        markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
        return markers;
    }

again assume that I get an IMarker with id (i.e., IMarker.getID()) 513253. Now, assume that I have added one blank line to my file that had the compilation error. Though, it didn't change the compilation error (it is still the same problem), now I get an IMarker (with the same code) with id: 513280.

That is why I cannot use IMarker.getID() to detect changes on IMarkers (or compilation errors). I wonder if there is another way to do this?

What I need is the following:
- As long as the changes to the document does not affect that compilation error, I want to detect it (somehow, by comparing some internal thing in the IMarker of something else) as the same compilation error.
- If there is a new compilation error added, I would be getting a new IMarker for that, so I can detect it.
- Similarly, if a compilation error is resolved, I would get one less IMarker, so that is also fine.
- However, for example, if that compilation error changes (i.e., I have modified the compilation error, however there is still a compilation error), I want to detect it as a new compilation error.

Is this possible and what can I use internally to detect these changes?

Thank you,

[Updated on: Sat, 21 January 2012 05:19]

Report message to a moderator

Re: Detecting Changes about Compilation Errors (and related IMarkers) [message #781411 is a reply to message #781391] Sat, 21 January 2012 06:32 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
A marker does not 'move', but a new marker is created if the location of
the compilation error changes. (This is easy to verify by looking at the
creation time of markers via Problems view. Select a marker, right click
and select properties)

You may have a chance by detecting that a marker is of type 'Java
Problem' and then compare the Java problem ids (the ones defined in
org.eclipse.jdt.core.compiler.IProblem)

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Re: Detecting Changes about Compilation Errors (and related IMarkers) [message #781415 is a reply to message #781411] Sat, 21 January 2012 06:53 Go to previous messageGo to next message
Kivanc Muslu is currently offline Kivanc MusluFriend
Messages: 153
Registered: November 2010
Senior Member
Hi Deepak,

Thanks for reply. You are right. Actually I have tried using problem ids too. However, what happens if my old compilation error changes but it still has the same problem id?
For example:

private string name; // string is undefined, therefore a compilation error

I made the following change:

private str name; // str is undefined, therefore a compilation error

In this case, I believe (though not sure) that problems ids for these compilation errors will be the same, however I would really want to detect this as a change in compilation error.
Any idea on handling this?

Thanks,
Re: Detecting Changes about Compilation Errors (and related IMarkers) [message #781438 is a reply to message #781415] Sat, 21 January 2012 08:18 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
> Thanks for reply. You are right. Actually I have tried using problem ids
> too. However, what happens if my old compilation error changes but it
> still has the same problem id?
That is why I said 'you may have a chance' :-)

I don't think there is a definite way to check if the 2 compilation
errors are really the same by just looking at the markers.

Is comparing the lines of text containing the errors an option ? You can
use the problem ids as a heuristic to eliminate some of the cases and
only do a text comparison when it is really needed.

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Re: Detecting Changes about Compilation Errors (and related IMarkers) [message #781440 is a reply to message #781415] Sat, 21 January 2012 08:22 Go to previous message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
> private string name; // string is undefined, therefore a compilation error
>
> I made the following change:
>
> private str name; // str is undefined, therefore a compilation error

Also each marker has a length/range. In the above example the 1st marker
is of length 6 and the 2nd marker is of lenght 3. Maybe this serves as
another heuristic?

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Previous Topic:[SOLVED] Quick Fix via Hovering
Next Topic:[glassfish] AppClient deployment
Goto Forum:
  


Current Time: Thu Apr 25 05:16:41 GMT 2024

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

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

Back to the top