Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Not getting proper notifications upon JavaModel changes(Problem with getting notifications on ALL JavaModel changes when model is updated within a very short period of time)
Not getting proper notifications upon JavaModel changes [message #753414] Thu, 27 October 2011 07:05 Go to next message
Stas  is currently offline Stas Friend
Messages: 2
Registered: October 2011
Junior Member
Hi,

In my setup the Java text editor is being updated both by a user input
(keyboard), and a plugin I'm developing. The plugin uses the standard
Display.getDefault().syncExec method to execute its changes to the Java Model
(e.g. createMethod, createField, etc.).

The problem:
------------
Seems that under certain timing conditions, if the user and the plugin almost
simultaneously add a new method to the Java Model, only one of new methods is
reported to the IElementChangedListener (and is usually the one introduced by
the plugin).
This notification runs in the main thread and looks like :

[Working copy] Temp.java[*]: {CHILDREN | FINE GRAINED}
Temp[*]: {CHILDREN | FINE GRAINED}
foo()[+]: {}

Where foo is the method that the plugin introduced. I'd expect the second
method to be reported much the same way.
Sometimes it does, but under certain timing conditions, it does not, and the
second method goes off the radar. The notification I get about it looks like so
and does not provide the details I expect to be getting:
[Working copy] Temp.java[*]: {AST AFFECTED}
(This notification runs in the org.eclipse.jdt.internal.ui.text.JavaReconciler
thread).

To sum things up, two methods are added to the JavaModel, one by a plugin and
one using keyboard input. Only one method, that of the plugin's, is reported in
a detailed manner via a IJavaElementDelta to my IElementChangedListener, the
other one does not trigger an elementChanged invocation with such delta.

It does not always happen and in fact requires some playing around to
reproduce. However, I have managed to reproduce it multiple times and I'm quite
positive of the findings. Basically seems that this happens when I time the
plugin's and the user's updates to be as "simultaneous" as I can.

Attached please find 2 files, one's presenting the described behavior, while the other isn't. In these files you can see the textual changes made to the editor (printed from the documentAboutToBeChanged method) and the JavaModel changes (printed from the
elementChanged method).

Any ideas as to what's going on here?

Thanks in advance.
Re: Not getting proper notifications upon JavaModel changes [message #753546 is a reply to message #753414] Thu, 27 October 2011 15:55 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 27.10.2011 09:05, Stas wrote:
> Hi,
>
> In my setup the Java text editor is being updated both by a user input
> (keyboard), and a plugin I'm developing. The plugin uses the standard
> Display.getDefault().syncExec method to execute its changes to the Java Model
> (e.g. createMethod, createField, etc.).
>
> The problem:
> ------------
> Seems that under certain timing conditions, if the user and the plugin almost
> simultaneously add a new method to the Java Model, only one of new methods is
> reported to the IElementChangedListener (and is usually the one introduced by
> the plugin).
Make sure that your code call reconcile(...) on the compilation unit.

Dani

> This notification runs in the main thread and looks like :
>
> [Working copy] Temp.java[*]: {CHILDREN | FINE GRAINED}
> Temp[*]: {CHILDREN | FINE GRAINED}
> foo()[+]: {}
>
> Where foo is the method that the plugin introduced. I'd expect the second
> method to be reported much the same way.
> Sometimes it does, but under certain timing conditions, it does not, and the
> second method goes off the radar. The notification I get about it looks like so
> and does not provide the details I expect to be getting:
> [Working copy] Temp.java[*]: {AST AFFECTED}
> (This notification runs in the org.eclipse.jdt.internal.ui.text.JavaReconciler
> thread).
>
> To sum things up, two methods are added to the JavaModel, one by a plugin and
> one using keyboard input. Only one method, that of the plugin's, is reported in
> a detailed manner via a IJavaElementDelta to my IElementChangedListener, the
> other one does not trigger an elementChanged invocation with such delta.
>
> It does not always happen and in fact requires some playing around to
> reproduce. However, I have managed to reproduce it multiple times and I'm quite
> positive of the findings. Basically seems that this happens when I time the
> plugin's and the user's updates to be as "simultaneous" as I can.
>
> Attached please find 2 files, one's presenting the described behavior, while the other isn't. In these files you can see the textual changes made to the editor (printed from the documentAboutToBeChanged method) and the JavaModel changes (printed from the
> elementChanged method).
>
> Any ideas as to what's going on here?
>
> Thanks in advance.
>
Re: Not getting proper notifications upon JavaModel changes [message #753619 is a reply to message #753546] Fri, 28 October 2011 05:49 Go to previous message
Stas  is currently offline Stas Friend
Messages: 2
Registered: October 2011
Junior Member
Dani Megert wrote on Thu, 27 October 2011 11:55
Make sure that your code call reconcile(...) on the compilation unit.

Dani


Hi Dani,

Thanks for taking the time to look at it, I'll give it a try.

I was under the impression I had to call reconcile only if I directly access a working copy buffer, say by applying some textual changes using buffer.append or workingCopy.applyTextEdit.
In my case, I'm making changes to the JavaModel itself, by calling the Java element API (e.g., createMethod, createField, etc.).
Also, unless I time it very carefully, the strange behavior I've mentioned does not present itself and the JavaModel notifications are properly sent.

It reeks of multithreading issues, though I'm not sure how. All of my changes are performed from the GUI main thread since I'm calling Display.getDefault().syncExec.

Anything comes to mind?

Edit: In fact, perhaps the bigger question is whether there's some kind of a synchronization mechanism between threads that access the JavaModel directly and between the thread that runs the reconcile operation in the Java text editor.

[Updated on: Fri, 28 October 2011 09:25]

Report message to a moderator

Previous Topic:junitsrc.zip file not found in eclipse indigo
Next Topic:Webservices Help
Goto Forum:
  


Current Time: Fri Apr 19 15:17:00 GMT 2024

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

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

Back to the top