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.pruning; 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 /** 29 * Supporting types for {@code ProductionSubcomponentOnlyRequestedBySiblingTest}. {@link ChildA} is 30 * a direct child of the top level component, but is only requested within its sibling, not directly 31 * from its parent. 32 */ 33 @ProductionComponent( 34 modules = { 35 ParentDoesntUseProductionSubcomponent.ParentModule.class, 36 dagger.functional.producers.ExecutorModule.class 37 } 38 ) 39 interface ParentDoesntUseProductionSubcomponent { 40 childBBuilder()41 ChildB.Builder childBBuilder(); 42 43 @ProductionSubcomponent(modules = ChildAModule.class) 44 interface ChildA { 45 @ProductionSubcomponent.Builder 46 interface Builder { build()47 ChildA build(); 48 } 49 componentHierarchy()50 ListenableFuture<Set<Class<?>>> componentHierarchy(); 51 } 52 53 @ProductionSubcomponent(modules = ChildBModule.class) 54 interface ChildB { 55 @ProductionSubcomponent.Builder 56 interface Builder { build()57 ChildB build(); 58 } 59 componentHierarchy()60 ListenableFuture<Set<Class<?>>> componentHierarchy(); 61 62 @FromChildA componentHierarchyFromChildA()63 ListenableFuture<Set<Class<?>>> componentHierarchyFromChildA(); 64 } 65 66 @ProducerModule(subcomponents = {ChildA.class, ChildB.class}) 67 class ParentModule { 68 @Produces 69 @IntoSet produceComponentType()70 static Class<?> produceComponentType() { 71 return ParentDoesntUseProductionSubcomponent.class; 72 } 73 } 74 75 @ProducerModule 76 class ChildAModule { 77 @Produces 78 @IntoSet produceComponentType()79 static Class<?> produceComponentType() { 80 return ChildA.class; 81 } 82 } 83 84 @ProducerModule 85 class ChildBModule { 86 @Produces 87 @IntoSet produceComponentType()88 static Class<?> produceComponentType() { 89 return ChildB.class; 90 } 91 92 @Produces 93 @FromChildA fromChildA(ChildA.Builder childABuilder)94 Set<Class<?>> fromChildA(ChildA.Builder childABuilder) throws Exception { 95 return childABuilder.build().componentHierarchy().get(); 96 } 97 } 98 99 @Qualifier 100 @interface FromChildA {} 101 } 102