1 /*
2  * Copyright (C) 2016 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.reusable;
18 
19 import dagger.Component;
20 import dagger.Module;
21 import dagger.Provides;
22 import dagger.Reusable;
23 import dagger.Subcomponent;
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 import javax.inject.Provider;
27 import javax.inject.Qualifier;
28 
29 @Component(modules = ComponentWithReusableBindings.ReusableBindingsModule.class)
30 interface ComponentWithReusableBindings {
31 
32   @Qualifier
33   @Retention(RetentionPolicy.RUNTIME)
34   @interface InParent {}
35 
36   @Qualifier
37   @Retention(RetentionPolicy.RUNTIME)
38   @interface InChildren {}
39 
40   @InParent
reusableInParent()41   Object reusableInParent();
42 
childOne()43   ChildOne childOne();
44 
childTwo()45   ChildTwo childTwo();
46 
47   // b/77150738
primitive()48   int primitive();
49 
50   // b/77150738: This is used as a regression test for fastInit mode's switching providers. In
51   // particular, it occurs when a @Provides method returns the boxed type but the component method
52   // returns the unboxed type, and the instance is requested from a SwitchingProvider.
unboxedPrimitive()53   boolean unboxedPrimitive();
54 
55   // b/77150738
booleanProvider()56   Provider<Boolean> booleanProvider();
57 
58   @Subcomponent
59   interface ChildOne {
60     @InParent
reusableInParent()61     Object reusableInParent();
62 
63     @InChildren
reusableInChild()64     Object reusableInChild();
65   }
66 
67   @Subcomponent
68   interface ChildTwo {
69     @InParent
reusableInParent()70     Object reusableInParent();
71 
72     @InChildren
reusableInChild()73     Object reusableInChild();
74   }
75 
76   @Module
77   static class ReusableBindingsModule {
78     @Provides
79     @Reusable
80     @InParent
inParent()81     static Object inParent() {
82       return new Object();
83     }
84 
85     @Provides
86     @Reusable
87     @InChildren
inChildren()88     static Object inChildren() {
89       return new Object();
90     }
91 
92     // b/77150738
93     @Provides
94     @Reusable
primitive()95     static int primitive() {
96       return 0;
97     }
98 
99     // b/77150738
100     @Provides
101     @Reusable
boxedPrimitive()102     static Boolean boxedPrimitive() {
103       return false;
104     }
105   }
106 }
107