Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Saving java file fires two IResourceChangeEvent
Saving java file fires two IResourceChangeEvent [message #1694776] Thu, 07 May 2015 19:17 Go to next message
Simon Laffoy is currently offline Simon LaffoyFriend
Messages: 19
Registered: January 2015
Junior Member
HI,

Everytime a .java file is saved in the workspace I want to do some processing of the changes in it. To do this I have a WorkspaceChangeListener which receives IResourceChangeEvents. This all works fine, except that the processing is performed twice for every saved .java file.

Two ResourceChangeEvents are received. The first is just for the saved .java file and is as I would expect. The delta tree would look like

/JavaProject/src/pkg/MyClass.java

The second ResourceChangeEvent concerns the corresponding newly compiled and built .class file. (I have Automatic Build turned on. if I turn this off the second ResourceChangeEvent is merely delayed, not eliminated). The delta for this second event has two branches below the project level. The tree would look like:

ResourceDelta(/JavaProject/src/pkg/MyClass.java
.............................................../bin/pkg/MyClass.class

I would also like to know if there are any situations in which the code changes to the .java file (the first event) and the .class file compilation (the second event) are handled by a single event? Is this possible?

If the answer is to this question is 'no', then I can just ignore any events with a delta including a .class file.

Thanks in advance.
Re: Saving java file fires two IResourceChangeEvent [message #1694819 is a reply to message #1694776] Fri, 08 May 2015 08:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33108
Registered: July 2009
Senior Member
Simon,

Comments below.

On 07/05/2015 9:17 PM, Simon Laffoy wrote:
> HI,
>
> Everytime a .java file is saved in the workspace I want to do some
> processing of the changes in it. To do this I have a
> WorkspaceChangeListener which receives IResourceChangeEvents. This all
> works fine, except that the processing is performed twice for every
> saved .java file.
Probably it would be better to use a Save Participant.
>
> Two ResourceChangeEvents are received. The first is just for the saved
> .java file and is as I would expect. The delta tree would look like
>
> /JavaProject/src/pkg/MyClass.java
Such a save will kick off a build, and that of course produces many
additional files.
>
> The second ResourceChangeEvent concerns the corresponding newly
> compiled and built .class file.
Yes, as expected.
> (I have Automatic Build turned on. if I turn this off the second
> ResourceChangeEvent is merely delayed, not eliminated).
Eventually you'll want to build it and get those deltas.
> The delta for this second event has two branches below the project
> level. The tree would look like:
>
> ResourceDelta(/JavaProject/src/pkg/MyClass.java
> ............................................../bin/pkg/MyClass.class
>
> I would also like to know if there are any situations in which the
> code changes to the .java file (the first event) and the .class file
> compilation (the second event) are handled by a single event? Is this
> possible?
Deltas are often groups when the things making the changes using a
workspace modify operation...
>
> If the answer is to this question is 'no', then I can just ignore any
> events with a delta including a .class file.
A save participant would be a better approach, especially if you intend
to further modify the workspace and cause more deltas...
>
> Thanks in advance.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Saving java file fires two IResourceChangeEvent [message #1694826 is a reply to message #1694819] Fri, 08 May 2015 09:09 Go to previous message
Simon Laffoy is currently offline Simon LaffoyFriend
Messages: 19
Registered: January 2015
Junior Member
Thanks for the response Ed,

I just came up with my own solution. The flags of the IResourceDelta class tell me if the change involves the content of the file or not.

As we don't intend to trigger further workspace changes after having received the change events, I feel it would not be necessary to use the save participants, but I appreciate that you drew my attention to them (I hadn't heard of them before).

Thanks again
Simon

[Updated on: Fri, 08 May 2015 09:10]

Report message to a moderator

Previous Topic:Possible Memory Leak in WorkbenchStatusDialogManagerImpl
Next Topic:Renaming resource file
Goto Forum:
  


Current Time: Tue Mar 19 11:37:01 GMT 2024

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

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

Back to the top