1 /* 2 * Copyright (C) 2017 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.binds.subpackage; 18 19 import dagger.Binds; 20 import dagger.Module; 21 import dagger.Provides; 22 import dagger.multibindings.ElementsIntoSet; 23 import dagger.multibindings.IntoSet; 24 import java.util.ArrayList; 25 import java.util.Arrays; 26 import java.util.Collection; 27 import java.util.List; 28 import java.util.Set; 29 import javax.inject.Provider; 30 import javax.inject.Singleton; 31 32 @Module 33 public abstract class ExposedModule { 34 @Binds notExposed(NotExposed notExposed)35 abstract Exposed notExposed(NotExposed notExposed); 36 37 @Provides 38 @Singleton // force a rawtypes Provider notExposedList()39 static List<NotExposed> notExposedList() { 40 return new ArrayList<>(); 41 } 42 43 @Binds bindList(List<NotExposed> notExposedList)44 abstract List<? extends Exposed> bindList(List<NotExposed> notExposedList); 45 46 @Binds bindExposedInjectsMembers( NotExposedInjectsMembers notExposedInjectsMembers)47 abstract ExposedInjectsMembers bindExposedInjectsMembers( 48 NotExposedInjectsMembers notExposedInjectsMembers); 49 50 @Provides provideNotExposedCollection(NotExposed notExposed)51 static Collection<NotExposed> provideNotExposedCollection(NotExposed notExposed) { 52 return Arrays.<NotExposed>asList(notExposed); 53 } 54 55 @Provides 56 @IntoSet // This is needed to ensure a provider field gets created for providing the Collection. provideNotExposed(Provider<Collection<NotExposed>> collectionProvider)57 static NotExposed provideNotExposed(Provider<Collection<NotExposed>> collectionProvider) { 58 return collectionProvider.get().iterator().next(); 59 } 60 61 @Binds 62 @ElementsIntoSet bindCollectionOfNotExposeds(Collection<NotExposed> collection)63 abstract Set<NotExposed> bindCollectionOfNotExposeds(Collection<NotExposed> collection); 64 65 @Provides provideString(Set<NotExposed> setOfFoo)66 static String provideString(Set<NotExposed> setOfFoo) { 67 return "not exposed"; 68 } 69 } 70