• 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.producers.subcomponent;
18 
19 import com.google.common.util.concurrent.ListenableFuture;
20 import dagger.functional.producers.ExecutorModule;
21 import dagger.multibindings.IntoSet;
22 import dagger.producers.ProducerModule;
23 import dagger.producers.Produces;
24 import dagger.producers.ProductionComponent;
25 import dagger.producers.ProductionSubcomponent;
26 import java.util.Set;
27 import javax.inject.Qualifier;
28 
29 /** Supporting types for {@code ProducerModuleWithSubcomponentsTest}. */
30 @ProductionComponent(
31   modules = UsesProducerModuleSubcomponents.ProducerModuleWithSubcomponents.class
32 )
33 public interface UsesProducerModuleSubcomponents {
34 
strings()35   ListenableFuture<Set<String>> strings();
36 
37   @FromChild
stringsFromChild()38   ListenableFuture<Set<String>> stringsFromChild();
39 
40   @ProducerModule(
41     subcomponents = Child.class,
42     includes = {AlsoIncludesSubcomponents.class, ExecutorModule.class}
43   )
44   class ProducerModuleWithSubcomponents {
45     @Produces
46     @IntoSet
produceStringInParent()47     static String produceStringInParent() {
48       return "from parent";
49     }
50 
51     @Produces
52     @FromChild
stringsFromChild(Child.Builder childBuilder)53     static Set<String> stringsFromChild(Child.Builder childBuilder) throws Exception {
54       return childBuilder.build().strings().get();
55     }
56   }
57 
58   @ProducerModule(subcomponents = Child.class)
59   class AlsoIncludesSubcomponents {}
60 
61   @ProductionSubcomponent(modules = ChildModule.class)
62   interface Child {
strings()63     ListenableFuture<Set<String>> strings();
64 
65     @ProductionSubcomponent.Builder
66     interface Builder {
build()67       Child build();
68     }
69   }
70 
71   @ProducerModule
72   class ChildModule {
73     @Produces
74     @IntoSet
produceStringInChild()75     static String produceStringInChild() {
76       return "from child";
77     }
78   }
79 
80   @Qualifier
81   @interface FromChild {}
82 
83   @ProducerModule(includes = ProducerModuleWithSubcomponents.class)
84   class OnlyIncludesProducerModuleWithSubcomponents {}
85 
86   @ProductionComponent(modules = OnlyIncludesProducerModuleWithSubcomponents.class)
87   interface ParentIncludesProductionSubcomponentTransitively
88       extends UsesProducerModuleSubcomponents {}
89 }
90