I m developing a plugin that takes all enums in workspace that implements certain interface (IDomain) parses the code (Using AST) does some modification over the enum and marks it as processed with an annotation (@IDomainInfo).
For example, it takes someting like this:
public
enum SomeEnum implements IDomain {
// ...
}
And generates something like this:
public @IDomainInfo(domainId = 1)
enum SomeEnum implements IDomain {
// Some changes here...
}
The idea behind of the @IDomainInfo is that annotated enums have not to be processed anymore by the plugin.
Basically what I do to accomplish the task is to make a search with JavaSearch API to find all the enums implementing IDomain (easy task), and as result I get a list of IJavaElements (which are in fact instances of IType). Then I call a method that iterates through the resulting list and creates a new list of all the IType instances that are not annotated with @IDomainInfo and then process the resulting list: For each non annotated IType do some work, annotate the IType with the @IDomainInfo annotation (Using AST) and then save back the results to file (using IFile, so I can see the changes without refresh, and in fact, if I have the enum open in the editor I see it refreshed instantly :-)
All that works fine, but if I open an @IDomainInfo annotated enum (just for testing) then remove the @IDomainInfo, save the file (I m sure) and then call the action that does all the job I ve described before, when I get to the part that filters annotated IType from non annotated ones, code is something like this:
for (IType type : typeList) {
IAnnotation annotation = type.getAnnotation(“IDomainInfo”);
if (!annotation.exists()) {
// The annotation does not exist, so add the type to the
// list of elements to update and go on...
ret.add(type);
continue;
}
// Something else here...
}
Well, it results that for the file I ve just saved the IType detects the annotation I ve just removed as if it s still there. If I close and reopen eclipse all works normally.
Now, I ve just checked and triple checked my code, so I m sure that I m not keeping a stale copy of the old IType unedited still with the annotation version (all my IType come from a fresh java search call every time I run the action).
So the question is, what might I be doing wrong? I mean, I ve just read the JavaCore API many times to check If I might be using it wrong or if I have some conceptual flaw there but really I have no clue, it s like if eclipse would be caching the IType ignoring the changes I ve just made in the editor :-/
If any one have an idea I would appreciate it a lot :-)