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