xref: /aosp_15_r20/external/dagger2/javatests/dagger/functional/kotlinsrc/binds/AccessesExposedComponent.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
18 
19 import dagger.Component
20 import dagger.functional.kotlinsrc.binds.subpackage.Exposed
21 import dagger.functional.kotlinsrc.binds.subpackage.ExposedModule
22 import dagger.functional.kotlinsrc.binds.subpackage.UsesExposedInjectsMembers
23 import javax.inject.Provider
24 import javax.inject.Singleton
25 
26 /**
27  * This component tests cases where the right-hand-side of a [dagger.Binds] method is not accessible
28  * from the component, but the left-hand-side is. If the right-hand-side is represented as a
29  * Provider (e.g. because it is scoped), then the raw `Provider.get()` will return [ ], which must
30  * be downcasted to the type accessible from the component. See `instanceRequiresCast()` in
31  * `DelegateRequestRepresentation`.
32  */
33 @Singleton
34 @Component(modules = [ExposedModule::class])
35 internal interface AccessesExposedComponent {
exposednull36   fun exposed(): Exposed
37 
38   fun exposedProvider(): Provider<Exposed>
39 
40   // TODO(b/260626101): @JvmWildcard is needed for KAPT to generate List<? extends Exposed>.
41   fun listOfExposed(): List<@JvmWildcard Exposed>
42 
43   // TODO(b/260626101): @JvmWildcard is needed for KAPT to generate List<? extends Exposed>.
44   fun providerOfListOfExposed(): Provider<List<@JvmWildcard Exposed>>
45 
46   fun usesExposedInjectsMembers(): UsesExposedInjectsMembers
47 
48   /**
49    * This provider needs a `Provider<ExposedInjectsMembers>`, which is bound to a
50    * `Provider<NotExposedInjectsMembers>`. This method is here to make sure that the cast happens
51    * appropriately.
52    */
53   fun usesExposedInjectsMembersProvider(): Provider<UsesExposedInjectsMembers>
54 }
55