I need API advice for new Konsist feature. Assumin...
# konsist
i
I need API advice for new Konsist feature. Assuming we have this code snippet...
Copy code
@SampleAnnotation("some_text", 1)
...and Konsist that parses it and exposes to the developer.
Copy code
...
   .annotations
   .arguments
   .map { it.value }
How the first argument be represented in the list of arguments? • 🅰️
""some_text"", "1"
🅱️
"some_text", "1"
Please vote with emojis
🅱️ 4
e
Is this an ArrayList of strings? Do we lose the integer type of the second argument?
i
Yes. This is the dilemma here.
e
Can't it be kept as an integer? If there's no way to keep it as an integer, without the quotes we lose valuable information. I wonder if everyone who voted B was clear on that.
i
This is actually a good point - array could store different types
👍 1
e
Why not just
List<Any>
? then you can do
arguments[1] as? Integer
checks etc
I also added an ext fun for checking my annotations:
Copy code
inline fun <reified A : Any> KoAnnotationProvider.hasAnnotation(predicate: (KoAnnotationDeclaration) -> Boolean) =
    hasAnnotationsOf(A::class) && predicate(annotations.first { it.fullyQualifiedName == A::class.java.name })
then I can use it like this:
Copy code
@Test
    fun `classes annotated with @RestController should produce application json`() {
        classesAnnotatedWith<RestController>()
            .assert { controller ->
                controller.hasAnnotation<RequestMapping> { requestMapping ->
                    requestMapping.text.contains("APPLICATION_JSON_VALUE")
                }
            }
    }