奇怪的JavaCore IType缓存问题 [英] Weird JavaCore IType cache problem

查看:127
本文介绍了奇怪的JavaCore IType缓存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个插件,它将实现某些接口(IDomain)的工作区中的所有枚举解析代码(使用AST)对枚举进行一些修改,并将其标记为使用注释(@IDomainInfo)进行处理。 p>

例如,它需要这样:

  public 
enum SomeEnum实现IDomain {
// ...
}

生成这样的东西:

  public @IDomainInfo(domainId = 1)
枚举SomeEnum实现IDomain {
//这里有一些变化...
}

@IDomainInfo背后的想法是该注释的枚举不再由插件处理。



基本上我完成任务是使用JavaSearch API进行搜索,以查找实现的所有枚举IDomain(简单的任务),结果我得到一个IJavaElements列表(实际上是IType的例子)。然后我调用一个方法来迭代生成的列表,并创建一个新的列表,所有未被@IDomainInfo注释的IType实例,然后处理生成的列表:对于每个未注释的IType做一些工作,用@ IDomainInfo注释(使用AST),然后将结果保存到文件(使用IFile,所以我可以看到更改不刷新,实际上,如果我在编辑器中打开了枚举,我看到它立即刷新: - ) p>

所有这些都可以正常工作,但是如果我打开一个@IDomainInfo注释的枚举(仅用于测试),然后删除@IDomainInfo,保存文件(我确定),然后调用我以前描述的所有工作的动作,当我从非注释过的部分过滤注释的IType时,代码就是这样的:

  for(IType type:typeList){
IAnnotation annotation = type.getAnnotation(IDomainInfo);

if(!annotation.exists()){
//注释不存在,所以将类型添加到
//要更新的元素列表,然后继续...
ret.add(type);
继续;
}
//这里有其他东西...
}

嗯,结果是,我刚刚保存的文件,IType会检测到我刚刚删除的注释,就像它仍然在那里一样。如果我关闭并重新打开eclipse,所有的工作正常。



现在,我刚刚检查和三重检查我的代码,所以我确定我没有保持旧的IType的旧版本仍然使用注释版本(所有我的IType每次运行操作时都来自一个新鲜的java搜索呼叫)。



所以问题是我该怎么做错了?我的意思是说,我刚读过JavaCore API来检查如果我可能使用它错了,或者如果我有一些概念上的缺陷,但是我没有任何线索,就像如果eclipse将缓存IType忽略编辑器中刚刚做出的更改: - /



如果有人有个想法,我会很感激: - )

解决方案

您的插件何时或如何调用?你注册了一个资源侦听器,还是一个项目构建器?如果由资源监听器调用,您的插件可能正在读取您的IType的主要副本,尚未保存。因此,您的更改仍在工作副本中。


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.

这篇关于奇怪的JavaCore IType缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆