views:

88

answers:

0

I am using a 3rd party annotation processor for generating meta-data code (.java files) from the annotated classes in my project. I have successfully configured the processor through Eclipse (Properties -> Java Compiler -> Annotation Processing) and the code generation works fine (code is automatically created and generated). Also, Eclipse successfully auto-completes the generated classes and their fields, without any errors. Let's say that I have a class "some.package.Foo" and that the generated meta-data class is "some.package.Foo_". By the help of auto-completion, I can get the following code in the Eclipse editor, without any errors:

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

However, as soon as I actually build the project (or just save the file since Build automatically is enabled), I get the error which tells that "some.package.Foo_" cannot be resolved. It seems like Eclipse is generating and compiling the some.package.Foo_ at the same time, or more likely.

I found two temporary solutions (which are practically hindering the use of the annotation processor in the first place):

  1. Before each build of that generated classes, right click on every generated file go to Properties and uncheck the "Derived" tick. After that, I do the cleanup of the project and the imports are fine - there are no more errors. However, if I do the cleanup one more time, the errors again show up, because the generation of the files causes the "Derived" tick to be checked again (automatically). So this is really annoying and time-consuming.
  2. I also uncheck the "Derived" tick from all those files, and this time I uncheck the "Derived" tick from the source folder and packages which contain those files. Then I disable the annotation processor, and then do the cleanup. There are no more import errors, even if I do another cleanup, but there is no benefit of using the annotation processor, because if I was to change something which would update the model, I need to turn the annotation processor back on, and repeat this tedious procedure to turn it off, after it has generated the new version of those files.

Is this a bug in Eclipse? If yes, is there a better workaround or quick-fix than the two I have stated above? If not, what should I try to solve the problem?

I also tried rearranging the order of the libraries on the build path and it doesn't help.