Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Reacting to workspace changes (java & jar files)
Reacting to workspace changes (java & jar files) [message #1715754] Wed, 25 November 2015 16:58
Johannes Dorn is currently offline Johannes DornFriend
Messages: 61
Registered: June 2013
Member
I am working on a plugin that processes every .java and .jar file on the classpath. If possible, a higher abstraction is processed (i.e. when a Java project is added, the entire project is processed rather than all of its fragment roots).

If there is any addition, change, or removal, they have to be processed again.

The tricky part is finding out when elements are added, changed, or removed.

My current approach is a class i call WorkspaceChangeListener.
It implements both IElementChangeListener and IResourceChangeListener. It adds itself as an ElementChangelistener and as a PreProcessingResourceChangedListener with an event mask of POST_CHANGE | PRE_DELETE

Here is how i am processing ElementChangedEvents:
-recursively process all the affected children of the IJavaElementDelta
-if the event adds a package, process all its compilation units
-if the event adds a package fragment root, process the entire package fragment root
-if a package fragment root is removed, process that removal
-if a java project is added/openend, process the entire project

Here is how i am processing ResourceChangeEvents:
-if it is a PRE_DELETE event and the resource is a project, process that project removal
-if the event resource is a java like file, process it, otherwise recursively process all the affected children of the IResourceDelta


There is couple of problems with that approach.
1. it is quite complicated. In particular, it is not clear whether to use the ElementChangedEvents or the ResourceChangeEvents in any given situation.
2. To process a compilation unit, i need to resolve all the bindings in its AST. If the classpath changes, i should reprocess all compilation which are affected by that classpath change. This might yield different results, especially if the classpath change added a missing dependency.
3. When importing multiple Maven projects, the ElementChangedEvent seems to be unreliable in conveying the information that there are new projects.

I hope that you have some idea of how to simplify my WorkspaceChangeListener.

I was hoping to only implement either the IElementChangedListener or the IResourceChangeListener but not both. I can imagine listening to POST_BUILD events as an IResourceChangeListener and process compilation units every time they are build. This should enable me to process them when they are added or changed, or when a classpath change made a rebuild necessary. I would still need to handle deletion separately, but that has been quite simple so far.

Does this seem like a sensible approach? Do you have any ideas?

If possible, i would still want to process higher abstractions than compilation units, as i can process them more efficiently.
Previous Topic:Java Build Path | Add Variable
Next Topic:Eclipse Mars & Neon, windowbuilder freezes in Linux
Goto Forum:
  


Current Time: Thu Sep 19 19:33:29 GMT 2024

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

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

Back to the top