AssistedInject for Dagger 2 如何工作?

How does AssistedInject for Dagger 2 work?

AssitedInject library from Square is actually an annotation processor that generates Dagger 2 个模块。 Dagger 2 也是一个注解处理器。

据我所知,无法控制

在此 example 中(参见下面的代码片段),您可以看到该模块依赖于 AssistedInject class AssistedInject_MainModule 生成的。因此,如果 Dagger 2 首先将 运行,则构建应该会失败,因为此时 AssistedInject_MainModule 不存在。

但是可以编译。它是如何工作的?

@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.

我没有研究 Dagger 2 或 AssistedInject 是如何工作的,但总的来说注释处理是 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.

文件是在这些轮次中生成的,但验证(和错误)发生在稍后或最后一轮,即每个文件都已生成和处理时。 on the question you linked. Someone also wrote a detailed answer about 在另一个问题上也提到了这一点。