1 /* 2 * Copyright (C) 2022 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.kotlinsrc.binds 18 19 import dagger.Binds 20 import dagger.Module 21 import dagger.Provides 22 import dagger.Reusable 23 import dagger.multibindings.ElementsIntoSet 24 import dagger.multibindings.IntKey 25 import dagger.multibindings.IntoMap 26 import dagger.multibindings.IntoSet 27 import java.util.TreeSet 28 import javax.inject.Named 29 import javax.inject.Singleton 30 31 @Module(includes = [InterfaceModule::class]) 32 internal abstract class SimpleBindingModule { 33 34 @Binds bindObjectnull35 abstract fun bindObject(impl: FooOfStrings): Any 36 37 @Binds 38 @Reusable 39 @SomeQualifier 40 abstract fun bindReusableObject(impl: FooOfStrings): Any 41 42 @Binds 43 abstract fun bindFooOfStrings(impl: FooOfStrings): Foo<String> 44 45 @Binds 46 abstract fun bindFooOfNumbers(fooOfIntegers: Foo<Int>): Foo<out Number> 47 48 @Binds 49 @Singleton 50 @SomeQualifier 51 abstract fun bindQualifiedFooOfStrings(impl: FooOfStrings): Foo<String> 52 53 @Binds 54 @IntoSet 55 abstract fun bindFooOfIntegersIntoSet(fooOfIntegers: Foo<Int>): Foo<out Number> 56 57 @Binds 58 @IntoSet 59 abstract fun bindFooExtendsNumberIntoSet(fooOfDoubles: Foo<Double>): Foo<out Number> 60 61 @Binds 62 @ElementsIntoSet 63 abstract fun bindSetOfFooNumbersToObjects( 64 setOfFooNumbers: Set<@JvmSuppressWildcards Foo<out Number>> 65 ): Set<Any> 66 67 @Binds 68 @IntoSet 69 abstract fun bindFooOfStringsIntoSetOfObjects(impl: FooOfStrings): Any 70 71 @Binds 72 @ElementsIntoSet 73 abstract fun bindHashSetOfStrings(set: HashSet<String>): Set<CharSequence> 74 75 @Binds 76 @ElementsIntoSet 77 abstract fun bindTreeSetOfCharSequences(set: TreeSet<CharSequence>): Set<CharSequence> 78 79 @Binds 80 @ElementsIntoSet 81 abstract fun bindCollectionOfCharSequences( 82 collection: Collection<@JvmSuppressWildcards CharSequence> 83 ): Set<CharSequence> 84 85 @Binds 86 @IntoMap 87 @IntKey(123) 88 abstract fun bind123ForMap(@Named("For-123") string: String): Any 89 90 @Binds 91 @IntoMap 92 @IntKey(456) 93 abstract fun bind456ForMap(@Named("For-456") string: String): Any 94 95 @Binds 96 @SomeQualifier 97 abstract fun primitiveToPrimitive(intValue: Int): Int 98 99 @Binds 100 @IntoSet 101 abstract fun intValueIntoSet(intValue: Int): Int 102 103 @Binds 104 @IntoMap 105 @IntKey(10) 106 abstract fun intValueIntoMap(intValue: Int): Int 107 108 @Binds 109 @IntoMap 110 @IntKey(123) 111 @SomeQualifier 112 abstract fun bindFooOfStringsIntoQualifiedMap(fooOfStrings: FooOfStrings): Any 113 114 companion object { 115 @Provides 116 fun provideFooOfIntegers(): Foo<Int> = object : Foo<Int> {} 117 118 @Provides 119 fun provideFooOfDoubles(): Foo<Double> = object : Foo<Double> {} 120 121 @Provides 122 fun provideStringHashSet(): HashSet<String> = hashSetOf("hash-string1", "hash-string2") 123 124 @Provides 125 fun provideCharSequenceTreeSet(): TreeSet<CharSequence> = sortedSetOf( 126 "tree-charSequence1", "tree-charSequence2" 127 ) 128 129 @Provides 130 fun provideCharSequenceCollection(): Collection<CharSequence> = listOf("list-charSequence") 131 132 @Provides 133 @IntoMap 134 @IntKey(789) 135 fun provide789ForMap(): Any = "789-string" 136 137 @Provides 138 fun intValue(): Int = 100 139 140 @Provides 141 @Named("For-123") 142 fun provide123String(): String = "123-string" 143 144 @Provides 145 @Named("For-456") 146 fun provide456String(): String = "456-string" 147 } 148 } 149