https://kotlinlang.org logo
#android
Title
# android
f

fanie

12/27/2018, 12:49 PM
Question: How can one annotate properties in a Kotlin interface and handle them with an Annotation processor? What for? I am developing an Annotation and code generation based library for Android shared preferences. The idea is to decorate properties in an interface and generate the code needed to store and retrieve those properties to and from the SharedPreferences. Simply decorating does not seem to work; the processor can't find any of the target properties. The current workaround is using functions instead of properties. Properties would be so much better and technically sound though. The project is the following in case you want to have a look: https://github.com/iFanie/ConfigurNation
l

louiscad

12/28/2018, 9:12 AM
@fanie You can do this with delegated properties. You can see the implementation of this library I made: https://github.com/LouisCAD/Splitties/tree/master/preferences
f

fanie

12/28/2018, 10:01 AM
@louiscad thanks for the suggestion, but that is a very different approach. My concern is that I can't seem to access decorated abstract properties from the Annotation processor.
l

louiscad

12/28/2018, 11:07 AM
Yes it is, but it can work with interface abstraction, without hacking into annotation processors (which also have an impact on build time)
f

fanie

12/28/2018, 1:06 PM
@louiscad still, I'm not looking for that though. I can't seem to get the processor to see the annotated abstract variables