AntonButov / AntonButov/code-factory

The factory have not all types in AI request.

Abierto
#159 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug pr welcome
Lenguaje dominante
Kotlin
Estrellas
4
Forks
1
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

```
w: [ksp] Request: ---->
You had to implement interface: ComponentTypeFinder Return only code implementation please.
package usecases
import com.google.devtools.ksp.processing.Resolver
import dagger.dsl.core.ComponentType
interface ComponentTypeFinder {
fun findByName(
resolver: Resolver,
name: String,
): ComponentType
}
package usecases
import compile
import dagger.dsl.core.ComponentTypeMethod
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
class ComponentTypeFinderTest: BehaviorSpec ({
Given("component type name is SimpleComponent and code") {
val componentTypeName = "SimpleComponent"
val code = """
interface SimpleComponent {
fun foo(): String
}
""".trimIndent()
When("findByName") {
Then("should return the component type") {
code.compile { resolver ->
val componentTypeFinder: ComponentTypeFinder = ComponentTypeFinderImpl()
val componentType = componentTypeFinder.findByName(resolver, componentTypeName)
componentType.name shouldBe "SimpleComponent"
componentType.methods shouldBe listOf(
ComponentTypeMethod(
name = "foo",
params = emptyList(),
returnType = "String"
)
)
}
}
}
}
}
)
Response: <----
Sure, here's a basic example of how the implementation could look like:
```kotlin
class ComponentTypeFinderImpl : ComponentTypeFinder {
override fun findByName(resolver: Resolver, name: String): ComponentType {
val symbol = resolver.getClassDeclarationByName(resolver.getKSNameFromString(name)) ?: return null
val functionSymbols = symbol.getDeclaredFunctions()
val methods = functionSymbols.mapNotNull { functionSymbol ->
val returnType = functionSymbol.returnType?.resolve()?.declaration?.simpleName?.asString() ?: return null
val parameters = functionSymbol.parameters.map { it.name.asString() to it.type.resolve().declaration.simpleName.asString() }
ComponentTypeMethod(name = functionSymbol.simpleName.asString(), params = parameters, returnType = returnType)
}
return ComponentType(name = symbol.simpleName.asString(), methods = methods)
}
}
```
```
data class ComponentType(
val name: String,
val methods: List,
)

data class ComponentTypeMethod(
val name: String,
val params: List,
val returnType: String?,
)

data class Params(
val name: String,
val type: String,
)
```
not presnt

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.