7.基于Dagger2.38.1的hilt源码-@DisableInstallInCheck、@EarlyEntryPoint等注解

238 阅读1分钟

源码很短

IncrementalAnnotationProcessor

IncrementalAnnotationProcessor校验使用@DisableInstallInCheck注解的节点必须使用@Module注解。

就这么一句话,完了!!!

EarlyEntryPointProcessor

EarlyEntryPointProcessor类处理使用@EarlyEntryPoint注解的earlyEntryPoint节点生成类;

可以先回顾一下AggregatedDepsProcessor。

生成的类在dagger.hilt.android.internal.earlyentrypoint.codegen包下:

//This class should only be referenced by generated code!
//This class aggregates information across multiple compilations.
@AggregatedEarlyEntryPoint(earlyEntryPoint = earlyEntryPoint节点名)
@Generated("AggregatedEarlyEntryPointGenerator")
public class earlyEntryPoint节点全路径以"_"拼接{
}

OriginatingElementProcessor

该类用于校验@OriginatingElement注解,规则如下:

  1. @OriginatingElement修饰的节点必须是顶级类或接口,顶级-表示再上一级就是包了;

  2. OriginatingElement#topLevelClass中的节点也必须是顶级类或接口。

GeneratesRootInputProcessor

使用@GeneratesRootInput修饰的注解生成@GeneratesRootInputPropagatedData修饰的节点。也是以源码中的代码为例:

在这里插入图片描述

在这里插入图片描述

但是这里的@GeneratesRootInputPropagatedData修饰的节点并没有做进一步处理。反正我从源码中没有找到进一步的处理代码!!!

UninstallModulesProcessor

处理@UninstallModules注解。当前注解用于测试。

校验规则:

  1. @UninstallModules修饰的节点必须是类或接口,还必须同时使用@HiltAndroidTest修饰;

  2. @UninstallModules#value里面的节点必须使用@Module 和 @InstallIn 同时修饰;

  3. @UninstallModules#value中的节点所在顶级节点(当前节点如果在上面是包,那么当前节点就是顶级节点)不允许使用@HiltAndroidTest修饰;

生成的类在dagger.hilt.android.internal.uninstallmodules.codegen包下:

//This class should only be referenced by generated code!This class aggregates information across multiple compilations.
@AggregatedUninstallModules(test = $Class名,uninstallModules = @UninstallModules#value中的节点名称)
@Generated("AggregatedUninstallModulesGenerator")
public class 包"_"拼接$Class{}

总结

到这里为止说的还都是比较零散的东西。都是一次处理、二次处理乃至三次处理。我们继续往下看。