|[JDT-Core][API] How to get a list of compilation units affected by a change? [message #1745483]
||Tue, 11 October 2016 12:43
| Abel Hegedus
Registered: September 2015
TL;DR: Is it possible to find out which compilation units are built by JDT after a change?|
We have created a prototype for transforming Java source code to UML models incrementally by listening to element change listener notifications on the JavaModel ( https://github.com/viatra/viatra-evm-jdt/wiki/Demo ).
Our approach works on a compilation unit level and relies on JDT to resolve cross references when identifying types of fields and method parameters or return types ( https://github.com/viatra/viatra-evm-jdt/wiki/Cross-reference-updating-between-compilation-units ). Since the element change listener only provides notifications on content changes, we needed an other way to refresh cross references when the referenced type is resolved without any change on the element itself (e.g. a missing type is created).
We found that this information is available in the build state of JDT, however we have not found any public API for accessing this from our code. For our prototype, we solved this by using a CompilationParticipant (
) and reflection to read some internal fields of org.eclipse.jdt.internal.core.builder.State and org.eclipse.jdt.internal.compiler.util.SimpleLookupTable (see JDTBuildState and JDTReferenceStorage ).
JavaModelManager.getJavaModelManager().getLastBuiltState(iproject, new NullProgressMonitor())
The information that we need is the list of compilation units that are affected by the change of a given element.
My questions are the following:
- Is there any API that provides this information without dealing with reflection?
- Does the new index provide any change notifications and if yes, can it be used to identify which types/compilation units were recompiled after a change?
If needed, I can send a message to the jdt-core-dev mailing list if the JDT developers think that is a more appropriate place to discuss this.
Thanks a lot for any input!
Powered by FUDForum
. Page generated in 0.02422 seconds