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.module
18 
19 import dagger.Component
20 import dagger.Module
21 import dagger.Provides
22 import dagger.Subcomponent
23 import dagger.multibindings.IntoSet
24 import javax.inject.Inject
25 
26 /** Supporting types for [ModuleWithSubcomponentsTest]. */
27 @Component(modules = [UsesModuleSubcomponents.ModuleWithSubcomponents::class])
28 interface UsesModuleSubcomponents {
usesChildnull29   fun usesChild(): UsesChild
30   fun strings(): Set<String>
31 
32   @Module(subcomponents = [Child::class], includes = [AlsoIncludesSubcomponents::class])
33   object ModuleWithSubcomponents {
34     @Provides @IntoSet fun provideStringInParent(): String = "from parent"
35   }
36 
37   @Module(subcomponents = [Child::class]) class AlsoIncludesSubcomponents
38 
39   @Subcomponent(modules = [ChildModule::class])
40   interface Child {
stringsnull41     fun strings(): Set<String>
42 
43     @Subcomponent.Builder
44     interface Builder {
45       fun build(): Child
46     }
47   }
48 
49   @Module
50   object ChildModule {
provideStringInChildnull51     @Provides @IntoSet fun provideStringInChild(): String = "from child"
52   }
53 
54   class UsesChild @Inject internal constructor(childBuilder: Child.Builder) {
55     var strings: Set<String> = childBuilder.build().strings()
56   }
57 
58   @Module(includes = [ModuleWithSubcomponents::class]) class OnlyIncludesModuleWithSubcomponents
59 
60   @Component(modules = [OnlyIncludesModuleWithSubcomponents::class])
61   interface ParentIncludesSubcomponentTransitively : UsesModuleSubcomponents
62 }
63