Skip to content

Commit

Permalink
fix(whetstone-compiler): workaround KT-58027
Browse files Browse the repository at this point in the history
  • Loading branch information
msfjarvis committed Sep 7, 2023
1 parent 2b84e51 commit 2a2f4b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ internal object FqNames {
@JvmField val AUTO_INJECTOR = FqName("com.deliveryhero.whetstone.meta.AutoInjectorBinding")
@JvmField val AUTO_INSTANCE = FqName("com.deliveryhero.whetstone.meta.AutoInstanceBinding")
@JvmField val SINGLE_IN = FqName("com.deliveryhero.whetstone.SingleIn")
@JvmField val APPLICATION = FqName("android.app.Application")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.deliveryhero.whetstone.compiler.handlers

import com.deliveryhero.whetstone.compiler.CodegenHandler
import com.deliveryhero.whetstone.compiler.FqNames
import com.deliveryhero.whetstone.compiler.FqNames.APPLICATION
import com.deliveryhero.whetstone.compiler.GeneratedFileInfo
import com.deliveryhero.whetstone.compiler.getValue
import com.squareup.anvil.annotations.MergeComponent
Expand Down Expand Up @@ -59,14 +60,21 @@ internal class AppComponentHandler : CodegenHandler {
.addSuperinterface(applicationComponentCn.nestedClass("Factory"))
.addAnnotation(Component.Factory::class)
.build()
val appParam = ParameterSpec.builder("application", APPLICATION.asClassName(module))
.build()
val companionObjectSpec = TypeSpec.companionObjectBuilder("Default")
.addSuperinterface(
generatedComponentCn.nestedClass("Factory"),
CodeBlock.of(
"%T.factory()",
generatedComponentCn.peerClass("Dagger${generatedComponentCn.simpleName}")
)
)
.addSuperinterface(generatedComponentCn.nestedClass("Factory"))
.addFunction(
FunSpec.builder("create")
.addParameter(appParam)
.returns(generatedComponentCn)
.addModifiers(KModifier.PUBLIC, KModifier.OVERRIDE)
.addCode(CodeBlock.of(
"return DaggerGeneratedApplicationComponent.factory().create(%L) as %T",
appParam.name,
generatedComponentCn,
))
.build())
.build()

val appComponentSpec = TypeSpec.interfaceBuilder(generatedComponentCn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ import com.deliveryhero.whetstone.meta.AutoInjectorBinding
* @Component.Factory
* public interface Factory : ApplicationComponent.Factory
*
* public companion object Default : Factory by DaggerGeneratedApplicationComponent.factory()
* }
* public companion object Default : Factory {
* public override fun create(application: Application): GeneratedApplicationComponent =
* DaggerGeneratedApplicationComponent.factory().create(application) as
* GeneratedApplicationComponent
* }
* ```
*
* This can be very handy for quickly bootstrapping the DI setup. It is ideal for cases where the
Expand Down

0 comments on commit 2a2f4b0

Please sign in to comment.