4.Dagger2.38.1源码解析-ComponentProcessor注解生成对象

本文详细介绍了Dagger2中ComponentProcessor如何根据不同的注解生成ComponentDescriptor、ComponentAnnotation、ComponentMethodDescriptor等对象,涉及Component、Module、Subcomponent、MultibindingDeclaration等核心概念和它们的属性。通过对源码的解析,阐述了对象之间的关系和作用。
摘要由CSDN通过智能技术生成

简介

使用不同注解的节点生成不同对象,对该对象的核心属性介绍,以及一些核心方法说明。

在学习的过程中最好拿一个笔对存在的问题进行记录,后面可能会找到,而且要学会不断翻阅前面的内容。如果都找不到需要的答案,我相信这个就是自身找到的亮点问题,对自身提升也有很大帮助。

节点生成的对象

ComponentDescriptor

该对象的生成在ComponentProcessingStep中继校验之后调用如下方法完成ComponentDescriptor对象的生成:

生成的是componentDescriptor对象:

 //重头戏,生成ComponentDescriptor对象
    ComponentDescriptor componentDescriptor =
            componentDescriptorFactory.rootComponentDescriptor(component);

生成subcomponentDescriptor对象:

    ComponentDescriptor subcomponentDescriptor =
            componentDescriptorFactory.subcomponentDescriptor(subcomponent);

component节点生成当前对象,属性如下:

  1. ComponentAnnotation annotation:当前component节点使用的注解信息,自行查看ComponentAnnotation对象;

  2. TypeElement typeElement:表示component节点(或module节点);

  3. ImmutableSet dependencies:componentAnnotation#dependencies里面dependency节点生成DEPENDENCY类型的ComponentRequirement对象集合,自行查看《多种类型查询总结》ComponentRequirement对象

  4. ImmutableSet modules:componentAnnotation#modules的module节点,以及该module节点上moduleAnnotation#includes的module节点,自行查看ModuleDescriptor对象

  5. ImmutableMap<ExecutableElement, ComponentRequirement> dependenciesByDependencyMethod:收集componentAnnotation#dependencies中dependency节点 ①无参②返回类型不是void 方法。K:dependency无参返回类型不是void方法,V:当前方法所在dependency节点生成的ComponentRequirement对象;

  6. ImmutableSet scopes:

  • (1)component节点使用Scope注解修饰的注解集合;

  • (2)如果componentAnnotation是production类型(@ProductionComponent,@ProductionSubcomponent或@ProducerModule),还会添加@ProductionScope注解;

  1. ImmutableSet childComponentsDeclaredByModules:(当前component节点上componentAnnotation#modules以及moduleAnnotation#includes里面的所有module节点,如果是module节点直接使用当前module节点的)moduleAnnotation#subcomponents里面的subcomponent节点集合生成ComponentDescriptor对象;

  2. ImmutableBiMap<ComponentDescriptor.ComponentMethodDescriptor, ComponentDescriptor> childComponentsDeclaredByFactoryMethods:当前component节点上返回类型是subcomponent节点的方法。K:返回类型是subcomponent节点的componentMethod方法生成的ComponentMethodDescriptor对象,V:当前方法返回类型subcomponent节点生成的ComponentDescriptor对象;

  3. ImmutableBiMap<ComponentDescriptor.ComponentMethodDescriptor, ComponentDescriptor> childComponentsDeclaredByBuilderEntryPoints:返回类型是subcomponent.creator节点(Builder)的componentMethod方法。K:返回类型是subcomponent.creator节点的componentMethod方法生成该方法生成的ComponentMethodDescriptor对象,V:componentMethod方法的返回类型subcomponent节点生成的ComponentDescriptor对象;

  4. ImmutableSet<ComponentDescriptor.ComponentMethodDescriptor> componentMethods:表示componentMethod的方法生成的ComponentMethodDescriptor集合,ComponentMethodDescriptor自行查看

  5. Optional creatorDescriptor:component.creator节点如果存在,那么生成一个ComponentCreatorDescriptor,自行查看《多种类型查询总结》ComponentCreatorDescriptor对象

ComponentAnnotation对象

表示component节点使用的componentAnnotation注解生成的对象(当然了,也可能当前component节点其实是一个module节点,这部分逻辑也是一个瑕疵,为啥module节点可以作为一个伪component节点!!!)

ComponentAnnotation有两个子类:一个是RealComponentAnnotation表示这是真的componentAnnotationAll;一个是FictionalComponentAnnotation表示moduleAnnotation,属性如下

  1. AnnotationMirror annotation:表示使

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值