1 /*
2  * Copyright (C) 2015 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 import dagger.functional.GenericComponent.NongenericModule;
23 import dagger.functional.sub.Exposed;
24 import dagger.functional.sub.PublicSubclass;
25 import java.util.Arrays;
26 import java.util.List;
27 import javax.inject.Provider;
28 
29 @Component(modules = {ChildDoubleModule.class, ChildIntegerModule.class, NongenericModule.class})
30 interface GenericComponent {
referencesGeneric()31   ReferencesGeneric referencesGeneric();
doubleGenericA()32   GenericDoubleReferences<A> doubleGenericA();
doubleGenericB()33   GenericDoubleReferences<B> doubleGenericB();
complexGenerics()34   ComplexGenerics complexGenerics();
noDepsA()35   GenericNoDeps<A> noDepsA();
noDepsB()36   GenericNoDeps<B> noDepsB();
37 
injectA(GenericChild<A> childA)38   void injectA(GenericChild<A> childA);
injectB(GenericChild<B> childB)39   void injectB(GenericChild<B> childB);
40 
exposed()41   Exposed exposed();
publicSubclass()42   PublicSubclass publicSubclass();
43 
iterableInt()44   Iterable<Integer> iterableInt();
iterableDouble()45   Iterable<Double> iterableDouble();
46 
stringsProvider()47   Provider<List<String>> stringsProvider(); // b/71595104
48 
49   // b/71595104
50   @Module
51   abstract class GenericModule<T> {
52     // Note that for subclasses that use String for T, this factory will still need two
53     // Provider<String> framework dependencies.
54     @Provides
list(T t, String string)55     List<T> list(T t, String string) {
56       return Arrays.asList(t);
57     }
58   }
59 
60   // b/71595104
61   @Module
62   class NongenericModule extends GenericModule<String> {
63     @Provides
string()64     static String string() {
65       return "string";
66     }
67   }
68 }
69