I use last versions of eclipse, java and https://marketplace.eclipse.org/content/m2e-apt to process annotations. I have a processor that processes a single annotation, and looks at the methods within the annotated class and will take all the nonprivate methods and make an interface containing them (which the annotated class will implement). So basically this class implements an interface that will be generated. Let's say we have classes A and B which, annotated, will generate the interfaces IntA and IntB, in the same package as the respective methods. Let's say I have a method in class A that has a return type of IntB.
In my annotation processors I extend the AbstractProcessor, and use things like TypeElement and TypeMirror ( ((ExecutableElement)element).getReturnType() to get the TypeMirror of the ExecutableElement's return value corresponding to a method from the annotated class). Then I use toString() on this TypeMirror to write the return value of the method in the generated interface.
Problem is, if IntA is generated before IntB, this method written in IntA will have the method returning IntB without its qualified name (as the processor doesn't know anything on IntB as it wasn't generated yet), so an error is generated in IntA. If I modify something in class A (then I save, which will cause Eclipse to incrementally generate files, which will only affect the files generated by the annotation on the class A), this error is solved, as IntB is already generated and it can write the fully qualified name as the return value of that method.
I discovered that by writing the fully qualified name for the return value of the method returning IntB in class A, I can avoid this problem. However, I would like if that is the case, to make the processor to process this class at a later time, when IntB is already generated.
How can I delay the process of the annotation on class A?
PS: so far I have made a mechanism where it checks for the return value of every method for the following statement (element.getReturnType().getKind() == TypeKind.ERROR), in which case I throw an exception and add this element in a list which will be processed in another round. It didn't work, as it processed the element a few more times with the same problems. Also I tried to return false to process() method Overridden from AbstractProcessor, and still didn't work.