English 中文(简体)
Weird JavaCore IType cache problem
原标题:

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 :-)

问题回答

When or how is your plugin called ? Did you register a resource listener or is it a project builder or something else ? If it is called by a resource listener, your plugin may be reading the primary copy for your IType, which has not been saved yet. Hence your changes are still in the Working Copy.





相关问题
Two Eclispse projects -> One Eclipse Plug-in

Background I m a developer of the Vrapper project. Vrapper contains of 2 major parts Vim-emulation library (vrapper.core) Eclipse part that makes a good use of it We want vrapper.core to be ...

Error in Preview of Custom Eclipse refactoring

I am implementing an new eclipse refactoring. This will enable developers to Pull-up the preconditions statements from a child method to the parent method. This all works perfectly when I select "...

Eclipse git checkout (aka, revert)

Is it possible to do the equivalent of git checkout from within Eclipse using the EGit plugin? I have a file that s been modified. I want to discards the changes and revert the file back to what s in ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

BlackBerry JDE Eclipse Plugin 1.1 on Windows 7

Has anybody been able to run the new plugin beta v1.1 on Windows 7? When I run the installer, it pops up an error that states "Please select another location to extract the installer to". It ...

How to not write the DocumentRoot to the XML

I m using EMF, and I created my ecore from XSD. I notice that the XML that are being saved by the editor have the element DocumentRoot, which is not part of my original XSD. Can I somehow not ...

How do you fix loading plugins in eclipse 3.5.1 on linux?

I have two linux boxes. Both Fedora 11 x64. On one, I downloaded the eclipse-java-galileo-SR1-linux-gtk-x86_64.tar.gz. I unpacked it to /opt/eclipse-3.5.1/ and used the Install New Software... item ...

热门标签