Description
If an annotation processor queries the Element.getEnclosedElements()
and generates results that implicitly depends on the order of the elements, then the processor will not be reinvoked when the enclosed element order is changed. As an example:
public class Subject {
public int a;
public int b;
}
The processor may generate a resource with the following contents
a[...]
b[...]
If the developer decides to only change up the order of the elements as:
public class Subject {
public int b;
public int a;
}
Then the processor would generate:
b[...]
a[...]
However, the processor is not reinvoked by the incremental compiler task.
This is a bug.
Workaround
Perform a clean build or the processor shouldn't depend on the element order. Alphabetic sorting may be a good solution.
Solution
Track the behaviour of the processors and the expected indexes for the associated elements. If the indexes change, reinvoke the processors.
We might consider adding a flag to the processor configuration to signal that a given processor actually depends on the element order. As most processors probably don't, tracking them could introduce some overhead.
Another note that is that we might get away by only tracking the relative order between elements that were reported as input dependencies to a given resource generation. This should be much easier to implement and more straight forward from a Processor
perspective.