Scala Macros: Making a Map out of fields of a class in Scala

Note that this can be done much more elegantly without the toString / c.parse business: import scala.language.experimental.macros abstract class Model { def toMap[T]: Map[String, Any] = macro Macros.toMap_impl[T] } object Macros { import scala.reflect.macros.Context def toMap_impl[T: c.WeakTypeTag](c: Context) = { import c.universe._ val mapApply = Select(reify(Map).tree, newTermName(“apply”)) val pairs = weakTypeOf[T].declarations.collect { case m: MethodSymbol … Read more

How to make IntelliJ IDEA recognise code created by macros?

With the latest Scala plugin build, there is an API which can be used to write your own plugin to support your macros: http://blog.jetbrains.com/scala/2015/10/14/intellij-api-to-build-scala-macros-support/ Now, everyone can use this API to make their macros more friendly to their favorite IDE. To do that, you have to implement SyntheticMembersInjector, and register it in the plugin.xml file: … Read more

Where can I learn about constructing AST’s for Scala macros?

There isn’t a lot of documentation for the internals of the compiler available, but the things that are available should be enough to get started. Mirko Stocker, has written his Master Thesis about Scala Refactoring. In Appendix D (p. 95) he describes the architecture of the AST. It includes also a graphical overview: Another way … Read more

Getting a structural type with an anonymous class’s methods from a macro

This question is answered in duplicate by Travis here. There are links to the issue in the tracker and to Eugene’s discussion (in the comments and mailing list). In the famous “Skylla and Charybdis” section of the type checker, our hero decides what shall escape dark anonymity and see the light as a member of … Read more

How to use Shapeless in a Quasiquote?

This is my working solution using old-style macro annotations. import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context import scala.annotation.StaticAnnotation class fieldable extends StaticAnnotation { def macroTransform(annottees: Any*): Any = macro fieldableMacro.impl } object fieldableMacro { def impl(c: Context)(annottees: c.Expr[Any]*): c.Tree = { import c.universe._ annottees.map(_.tree) match { case (param @ q”case class $className(..$fields)”) :: Nil => { val implicits … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)