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.reusable
18 
19 import dagger.Component
20 import dagger.Module
21 import dagger.Provides
22 import dagger.Reusable
23 import dagger.Subcomponent
24 import javax.inject.Provider
25 import javax.inject.Qualifier
26 
27 @Component(modules = [ComponentWithReusableBindings.ReusableBindingsModule::class])
28 interface ComponentWithReusableBindings {
29   @Qualifier annotation class InParent
30 
31   @Qualifier annotation class InChildren
32 
reusableInParentnull33   @InParent fun reusableInParent(): Any
34   fun childOne(): ChildOne
35   fun childTwo(): ChildTwo
36 
37   // b/77150738
38   fun primitive(): Int
39 
40   // b/77150738: This is used as a regression test for fastInit mode's switching providers. In
41   // particular, it occurs when a @Provides method returns the boxed type but the component method
42   // returns the unboxed type, and the instance is requested from a SwitchingProvider.
43   fun unboxedPrimitive(): Boolean
44 
45   // b/77150738
46   fun booleanProvider(): Provider<Boolean>
47 
48   @Subcomponent
49   interface ChildOne {
50     @InParent fun reusableInParent(): Any
51 
52     @InChildren fun reusableInChild(): Any
53   }
54 
55   @Subcomponent
56   interface ChildTwo {
reusableInParentnull57     @InParent fun reusableInParent(): Any
58 
59     @InChildren fun reusableInChild(): Any
60   }
61 
62   @Module
63   object ReusableBindingsModule {
64     @Provides
65     @Reusable
66     @InParent
67     fun inParent(): Any {
68       return Any()
69     }
70 
71     @Provides
72     @Reusable
73     @InChildren
74     fun inChildren(): Any {
75       return Any()
76     }
77 
78     // b/77150738
79     @Provides @Reusable fun primitive(): Int = 0
80 
81     // b/77150738
82     @Provides @Reusable fun boxedPrimitive(): Boolean = false
83   }
84 }
85