I have simple Java annotation with one parameter:
public @interface Annot {
String value();
}
Also I have Java annotation that takes array of Annot as parameter:
public @interface Annotations {
Annot[] value();
}
I want to generate Annot with paramter "value" using Scala macro like this:
object MyAnnotations {
def MyAnnotation: Annot = macro myAnnotationMacro
def myAnnotationMacro(c: whitebox.Context): c.Expr[Annot] = {
import c.universe._
c.Expr(q"""new Annot("value")""")
}
}
While this works:
@Annotations(Array(
new Annot("value")
))
trait T
This doesn't work:
@Annotations(Array(
MyAnnotations.MyAnnotation
)) // too many arguments for constructor Annot: ()Annot
trait T
Why? And how can I generate Annot?