xref: /aosp_15_r20/external/dagger2/javatests/dagger/functional/kotlinsrc/binds/subpackage/ExposedModule.kt (revision f585d8a307d0621d6060bd7e80091fdcbf94fe27)
1 /*
2  * Copyright (C) 2022 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.binds.subpackage
18 
19 import dagger.Binds
20 import dagger.Module
21 import dagger.Provides
22 import dagger.multibindings.ElementsIntoSet
23 import dagger.multibindings.IntoSet
24 import javax.inject.Provider
25 import javax.inject.Singleton
26 import kotlin.jvm.JvmWildcard
27 
28 @Module
29 abstract class ExposedModule {
notExposednull30   @Binds internal abstract fun notExposed(notExposed: NotExposed): Exposed
31 
32   // TODO(b/260626101): @JvmWildcard is needed for KAPT to generate List<? extends Exposed>.
33   @Binds
34   internal abstract fun bindList(notExposedList: List<NotExposed>): List<@JvmWildcard Exposed>
35 
36   @Binds
37   internal abstract fun bindExposedInjectsMembers(
38     notExposedInjectsMembers: NotExposedInjectsMembers
39   ): ExposedInjectsMembers
40 
41   @Binds
42   @ElementsIntoSet
43   internal abstract fun bindCollectionOfNotExposeds(
44     collection: Collection<NotExposed>
45   ): Set<NotExposed>
46 
47   companion object {
48     @Provides
49     @Singleton // force a rawtypes Provider
50     internal fun notExposedList(): List<NotExposed> = listOf(NotExposed())
51 
52     @Provides
53     internal fun provideNotExposedCollection(notExposed: NotExposed): Collection<NotExposed> {
54       return listOf(notExposed) as Collection<NotExposed>
55     }
56 
57     @Provides
58     @IntoSet // This is needed to ensure a provider field gets created for providing the Collection.
59     internal fun provideNotExposed(
60       collectionProvider: Provider<Collection<NotExposed>>
61     ): NotExposed {
62       return collectionProvider.get().iterator().next()
63     }
64 
65     @Provides
66     internal fun provideString(setOfFoo: Set<NotExposed>): String = "not exposed"
67   }
68 }
69