5.基于Dagger2.38.1的hilt源码-AggregatedDepsProcessor

前言

本篇主要是处理@InstallIn和@TestInstallIn、@Module、@EntryPoint和@EarlyEntryPoint和@GeneratedEntryPoint和@ComponentEntryPoint注解。这些注解只能用于修饰类或接口。

校验并且生成PkgPrivateMetadata对象

校验规则

  1. @InstallIn和@TestInstallIn:当前节点只允许使用其中的一个注解,只允许使用一次;

  2. @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中;

  1. @Module:当前节点只允许使用一次Module注解;

  2. @InstallIn或@TestInstallIn注解修饰的节点。该节点要么使用@Module修饰,要么使用@EntryPoint或@EarlyEntryPoint或@GeneratedEntryPoint或@ComponentEntryPoint修饰;

  3. @Module修饰的节点不允许同时使用@EntryPoint或@EarlyEntryPoint或@GeneratedEntryPoint或@ComponentEntryPoint修饰;

  4. @InstallIn或@TestInstallIn注解修饰的节点同时使用@Module修饰,我们称之为module节点:

  • (1)module节点必须是类或接口;

  • (2)module节点是顶级类(再上一级就是包) || module节点使用static修饰 || module节点使用abstract修饰 || module节点的父节点使用@HiltAndroidTest修饰;

  • (3)module节点是ApplicationContextModule类 || module节点不需要实例化(module节点何时需要实例化࿱

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值