Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import kotlinx.coroutines.flow.onStart

context(coroutineScopeOwner: CoroutineScopeOwner)
fun <T : Any?> FlowUseCase<Unit, T>.execute(
config: FlowUseCaseConfig.Builder<T, T>.() -> Unit
) = execute(Unit, config)
config: FlowUseCaseConfig.Builder<T, T>.() -> Unit,
): Unit = execute(Unit, config)

/**
* Asynchronously executes use case and consumes data from flow on UI thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import kotlinx.coroutines.launch
* Coroutine and to set configuration options.
*/
context(coroutineScopeOwner: CoroutineScopeOwner)
fun <T : Any?> UseCase<Unit, T>.execute(config: UseCaseConfig.Builder<T>.() -> Unit) = execute(Unit, config)
fun <T : Any?> UseCase<Unit, T>.execute(
config: UseCaseConfig.Builder<T>.() -> Unit,
): Unit = execute(Unit, config)

/**
* Asynchronously executes use case and saves it's Deferred. By default, all previous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ import kotlin.reflect.KClass
class ComponentFactoryProcessor(
private val codeGenerator: CodeGenerator,
) : SymbolProcessor {

var invoked: Boolean = false

override fun process(resolver: Resolver): List<KSAnnotated> {
val components: Sequence<KSClassDeclaration> = resolver.findAnnotationsForClass(GenerateFactory::class)
if (invoked) {
return emptyList()
}
invoked = true

val components: Sequence<KSClassDeclaration> = resolver.findAnnotationsForClass(GenerateFactory::class)
components.forEach { generateComponent(it) }

return emptyList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package app.futured.arkitekt.factorygenerator.processor

import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSFile
import com.google.devtools.ksp.symbol.KSValueParameter
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.ksp.addOriginatingKSFile
import com.squareup.kotlinpoet.ksp.toTypeName
import com.squareup.kotlinpoet.ksp.writeTo

Expand Down Expand Up @@ -64,9 +66,13 @@ object PoetFactoryComponentGenerator {
simpleNames = listOf("KoinComponent"),
)

val originatingFile = factoryComponent.containingFile
?: error("Unable to get containing file for ${factoryComponent.qualifiedName?.asString()}")

val componentTypeSpec = createComponentTypeSpec(
factoryClassName = factoryClassName,
koinComponentClass = koinComponentClass,
originatingFile = originatingFile,
createComponentFunction = createComponentFunction(
baseName,
factoryComponentPackageName,
Expand All @@ -76,14 +82,18 @@ object PoetFactoryComponentGenerator {

val fileSpec = createFileSpec(factoryClassName, componentTypeSpec)

fileSpec.writeTo(codeGenerator, aggregating = true)
// Each factory depends only on the annotated component that owns it.
// This lets KSP keep outputs for unchanged components during incremental builds.
fileSpec.writeTo(codeGenerator, aggregating = false)
}

private fun createComponentTypeSpec(
factoryClassName: ClassName,
koinComponentClass: ClassName,
originatingFile: KSFile,
createComponentFunction: FunSpec,
) = TypeSpec.objectBuilder(factoryClassName)
.addOriginatingKSFile(originatingFile)
.addModifiers(KModifier.INTERNAL)
.addSuperinterface(superinterface = koinComponentClass)
.addFunction(createComponentFunction)
Expand Down
Loading