Macros in Scala: moderately complex example
I recently began to discover the power of newly-added macros in Scala. While they are still labeled as "experimental" , they already pack quite a punch. Most tutorials on the web usually use some simple examples - like assert macro , or debugging helper . In this post, I'll try to make a bit deeper dive into the subject, in hope that I will be able to explore darker corners of macro engineering. The use-case for today's macro is actually something I needed in one of my real projects - I had complex hierarchy of case classes, and I wanted a quick way to visualize it (without needing to read mile-long text files). So I created a macro, that takes case class, and creates a frame with JTree containing the hierarchy of case class members. Example use-case for the macro looks as follows: case class Author(name: String, birthYear: Int) case class Book(title: String, authors: List[Author]) val hobbit = Book("Hobbit: There And Back Again", List(Author(...