I'm writing an annotation processor that generates a JSON file containing some data read from the annotations (easy) and the file path where these annotations are used.
Problem: I cannot figure out how to get the file corresponding to a TypeElement (which is the annotated element).
I found that the TreePath api should do this:
val instance = Trees.instance(processingEnv)
instance.getPath(element)
but it seems that com.sun.source.util.Trees is not available in the jdk version we use (AdoptOpenJDK OpenJDK Runtime Environment 1.8.0_242-b08)
I also tried with
val compiler: JavaCompiler = ToolProvider.getSystemJavaCompiler()
val fm = compiler.getStandardFileManager(null, null, null)
val locations = fm.getJavaFileObjects(element.toString())
println(locations.first().toUri())
but it doesn't give me a valid path to the file.
Any other hint?