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.subcomponent.pruning; 18 19 import dagger.Component; 20 import dagger.Module; 21 import dagger.Provides; 22 import dagger.Subcomponent; 23 import dagger.multibindings.IntoSet; 24 import java.util.Set; 25 import javax.inject.Qualifier; 26 27 /** 28 * Supporting types for {@link SubcomponentOnlyRequestedBySiblingTest}. {@link ChildA} is a direct 29 * child of the top level component, but is only requested within its sibling, not directly from its 30 * parent. 31 */ 32 @Component(modules = ParentDoesntUseSubcomponent.ParentModule.class) 33 interface ParentDoesntUseSubcomponent { 34 childBBuilder()35 ChildB.Builder childBBuilder(); 36 37 @Subcomponent(modules = ChildAModule.class) 38 interface ChildA { 39 @Subcomponent.Builder 40 interface Builder { build()41 ChildA build(); 42 } 43 componentHierarchy()44 Set<Class<?>> componentHierarchy(); 45 } 46 47 @Subcomponent(modules = ChildBModule.class) 48 interface ChildB { 49 @Subcomponent.Builder 50 interface Builder { build()51 ChildB build(); 52 } 53 componentHierarchy()54 Set<Class<?>> componentHierarchy(); 55 56 @FromChildA componentHierarchyFromChildA()57 Set<Class<?>> componentHierarchyFromChildA(); 58 } 59 60 @Module(subcomponents = {ChildA.class, ChildB.class}) 61 class ParentModule { 62 @Provides 63 @IntoSet provideComponentType()64 static Class<?> provideComponentType() { 65 return ParentDoesntUseSubcomponent.class; 66 } 67 } 68 69 @Module 70 class ChildAModule { 71 @Provides 72 @IntoSet provideComponentType()73 static Class<?> provideComponentType() { 74 return ChildA.class; 75 } 76 } 77 78 @Module 79 class ChildBModule { 80 @Provides 81 @IntoSet provideComponentType()82 static Class<?> provideComponentType() { 83 return ChildB.class; 84 } 85 86 @Provides 87 @FromChildA fromChildA(ChildA.Builder childABuilder)88 Set<Class<?>> fromChildA(ChildA.Builder childABuilder) { 89 return childABuilder.build().componentHierarchy(); 90 } 91 } 92 93 @Qualifier 94 @interface FromChildA {} 95 } 96