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 23 /** 24 * This tests that @Module.includes are traversed for supertypes of a module. 25 */ 26 final class ModuleIncludesCollectedFromModuleSuperclasses { 27 @Component(modules = TopLevelModule.class) 28 interface C { foo()29 Foo<String> foo(); includedInTopLevelModule()30 int includedInTopLevelModule(); includedFromModuleInheritance()31 String includedFromModuleInheritance(); 32 } 33 34 @Module(includes = IncludedTopLevel.class) 35 static class TopLevelModule extends FooModule<String> {} 36 37 static class Foo<T> {} 38 39 @Module(includes = IncludedFromModuleInheritance.class) 40 abstract static class FooModule<T> extends FooCreator { fooOfT()41 @Provides Foo<T> fooOfT() { 42 return createFoo(); 43 } 44 } 45 46 static class FooCreator { createFoo()47 <T> Foo<T> createFoo() { 48 return new Foo<T>(); 49 } 50 } 51 52 @Module 53 static class IncludedTopLevel { i()54 @Provides int i() { 55 return 123; 56 } 57 } 58 59 @Module 60 static class IncludedFromModuleInheritance { inheritedProvision()61 @Provides String inheritedProvision() { 62 return "inherited"; 63 } 64 } 65 } 66