前言
本篇主要是处理@InstallIn和@TestInstallIn、@Module、@EntryPoint和@EarlyEntryPoint和@GeneratedEntryPoint和@ComponentEntryPoint注解。这些注解只能用于修饰类或接口。
校验并且生成PkgPrivateMetadata对象
校验规则
-
@InstallIn和@TestInstallIn:当前节点只允许使用其中的一个注解,只允许使用一次;
-
@EntryPoint、@EarlyEntryPoint、@GeneratedEntryPoint和@ComponentEntryPoint:当前节点只允许使用其中的一个注解,只允许使用一次;
-
(1)@EntryPoint和@GeneratedEntryPoint的区别在于(当然并不是强制的要求),@EntryPoint是用户使用的注解,@GeneratedEntryPoint是通过代码生成的类使用的注解;e.g.例如ViewComponentManager.ViewWithFragmentComponentBuilderEntryPoint和Application_GeneratedInjector可自行去查看;
-
(2)@GeneratedEntryPoint使用了@GeneratesRootInput修饰,会在
dagger.hilt.processor.internal.generatesrootinput.codegen
包下生成dagger_hilt_internal_ComponentEntryPoint
类; -
(3)@EarlyEntryPoint注解修饰的earlyEntryPoint节点生成的类在
dagger.hilt.android.internal.earlyentrypoint.codegen
包下,并且当前节点使用@AggregatedEarlyEntryPoint(earlyEntryPoint = earlyEntryPoint节点名)修饰,@EarlyEntryPoint修饰的节点应用于测试; -
(4)@ComponentEntryPoint修饰的节点会放在生成的类的注解@AggregatedDeps#componentEntryPoints中;
-
@Module:当前节点只允许使用一次Module注解;
-
@InstallIn或@TestInstallIn注解修饰的节点。该节点要么使用@Module修饰,要么使用@EntryPoint或@EarlyEntryPoint或@GeneratedEntryPoint或@ComponentEntryPoint修饰;
-
@Module修饰的节点不允许同时使用@EntryPoint或@EarlyEntryPoint或@GeneratedEntryPoint或@ComponentEntryPoint修饰;
-
@InstallIn或@TestInstallIn注解修饰的节点同时使用@Module修饰,我们称之为module节点:
-
(1)module节点必须是类或接口;
-
(2)module节点是顶级类(再上一级就是包) || module节点使用static修饰 || module节点使用abstract修饰 || module节点的父节点使用@HiltAndroidTest修饰;
-
(3)module节点是ApplicationContextModule类 || module节点不需要实例化(module节点何时需要实例化