The AssitedInject library from Square is actually an annotation processor that generates Dagger 2 modules. Dagger 2 is also an annotation processor.
And as I know there is no way to control the order of processors execution.
In this example (see snippet below) you can see that the module has dependency on generated by AssistedInject class AssistedInject_MainModule
. So in case if Dagger 2 will run first the build should fail because of at this moment AssistedInject_MainModule
does not exist.
But it can be compiled. How does it work?
@AssistedModule
@Module(includes = AssistedInject_MainModule.class)
public abstract class MainModule {
@Provides static @Exclamation String provideExclamation() {
return "!";
}
}
And as I know there is no way to control the order of processors execution.
I did not look into how either Dagger 2 or AssistedInject work under the hood, but in general Annotation Processing is done in multiple rounds.
Annotation processing happens in a sequence of rounds. On each round, a processor may be asked to process a subset of the annotations found on the source and class files produced by a prior round.
Files get generated during those rounds, but validation (and errors) happens on a later or last round, when every file was generated and processed. This is also mentioned on a second answer on the question you linked. Someone also wrote a detailed answer about how rounds work on a different question.