Is it possible to determine if an annotation value...
# ksp
j
Is it possible to determine if an annotation value is present because it was the default or if it was set manually?
g
How is it possible to set an annotation by "default"? What does that mean?
j
I think it means when you define an annotation class, you can specify a default value for the annotation value arguments.
👍 1
j
Correct
In Micronaut we support the notion of an argument that is actually set vs a default value
I’ve determined the likely way to determine this is through the constructor of the annotation, however I don’t know how to get the default values from the parameters. Any ideas @Jiaxiang?
j
I can think of it, but what is the usage of that? I feel like you have all you need with getting the value itself, it shouldn’t matter whether it comes from a default value or defined in the code?
j
its more efficient to store the default values from annotations once instead of each time they are used
so its split out that way to reduce memory usage
Micronaut stores annotation data in our own API that is accessible at runtime so no runtime reflection is necessary to retrieve that info
j
to store it I will need a flag in KSP to determine if a value is present in code, or alternatively do a computation every time user query it, either sacrifices space or time efficiency in my opinion.
also we don’t actually do runtime reflection to get the annotation value, if reflection is your concern.
j
reflection is a concern for us at runtime, not compile time
So are you saying that it isn’t possible with the current version of KSP?
j
it isn’t possible in current version, I can see it is doable but need more context on the necessity of this use case.
j
A boolean on KSValueArgument
isDefaultValue
or something of the sort would be sufficient I believe
perhaps not actually
j
I would call it
isPresent
since user can still write a value equal to default value, and I think you are more interested in if user has written the value or not, rather than the actual value
j
I’ll create an issue
👍 1