且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eclipse 3.5+ - 注释处理器:无法导入生成的类

更新时间:2023-01-13 13:28:16

我有一个类似的问题,我唯一发现的是,这是导入不工作,但是类中的引用也可以工作。我使用的解决方法是在需要生成的类的所有情况下使用FQCN(除了生成的类在同一个包中,因为显然不需要导入)。

I have a similar problem, and the only thing I've found is that it's the imports specifically that don't work, but the references in the class itself do work. The workaround I've used is to use the FQCN in all cases where the generated class is needed (except when the generated class is in the same package, since then the import is obviously not needed).

所以要使用你的例子,我会做:

So to use your example, I'd do:

public class Test {
  void test() {
    some.package.Foo_.someField = null; // try to access a field from the generated class Foo_
  }
}

我唯一的猜测是,eclipse编译器在进行注解处理之前正在处理导入,这在eclipse中必须是一个错误。

My only guess then is that the eclipse compiler is processing the imports before doing the annotation processing, which imho must be a bug in eclipse.

我知道这个问题已经结束了一年以前,所以我有兴趣知道你是否找到其他方法来解决它。

I know this question is over a year old, so I'd be interested to know if you've found any other way to fix it.