Is it possible to implement something similar to Scala @BeanProperty with macros?

I would like to create an annotation or trait that dynamically adds methods to the object at compile time based on existing fields. Although I'm interested in something at the class level, I would also work with annotations at the field level (or with something even more granular).

An older stack overflow question asking for information about the Scala @BeanProperty implementation answered: "This is a compiler plugin, but macros may also allow you to do this." Given the official (if experimental) release of macros in Scala 2.10, is this possible?

+7
source share
1 answer

Update: This answer is no longer valid. See Comment by Eugenes.

No, this is not yet possible.

In 2.10, there is only def macros that cannot match anything. For 2.11, the world is a little better; macros and implementation to introduce participants to classes already exist. But they are only a few weeks old, and therefore they will only work in some cases. In addition, the implementation for introducing members into classes lives in a different branch than the implementation for macros, so it is not yet possible to use them.

+8
source

All Articles