androidkotlinkotlin-symbol-processing

Can we read value of a variable in a class using KSP?


I have a class which has some variables, can we use kotlin symbol processing api to somehow read the value of the variable declared in the class?

resolver.getDeclarationsFromPackage("com.example")
            .filter { it is KSClassDeclaration }
            .iterator().forEach {
                val cls = it as KSClassDeclaration
                cls.getDeclaredProperties().first()
                }

Solution

  • As of today, KSP doesn't provide the functionality to read the content of the values. However, an exception to this limitation is for Annotation classes, where you can read the arguments values.