resource tree locked when creating marker during IElementChangedListener#elementChanged() [message #244766] |
Thu, 21 June 2007 09:15  |
Eclipse User |
|
|
|
Originally posted by: schmidts.iese.fraunhofer.de
Hi
I'm trying to listen for changes in Java code by using an
IElementChangedListener. When I process a delta tree, look for certain
conditions in some Javaelements. In some cases I have to create a Marker
(subtype of ProblemMarker) at a file.
I get an Exception telling me, that the resource tree is locked for
modifications when the method
resource.createMarker(markerType);
is called. The Flag of the ElementChangedEvent ist POST_CHANGE and I read in
the archives of several newsgroups, that my access is not allowed in this
case. But there is no other event that I could use. The description of the
resource lock mechanism refers to the IResourceChangeEvent, but I'm not
using these.
How am I supposed to create a Marker upon an element change, when I only get
a POST_CHANGE event???
Tnx in advance,
Seb
|
|
|
|
Re: resource tree locked when creating marker during IElementChangedListener#elementChanged() [message #775395 is a reply to message #244766] |
Thu, 05 January 2012 17:28  |
Eclipse User |
|
|
|
This is an incredibly stale post, but I was trying to do the exact same thing and this came up in the Google search; I'm posting the solution for all future readers.
You cannot modify the markers during Eclipse's build job, but you can schedule them for later modification. I had to refactor my method that called createMarker into an Eclipse job. Set the job's rule to workspace.getRuleFactory().buildRule(), and this will ensure does not run during any other build process.
When you need to schedule the modification, do this:
private class PerformJavaCheck extends Job { ... }
Job checkJob = new PerformJavaCheck(fdModel, myFile, javaFile);
checkJob.setRule(cu.getResource().getWorkspace().getRuleFactory().buildRule());
checkJob.schedule();
|
|
|
Powered by
FUDForum. Page generated in 0.19516 seconds