1 /* 2 * Copyright (C) 2023 The Dagger Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dagger.functional.kotlinsrc.subcomponent.pruning 18 19 import dagger.Component 20 import dagger.Module 21 import dagger.Provides 22 import dagger.Subcomponent 23 import dagger.functional.kotlinsrc.subcomponent.pruning.ParentDoesntUseSubcomponent.ChildA 24 import dagger.multibindings.IntoSet 25 import javax.inject.Qualifier 26 27 /** 28 * Supporting types for [SubcomponentOnlyRequestedBySiblingTest]. [ChildA] is a direct child of the 29 * top level component, but is only requested within its sibling, not directly from its parent. 30 */ 31 @Component(modules = [ParentDoesntUseSubcomponent.ParentModule::class]) 32 interface ParentDoesntUseSubcomponent { childBBuildernull33 fun childBBuilder(): ChildB.Builder 34 35 @Subcomponent(modules = [ChildAModule::class]) 36 interface ChildA { 37 @Subcomponent.Builder 38 interface Builder { 39 fun build(): ChildA 40 } 41 42 fun componentHierarchy(): Set<Class<*>> 43 } 44 45 @Subcomponent(modules = [ChildBModule::class]) 46 interface ChildB { 47 @Subcomponent.Builder 48 interface Builder { buildnull49 fun build(): ChildB 50 } 51 52 fun componentHierarchy(): Set<Class<*>> 53 54 @FromChildA fun componentHierarchyFromChildA(): Set<Class<*>> 55 } 56 57 @Module(subcomponents = [ChildA::class, ChildB::class]) 58 object ParentModule { 59 @Provides 60 @IntoSet 61 fun provideComponentType(): Class<*> = ParentDoesntUseSubcomponent::class.java 62 } 63 64 @Module 65 object ChildAModule { provideComponentTypenull66 @Provides @IntoSet fun provideComponentType(): Class<*> = ChildA::class.java 67 } 68 69 @Module 70 class ChildBModule { 71 @Provides 72 @FromChildA 73 fun fromChildA(childABuilder: ChildA.Builder): Set<Class<*>> = 74 childABuilder.build().componentHierarchy() 75 76 companion object { 77 @Provides @IntoSet fun provideComponentType(): Class<*> = ChildB::class.java 78 } 79 } 80 81 @Qualifier annotation class FromChildA 82 } 83