Setting positions for annotation generated trees
Torsten Schmits <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
I use annotations on objects to generate a lot of code from very little code, so I'd like to have a way to match compiler errors from the generated code to a location in that code. It's easy to print the expanded tree to a file using `showCode`, but the compiler doesn't know about that, of course. Alas, I recurse into the generated tree at the very end of the expansion and update the position to use the written source file, but it's quite hard to determine the correct offset for the individual trees. Right now, I'm doing it heuristically, treating Template and DefDef differently, which is fine, but if there is something off, the compiler doesn't use the debug printed file for determination of error context and line number, but the file where the macros annotation is, although the file name specified is correct. It worked a few times, though with incorrect offsets. My question is, is there an easier way to do this? Like, can I use the compiler api inside of a macro expansion to do this? Also, is there a sensible way to set the position attributes? Right now, I use runtime reflection on the `Position.withSource` and `Tree.setPos` methods and the `SourceFile.file` field. -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.