Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » resource tree locked when creating marker during IElementChangedListener#elementChanged()
resource tree locked when creating marker during IElementChangedListener#elementChanged() [message #244766] Thu, 21 June 2007 09:15 Go to next message
Eclipse UserFriend
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 #244776 is a reply to message #244766] Thu, 21 June 2007 10:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: francois.malouin.polymtl.ca

I'm not sure about if this could help you...

But the way Eclipse handles the events and actually creates the markers is
with the concept of builders
(org.eclipse.core.resources.IncrementalProjectBuilder). Multiple builders
can be associated with a project, so you could add yours and get notified
when resources are added/deleted/modifed within that project.

And for a reason I don't really understand, you can add markers while in the
builder, so you could do what you want to do.

Open a .project and you'll see what I am talking about...
buildCommand = registered builders
natures = something you might wanna look into too...they are often used with
builders.

I hope this helps, I too had problems with adding markers :)

Fran
Re: resource tree locked when creating marker during IElementChangedListener#elementChanged() [message #775395 is a reply to message #244766] Thu, 05 January 2012 17:28 Go to previous message
Eclipse UserFriend
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();
Previous Topic:Huh? "A class file was not written. The project may be inconsistent, if so try refreshing this
Next Topic:Runnable Jar export fails with class-path problems
Goto Forum:
  


Current Time: Sat May 24 09:03:12 EDT 2025

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

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

Back to the top