• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
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 
30   @Qualifier
31   @interface InParent {}
32 
33   @Qualifier
34   @interface InChildren {}
35 
36   @InParent
reusableInParent()37   Object reusableInParent();
38 
childOne()39   ChildOne childOne();
40 
childTwo()41   ChildTwo childTwo();
42 
43   // b/77150738
primitive()44   int primitive();
45 
46   // b/77150738: This is used as a regression test for fastInit mode's switching providers. In
47   // particular, it occurs when a @Provides method returns the boxed type but the component method
48   // returns the unboxed type, and the instance is requested from a SwitchingProvider.
unboxedPrimitive()49   boolean unboxedPrimitive();
50 
51   // b/77150738
booleanProvider()52   Provider<Boolean> booleanProvider();
53 
54   @Subcomponent
55   interface ChildOne {
56     @InParent
reusableInParent()57     Object reusableInParent();
58 
59     @InChildren
reusableInChild()60     Object reusableInChild();
61   }
62 
63   @Subcomponent
64   interface ChildTwo {
65     @InParent
reusableInParent()66     Object reusableInParent();
67 
68     @InChildren
reusableInChild()69     Object reusableInChild();
70   }
71 
72   @Module
73   static class ReusableBindingsModule {
74     @Provides
75     @Reusable
76     @InParent
inParent()77     static Object inParent() {
78       return new Object();
79     }
80 
81     @Provides
82     @Reusable
83     @InChildren
inChildren()84     static Object inChildren() {
85       return new Object();
86     }
87 
88     // b/77150738
89     @Provides
90     @Reusable
primitive()91     static int primitive() {
92       return 0;
93     }
94 
95     // b/77150738
96     @Provides
97     @Reusable
boxedPrimitive()98     static Boolean boxedPrimitive() {
99       return false;
100     }
101   }
102 }
103