前言
RootProcessor处理@HiltAndroidApp、@HiltAndroidTest和@InternalTestRoot三种注解,以及该注解关联的注解。生成一个@ComponentTreeDeps修饰的节点,该节点再由ComponentTreeDepsProcessor类处理。
同样的,以下源码的学习对照该demo去理解事半功倍,否则感觉说的非常无厘头。
RootProcessor
RootType
当前枚举有两种:
-
ROOT: 表示节点使用@HiltAndroidApp修饰;
-
TEST_ROOT:表示节点使用@HiltAndroidTest或@InternalTestRoot修饰;
TestInjectorGenerator
如果RootType是TEST_ROOT类型,那么使用当前类用于生成一个新类。
@HiltAndroidTest或@InternalTestRoot修饰的节点规则:
-
@HiltAndroidTest或@InternalTestRoot修饰的节点不允许使用@AndroidEntryPoint修饰;
-
test测试节点一定使用了@HiltAndroidTest注解,是否使用@InternalTestRoot随意。
demo:
@HiltAndroidTest
public class TestApplication extends Application{...}
生成的类如下:
@OriginatingElement(topLevelClass = TestApplication.class)
@GeneratedEntryPoint
@InstallIn(SingletonComponent.class)
@Generated("TestInjectorGenerator")
public interface TestApplication_GeneratedInjector {
public void injectTest(TestApplication testApplication);
}
AggregatedRootGenerator
@HiltAndroidApp或@HiltAndroidTest修饰的节点生成@AggregatedRoot修饰的类。
com.aregyan.github包下的demo:
@HiltAndroidApp
class Application : Application() {...}
生成类在dagger.hilt.internal.aggregatedroot.codegen包下:
/**
* This class should only be referenced by generated code! This class aggregates information across multiple compilations.
*/
@AggregatedRoot(
root = "com.aregyan.github.Application",
originatingRoot = "com.aregyan.github.Application",
rootAnnotation = HiltAndroidApp.class
)
public class _com_aregyan_github_Application {
}
ProcessedRootSentinelMetadata
dagger.hilt.internal.processedrootsentinel.codegen包下使用@ProcessedRootSentinel注解修饰的节点生成的对象。
@AggregatedRoot修饰的节点会再次在dagger.hilt.internal.processedrootsentinel.codegen包生成一个@ProcessedRootSentinel修饰的类。
属性如下:
-
aggregatingElement:@ProcessedRootSentinel注解修饰的节点;
-
rootElements:当前@ProcessedRootSentinel#roots中的值表示的类或接口;
将ProcessedRootSentinelMetadata对象转换成ProcessedRootSentinelIr,属性:
-
fqName:@ProcessedRootSentinel注解修饰的节点;
-
roots:当前@ProcessedRootSentinel#roots中的值表示的类或接口;
AggregatedRootMetadata
dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点生成的对象,属性如下:
-
TypeElement aggregatingElement:dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点;
-
TypeElement rootElement:@AggregatedRoot#root中的节点,
-
TypeElement originatingRootElement:@AggregatedRoot#originatingRoot中的节点,
-
TypeElement rootAnnotation:@AggregatedRoot#rootAnnotation中的节点,
-
boolean allowsSharingComponent:true。
当前AggregatedRootMetadata对象转换成AggregatedRootIr对象,属性如下:
-
val fqName: dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点;
-
val root: @AggregatedRoot#root中的节点;
-
val originatingRoot: @AggregatedRoot#originatingRoot中的节点;
-
val rootAnnotation: @AggregatedRoot#rootAnnotation中的节点;
-
val allowsSharingComponent: Boolean = true。
AggregatedRootIrValidator
校验:
-
@HiltAndroidApp在一个项目中只允许出现一次;
-
同一个项目中不允许同时出现@HiltAndroidTest或@InternalTestRoot 和 @HiltAndroidApp;
- 可以理解为@HiltAndroidApp应用于项目,@HiltAndroidTest或@InternalTestRoot应用于测试环境;
-
如果@AggregatedRoot#rootAnnotation中的注解是@HiltAndroidTest或@InternalTestRoot && @AggregatedRoot#root包含在@ProcessedRootSentinel#roots中(已经被处理过了) ,那么不允许再次处理该注解;;
-
@AggregatedRoot#rootAnnotation中的注解如果是@HiltAndroidApp && @HiltAndroidApp包含在@ProcessedRootSentinel#roots中(已经被处理过了),那么不允许再次在当前项目中处理 @HiltAndroidApp注解;
可自行查看代码,这里的逻辑非常的绕口,必须理解的是**@ProcessedRootSentinel#roots收集的是@AggregatedRoot#rootAnnotation中处理过的注解**。
DefineComponentClassesMetadata
dagger.hilt.processor.internal.definecomponent.codegen包下使用@DefineComponentClasses注解修饰的节点生成DefineComponentClassesMetadata对象。
该包下的@DefineComponentClasses注解修饰的节点是通过@DefineComponent修饰的节点生成得来的,一般使用hilt提供的@DefineComponent修饰的节点,前面已有介绍,自行去查看。
属性如下:
-
TypeElement aggregatingElement:@DefineComponentClasses注解修饰的节点;
-
TypeElement element:@DefineComponentClasses#component或@DefineComponentClasses#builder里面的节点;
- @DefineComponentClasses#component或@DefineComponentClasses#builder有且仅有一个有效;
- boolean isComponent: 是否是@DefineComponentClasses#component。
DefineComponentClassesMetadata对象转换成DefineComponentClassesIr对象,属性如下:
-
val fqName: @DefineComponentClasses注解修饰的节点;
-
val component: @DefineComponentClasses#component或@DefineComponentClasses#builder里面的节点;
AliasOfPropagatedDataMetadata
dagger.hilt.processor.internal.aliasof.codegen包下使用@AliasOfPropagatedData修饰的节点生成的对象,属性如下:
-
TypeElement aggregatingElement:@AliasOfPropagatedData修饰的节点;
-
TypeElement defineComponentScopeElement:@AliasOfPropagatedData#defineComponentScope中的节点;
-
TypeElement aliasElement:@AliasOfPropagatedData#alias中的节点;
AliasOfPropagatedDataMetadata对象转换成AliasOfPropagatedDataIr对象,属性如下:
-
val fqName: @AliasOfPropagatedData修饰的节点
-
val defineComponentScope: @AliasOfPropagatedData#defineComponentScope中的节点;
-
val alias: @AliasOfPropagatedData#alias中的节点;
AggregatedDepsMetadata
hilt_aggregated_deps包下使用@AggregatedDeps修饰的节点生成的AggregatedDepsMetadata对象,属性如下:
-
TypeElement aggregatingElement:@AggregatedDeps修饰的节点;
-
Optional testElement:@AggregatedDeps#test中的节点;
-
ImmutableSet componentElements:@AggregatedDeps#components中的节点;
-
AggregatedDepsMetadata.DependencyType dependencyType:
-
(1)如果@AggregatedDeps#modules存在,使用DependencyType.MODULE;
-
(2)如果@AggregatedDeps#entryPoints存在,使用DependencyType.ENTRY_POINT;
-
(3)如果@AggregatedDeps#componentEntryPoints存在,使用DependencyType.COMPONENT_ENTRY_POINT;
-
(4)@AggregatedDeps#modules、@AggregatedDeps#entryPoints、@AggregatedDeps#componentEntryPoints三者有且仅有一个存在;
-
TypeElement dependency:@AggregatedDeps#modules或@AggregatedDeps#entryPoints或@AggregatedDeps#componentEntryPoints中的节点;
-
ImmutableSet replacedDependencies:@AggregatedDeps#replaces中的节点。
AggregatedDepsMetadata转换成AggregatedDepsIr对象,属性如下:
-
val fqName: @AggregatedDeps修饰的节点;
-
val components: @AggregatedDeps#components中的节点;
-
val test: @AggregatedDeps#test中的节点;
-
val replaces: @AggregatedDeps#replaces中的节点;
-
val module: @AggregatedDeps#modules中的节点;
-
val entryPoint: @AggregatedDeps#entryPoints中的节点;
-
val componentEntryPoint: @AggregatedDeps#componentEntryPoints中的节点;
AggregatedUninstallModulesMetadata
dagger.hilt.android.internal.uninstallmodules.codegen包下使用@AggregatedUninstallModules修饰的节点生成AggregatedUninstallModulesMetadata对象,属性如下:
-
TypeElement aggregatingElement:@AggregatedUninstallModules修饰的节点;
-
TypeElement testElement:@AggregatedUninstallModules#test中的节点;
-
ImmutableList uninstallModuleElements:@AggregatedUninstallModules#uninstallModules中的节点。
AggregatedUninstallModulesMetadata对象转换成AggregatedUninstallModulesIr对象,属性如下:
-
val fqName: @AggregatedUninstallModules修饰的节点;
-
val test:@AggregatedUninstallModules#test中的节点;
-
val uninstallModules:@AggregatedUninstallModules#uninstallModules中的节点。
AggregatedEarlyEntryPointMetadata
dagger.hilt.android.internal.earlyentrypoint.codegen包下使用@AggregatedEarlyEntryPoint修饰的节点生成AggregatedEarlyEntryPointMetadata对象,属性如下:
-
TypeElement aggregatingElement:@AggregatedEarlyEntryPoint修饰的节点;
-
TypeElement earlyEntryPoint:@AggregatedEarlyEntryPoint#earlyEntryPoint中的节点。
AggregatedEarlyEntryPointMetadata转换成AggregatedEarlyEntryPointIr对象,属性如下:
-
val fqName: @AggregatedEarlyEntryPoint修饰的节点;
-
val earlyEntryPoint: @AggregatedEarlyEntryPoint#earlyEntryPoint中的节点。
ComponentTreeDepsIr
将之前的所有节点汇集。
@HiltAndroidApp修饰自定义Application生成的对象属性如下:
- val name: @AggregatedRoot#root中的元素拼接"_ComponentTreeDeps",e.g.:
_com_aregyan_github_Application_ComponentTreeDeps;
- dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点有且仅有一个;
-
val rootDeps: dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点;
-
val defineComponentDeps: @DefineComponentClasses注解修饰的节点;
-
val aliasOfDeps: @AliasOfPropagatedData修饰的节点;
-
val aggregatedDeps: @AggregatedDeps(筛选出@AggregatedDeps#replaces为空)修饰的节点;
-
val uninstallModulesDeps: 空;
-
val earlyEntryPointDeps: 空。
@HiltAndroidTest修饰自定义Application生成的对象属性如下:
-
val name: 生成的类名;
-
val rootDeps: dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点;也可能是Default类;
-
val defineComponentDeps: @DefineComponentClasses注解修饰的节点;
-
val aliasOfDeps: @AliasOfPropagatedData修饰的节点;
-
val aggregatedDeps: @AggregatedDeps(筛选出@AggregatedDeps#replaces为空)修饰的节点;
-
val uninstallModulesDeps: AggregatedUninstallModulesMetadata对象中的节点;
-
val earlyEntryPointDeps: 空或者AggregatedEarlyEntryPointIr对象中的节点。
由此可知@EarlyEntryPoint修饰的节点应用于测试。
ComponentTreeDepsIr对象转换成ComponentTreeDepsMetadata对象,属性如下:
@HiltAndroidApp修饰自定义Application生成的对象为例。
-
ClassName name: @AggregatedRoot#root中的元素拼接"_ComponentTreeDeps",e.g.:
_com_aregyan_github_Application_ComponentTreeDeps; -
ImmutableSet aggregatedRootDeps:dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点;
-
ImmutableSet defineComponentDeps:dagger.hilt.processor.internal.definecomponent.codegen包下@DefineComponentClasses注解修饰的节点;
-
ImmutableSet aliasOfDeps: dagger.hilt.processor.internal.aliasof.codegen包下使用@AliasOfPropagatedData修饰的节点;
-
ImmutableSet aggregatedDeps:@AggregatedDeps(筛选出@AggregatedDeps#replaces为空)修饰的节点;
-
ImmutableSet aggregatedUninstallModulesDeps:空;
-
ImmutableSet aggregatedEarlyEntryPointDeps:空。
ComponentTreeDepsGenerator
demo:
@AggregatedRoot(
root = "com.aregyan.github.Application",
originatingRoot = "com.aregyan.github.Application",
rootAnnotation = HiltAndroidApp.class
)
public class _com_aregyan_github_Application {
}
生成的代码如下:
//com.aregyan.github包下
@ComponentTreeDeps(
rootDeps = [_com_aregyan_github_Application.class] ,
defineComponentDeps = [
_dagger_hilt_components_SingletonComponent.class,
_dagger_hilt_android_components_FragmentComponent.class,
_dagger_hilt_android_components_ActivityComponent.class,
_dagger_hilt_android_components_ActivityRetainedComponent.class,
_dagger_hilt_android_components_ServiceComponent.class,
_dagger_hilt_android_components_ViewComponent.class,
_dagger_hilt_android_components_ViewModelComponent.class,
_dagger_hilt_android_components_ViewWithFragmentComponent.class,
_dagger_hilt_android_internal_builders_ActivityComponentBuilder.class,
_dagger_hilt_android_internal_builders_ActivityRetainedComponentBuilder.class,
_dagger_hilt_android_internal_builders_FragmentComponentBuilder.class,
_dagger_hilt_android_internal_builders_ServiceComponentBuilder.class,
_dagger_hilt_android_internal_builders_ViewComponentBuilder.class,
_dagger_hilt_android_internal_builders_ViewModelComponentBuilder.class,
_dagger_hilt_android_internal_builders_ViewWithFragmentComponentBuilder.class
],
aggregatedDeps = [
_com_aregyan_github_Application_GeneratedInjector.class,
_com_aregyan_github_di_DatabaseModule.class,
_com_aregyan_github_di_NetworkModule.class,
_com_aregyan_github_MainActivity_GeneratedInjector.class,
_com_aregyan_github_views_userDetails_UserDetailsFragment_GeneratedInjector.class,
_com_aregyan_github_views_userDetails_UserDetailsViewModel_HiltModules_BindsModule.class,
_com_aregyan_github_views_userDetails_UserDetailsViewModel_HiltModules_KeyModule.class,
_com_aregyan_github_views_userList_UserListFragment_GeneratedInjector.class,
_com_aregyan_github_views_userList_UserListViewModel_HiltModules_BindsModule.class,
_com_aregyan_github_views_userList_UserListViewModel_HiltModules_KeyModule.class,
_dagger_hilt_android_internal_lifecycle_DefaultViewModelFactories_ActivityEntryPoint.class,
_dagger_hilt_android_internal_lifecycle_DefaultViewModelFactories_FragmentEntryPoint.class,
_dagger_hilt_android_internal_lifecycle_HiltWrapper_DefaultViewModelFactories_ActivityModule.class,
_dagger_hilt_android_internal_lifecycle_HiltViewModelFactory_ViewModelFactoriesEntryPoint.class,
_dagger_hilt_android_internal_lifecycle_HiltWrapper_HiltViewModelFactory_ViewModelModule.class,
_dagger_hilt_android_internal_lifecycle_HiltWrapper_HiltViewModelFactory_ActivityCreatorEntryPoint.class,
_dagger_hilt_android_internal_managers_ActivityComponentManager_ActivityComponentBuilderEntryPoint.class,
_dagger_hilt_android_internal_managers_FragmentComponentManager_FragmentComponentBuilderEntryPoint.class,
_dagger_hilt_android_internal_managers_HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedComponentBuilderEntryPoint.class,
_dagger_hilt_android_internal_managers_HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedLifecycleEntryPoint.class,
_dagger_hilt_android_internal_managers_HiltWrapper_ActivityRetainedComponentManager_LifecycleModule.class,
_dagger_hilt_android_internal_managers_ServiceComponentManager_ServiceComponentBuilderEntryPoint.class,
_dagger_hilt_android_internal_managers_ViewComponentManager_ViewComponentBuilderEntryPoint.class,
_dagger_hilt_android_internal_managers_ViewComponentManager_ViewWithFragmentComponentBuilderEntryPoint.class,
_dagger_hilt_android_internal_modules_ApplicationContextModule.class,
_dagger_hilt_android_internal_modules_HiltWrapper_ActivityModule.class
],
)
@Generated("RootProcessor")
class _com_aregyan_github_Application_ComponentTreeDeps{
}
当前类@ComponentTreeDeps注解及注解值是关键!!!
ProcessedRootSentinelGenerator
dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点生成的类。
demo:
/**
* This class should only be referenced by generated code! This class aggregates information across multiple compilations.
*/
@AggregatedRoot(
root = "com.aregyan.github.Application",
originatingRoot = "com.aregyan.github.Application",
rootAnnotation = HiltAndroidApp.class
)
public class _com_aregyan_github_Application {
}
该类在dagger.hilt.internal.processedrootsentinel.codegen包下:
/**
* This class should only be referenced by generated code!This class aggregates information across multiple compilations.
*/
@Generated("ProcessedRootSentinelGenerator")
@ProcessedRootSentinel(roots = ["com.aregyan.github.Application"])
public class _dagger_hilt_internal_aggregatedroot_codegen_com_aregyan_github_Application{}
ComponentTreeDepsProcessor
处理@ComponentTreeDeps修饰的节点。
ComponentTreeDepsMetadata
使用@ComponentTreeDeps修饰的节点生成对象。属性如下:
-
ClassName name:@ComponentTreeDeps修饰的类;
-
ImmutableSet aggregatedRootDeps:@ComponentTreeDeps#rootDeps中的节点;
-
ImmutableSet defineComponentDeps:@ComponentTreeDeps#defineComponentDeps中的节点;
-
ImmutableSet aliasOfDeps:@ComponentTreeDeps#aliasOfDeps中的节点;
-
ImmutableSet aggregatedDeps:@ComponentTreeDeps#aggregatedDeps中的节点;
-
ImmutableSet aggregatedUninstallModulesDeps:@ComponentTreeDeps#uninstallModulesDeps中的节点;
-
ImmutableSet aggregatedEarlyEntryPointDeps:@ComponentTreeDeps#earlyEntryPointDeps中的节点。
ComponentDescriptor
@ComponentTreeDeps#defineComponentDeps中的节点(dagger.hilt.processor.internal.definecomponent.codegen包下使用@DefineComponentClasses注解的节点)生成的对象。
** 规则如下: **
-
@DefineComponentClasses#component中的节点一定是使用@DefineComponent修饰;@DefineComponentClasses#builder中的节点一定是使用@DefineComponent.Builder修饰;
-
如果有多个@DefineComponent.Builder修饰的接口,那么这些接口的build方法返回类型不允许相同。
@DefineComponentClasses#component和 @DefineComponentClasses#builder 有且仅有一个存在。
** 对象属性如下: **
-
ClassName component:@DefineComponent修饰的节点;
-
ImmutableSet scopes:@DefineComponent修饰的节点使用的@Scope修饰的注解修饰;
-
ClassName... scopes:暂时没用到;
-
ClassName creator:@DefineComponent.Builder修饰的接口的build方法返回类型是当前@DefineComponent修饰的节点;
-
ComponentDescriptor parent:@DefineComponent#parent。
所有的ComponentDescriptor对象生成ComponentTree树,该ComponentTree树中包含ComponentDescriptor对象生成的有向图:
-
有向图节点:当前ComponentDescriptor对象;
-
有向边:当前ComponentDescriptor对象存在父ComponentDescriptor对象 指向 当前ComponentDescriptor对象;
关系图如下:
ComponentDependencies
-
ImmutableSetMultimap.Builder<ClassName, TypeElement> modulesBuilder:K-@AggregatedDeps#components中的节点,V-@AggregatedDeps#modules节点;hilt源码+案例如下:
-
ImmutableSetMultimap.Builder<ClassName, TypeElement> entryPointsBuilder:(1)K-@AggregatedDeps#components中的节点,V-@AggregatedDeps#entryPoints;(2)K-SingletonComponent接口,V-@AggregatedEarlyEntryPoint#earlyEntryPoint;
-
ImmutableSetMultimap.Builder<ClassName, TypeElement> componentEntryPointsBuilder:K-@AggregatedDeps#components中的节点,V-@AggregatedDeps#componentEntryPoints;
- 暂时没有。
RootMetadata
该对象属性如下:
属性如下:
-
Root root:dagger.hilt.internal.aggregatedroot.codegen包下使用@AggregatedRoot修饰的节点中@AggregatedRoot#root中的节点生成Root对象;
-
ComponentTree componentTree:当前项目中所有dagger.hilt.processor.internal.definecomponent.codegen包下使用@DefineComponentClasses注解的节点生成的对象在生成当前ComponentTree树;
-
ComponentDependencies deps:查看以上对象,@AggregatedDeps生成的对应关系;
-
AliasOfs aliasOfs:对照关系图理解,@AliasOfPropagatedData#defineComponentScope中的节点,v:@AliasOfPropagatedData#alias中的节点(@AliasOf修饰的节点);
RootGenerator
demo为例,生成如下代码:
在上面RootGenerator类中生成的_com_aregyan_github_Application_HiltComponents中生成内部类:
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
public final class _com_aregyan_github_Application_HiltComponents{
private _com_aregyan_github_Application_HiltComponents(){}
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
@Module(subcomponents = hilt源码中的ActivityComponent.class)
@DisableInstallInCheck
interface ActivityComponentBuilderModule{
@Binds
public ActivityComponentBuilder bind(ActivityComponent.Builder builder);
}
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
@Module(subcomponents = hilt源码中的ActivityRetainedComponent.class)
@DisableInstallInCheck
interface ActivityRetainedComponentBuilderModule{
@Binds
public ActivityRetainedComponentBuilder bind(ActivityRetainedComponent.Builder builder);
}
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
@Module(subcomponents = hilt源码中的ViewWithFragmentComponent.class)
@DisableInstallInCheck
interface ViewWithFragmentComponentBuilderModule{
@Binds
public ViewWithFragmentComponentBuilder bind(ViewWithFragmentComponent.Builder builder);
}
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
@Module(subcomponents = hilt源码中的FragmentComponent.class)
@DisableInstallInCheck
interface FragmentComponentBuilderModule{
@Binds
public FragmentComponentBuilder bind(FragmentComponent.Builder builder);
}
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
@Module(subcomponents = hilt源码中的ServiceComponent.class)
@DisableInstallInCheck
interface ServiceComponentBuilderModule{
@Binds
public ServiceComponentBuilder bind(ServiceComponent.Builder builder);
}
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
@Module(subcomponents = hilt源码中的ViewComponent.class)
@DisableInstallInCheck
interface ViewComponentBuilderModule{
@Binds
public ViewComponentBuilder bind(ViewComponent.Builder builder);
}
@Generated("dagger.hilt.processor.internal.root.RootProcessor")
@Module(subcomponents = hilt源码中的ViewModelComponent.class)
@DisableInstallInCheck
interface ViewModelComponentBuilderModule{
@Binds
public ViewModelComponentBuilder bind(ViewModelComponent.Builder builder);
}
@Component(modules = [
DatabaseModule.class,
NetworkModule.class,
ApplicationContextModule.class,
ServiceComponentBuilderModule.class,
ActivityRetainedComponentBuilderModule.class,
ViewModelComponentBuilderModule.class,
ActivityComponentBuilderModule.class,
ViewComponentBuilderModule.class,
FragmentComponentBuilderModule.class,
ViewWithFragmentComponentBuilderModule.class
])
@Singleton
public static abstract class SingletonComponent
implements GeneratedComponent,
源码中的SingletonComponent,
Application_GeneratedInjector,
HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedComponentBuilderEntryPoint,
ServiceComponentManager.ServiceComponentBuilderEntryPoint{}
@subComponent(modules = [
UserDetailsViewModel_HiltModules.KeyModule.class,
UserListViewModel_HiltModules.KeyModule.class,
HiltWrapper_ActivityRetainedComponentManager_LifecycleModule.class,
ViewModelComponentBuilderModule.class,
ActivityComponentBuilderModule.class,
ViewComponentBuilderModule.class,
FragmentComponentBuilderModule.class,
ViewWithFragmentComponentBuilderModule.class,
])
@ActivityRetainedScoped
public static abstract class ActivityRetainedComponent
implements GeneratedComponent,
源码中的ActivityRetainedComponent,
ActivityComponentManager.ActivityComponentBuilderEntryPoint,
HiltWrapper_ActivityRetainedComponentManager_ActivityRetainedLifecycleEntryPoint{
@SubComponent.Builder
static interface Builder implements ActivityRetainedComponentBuilder{}
}
@subComponent(modules = [
HiltWrapper_DefaultViewModelFactories_ActivityModule.class,
HiltWrapper_ActivityModule.class,
ViewComponentBuilderModule.class,
FragmentComponentBuilderModule.class,
ViewWithFragmentComponentBuilderModule.class
])
@ActivityScoped
public static abstract class ActivityComponent
implements GeneratedComponent,
源码中的ActivityComponent,
MainActivity_GeneratedInjector,
DefaultViewModelFactories.ActivityEntryPoint,
HiltWrapper_HiltViewModelFactory_ActivityCreatorEntryPoint,
FragmentComponentManager.FragmentComponentBuilderEntryPoint,
ViewComponentManager.ViewComponentBuilderEntryPoint{
@SubComponent.Builder
static interface Builder implements ActivityComponentBuilder{}
}
@subComponent(modules = [
ViewWithFragmentComponentBuilderModule.class
])
@FragmentScoped
public static abstract class FragmentComponent
implements GeneratedComponent,
源码中的FragmentComponent,
UserDetailsFragment_GeneratedInjector,
UserListFragment_GeneratedInjector,
DefaultViewModelFactories.FragmentEntryPoint,
ViewComponentManager.ViewWithFragmentComponentBuilderEntryPoint{
@SubComponent.Builder
static interface Builder implements FragmentComponentBuilder{}
}
@subComponent
@ServiceScoped
public static abstract class ServiceComponent
implements GeneratedComponent,
源码中的ServiceComponent{
@SubComponent.Builder
static interface Builder implements ServiceComponentBuilder{}
}
@subComponent
@ViewScoped
public static abstract class ViewComponent
implements GeneratedComponent,
源码中的ViewComponent{
@SubComponent.Builder
static interface Builder implements ViewComponentBuilder{}
}
@subComponent(modules = [
UserDetailsViewModel_HiltModules.BindsModule.class,
UserListViewModel_HiltModules.BindsModule.class,
HiltWrapper_HiltViewModelFactory_ViewModelModule.class
])
@ViewModelScoped
public static abstract class ViewModelComponent
implements GeneratedComponent,
源码中的ViewModelComponent,
HiltViewModelFactory.ViewModelFactoriesEntryPoint{
@SubComponent.Builder
static interface Builder implements ViewModelComponentBuilder{}
}
@subComponent
@ViewScoped
public static abstract class ViewWithFragmentComponent
implements GeneratedComponent,
源码中的ViewWithFragmentComponent{
@SubComponent.Builder
static interface Builder implements ViewWithFragmentComponentBuilder{}
}
}
EarlySingletonComponentCreatorGenerator
测试环境下的,暂且不看。可自行去查看。
TestComponentDataGenerator
测试环境下的,暂且不看。可自行去查看。
ApplicationGenerator
这里我们掉回头去看第一篇文章的标签1了。
总结
至此代码讲解完毕,或者说理解完毕!!!但是代码太杂或者理解起来太过复杂,我们可以去把第0篇文章再看一遍,并且后面还有针对该源码实际应用的解说可以详细看一遍。