How do I generate new source code in text form in a Scala compiler plugin?

前端 未结 2 1196
不思量自难忘°
不思量自难忘° 2021-02-09 03:24

I have just finished the first version of a Java 6 compiler plugin, that automatically generates wrappers (proxy, adapter, delegate, call it what you like) based on an annotatio

2条回答
  •  情歌与酒
    2021-02-09 03:56

    Kevin is entirely correct, but just for completeness it's worth mentioning that there is another alternative - write a compiler plugin that generates source. This is the approach that I've adopted in Borachio. It's not a very satisfactory solution, but it can be made to work.

    Edit - I just reread your question and realised that you're actually asking about generating source anyway

    So there is no support for this directly, but it's basically just a question of opening a file and writing the relevant "print" statements. There's no way to invoke the compiler "inside" a plugin AFAIK, but I've written an sbt plugin which hides most of the complexity of invoking the compiler twice.

提交回复
热议问题