Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A good idea is to use annotation processing with reflekt for the configuration #79

Closed
akuleshov7 opened this issue Nov 6, 2021 · 3 comments

Comments

@akuleshov7
Copy link
Owner

https://github.com/JetBrains-Research/reflekt

@Peanuuutz
Copy link
Contributor

Peanuuutz commented Jan 14, 2022

I think @SerialInfo from kotlinx.serialization could make it, like this:

@SerialInfo
@Target(AnnotationTarget.PROPERTY)
public annotation class Comment(vararg val texts: String)

// Model class
data class Account(
    val username: String,
    @Comment("Don't tell others!")
    val password: String
)

// In Encoder
fun comment(descriptor: SerialDescriptor, index: Int) {
    descriptor.getElementAnnotations(index)
        .filterIsInstance<Comment>()
        .map {
            if (it.isEmpty())
                emptyArray<String>()
            else
                it[0].texts // As Comment is not @Repeatable, we take the first
        }
        .forEach(writer::emitComment) // functional YES!
}

@NightEule5
Copy link
Collaborator

Yes, I think this is covered by kotlinx.serialization already. I'm not sure what functionality Reflekt would provide that we don't have access to, but I could be missing something

@akuleshov7
Copy link
Owner Author

Yeah, it looks so. I actually wanted to add some custom annotations for compile time reflection, but yes Kotlinx.serialization already has mostly everything we need. May be we will use reflekt for something else next time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants