AntonButov / AntonButov/code-factory

The factory have not all types in AI request.

Đang mở
#159 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug pr welcome
Ngôn ngữ chính
Kotlin
Star
4
Fork
1
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

```
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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.