• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package dagger.functional.kotlin
2 
3 import dagger.Binds
4 import dagger.Component
5 import dagger.Module
6 import dagger.Provides
7 import javax.inject.Named
8 
9 @Component(
10   modules = [
11     TestKotlinModuleWithCompanion::class,
12     TestKotlinModuleWithNamedCompanion::class,
13     TestKotlinAbstractModuleWithCompanion::class,
14     TestKotlinWorkaroundModuleWithCompanion::class,
15     TestKotlinModuleWithPrivateCompanion::class
16   ]
17 )
18 interface TestKotlinComponentWithCompanionModule {
getDataAnull19   fun getDataA(): TestDataA
20   fun getDataB(): TestDataB
21   fun getBoolean(): Boolean
22   fun getStringType(): String
23   @Named("Cat")
24   fun getCatNamedStringType(): String
25   @Named("Dog")
26   fun getDogNamedStringType(): String
27 
28   fun getInterface(): TestInterface
29   fun getLong(): Long
30   fun getDouble(): Double
31   fun getInteger(): Int
32 }
33 
34 @Module
35 class TestKotlinModuleWithCompanion {
36   @Provides
37   fun provideDataA() = TestDataA("test")
38 
39   companion object {
40     @Provides
41     fun provideDataB() = TestDataB("test")
42 
43     @Provides
44     fun provideBoolean(): Boolean = true
45   }
46 }
47 
48 @Module
49 class TestKotlinModuleWithNamedCompanion {
50 
51   @Provides
52   @Named("Cat")
provideNamedStringnull53   fun provideNamedString() = "Cat"
54 
55   companion object Foo {
56     @Provides
57     fun provideStringType(): String = ""
58   }
59 }
60 
61 @Module
62 abstract class TestKotlinAbstractModuleWithCompanion {
63 
64   @Binds
bindInterfacenull65   abstract fun bindInterface(injectable: TestInjectable): TestInterface
66 
67   companion object {
68     @Provides
69     fun provideLong() = 4L
70   }
71 }
72 
73 @Module
74 class TestKotlinWorkaroundModuleWithCompanion {
75 
76   @Provides
provideDoublenull77   fun provideDouble() = 1.0
78 
79   @Module
80   companion object {
81     @Provides
82     @JvmStatic
83     fun provideInteger() = 2
84   }
85 }
86 
87 @Module
88 class TestKotlinModuleWithPrivateCompanion {
89 
90   @Provides
91   @Named("Dog")
getNamedStringTypenull92   fun getNamedStringType() = "Dog"
93 
94   private companion object {
95     fun randomFunction() = ""
96   }
97 }
98