Consider the following annotation:
// ok to have more meta
@field
@param
@compileTimeOnly("Only for code generation")
case class Annot(value: String) extends ConstantAnnotation
Now three uses:
case class A(x: Int, @Annot("z") y: String)
object A:
def f1(x: Int, y: String @Annot("z")): A = ???
def f2(x: Int, @Annot("z") y: String): A = ???
I would like to use Scala 3 macros to find each of these annotations.
- Case Class:
Symbol.caseFields
gives me the list of parameters, and on each of those parameters (of typeSymbol
), methodannotations
gives me what I am looking for. - Annotated Type: Each param is a
ValDef
. Ifparam.tpt.tpe
matchesAnnotatedType(tpe, t)
thent
is the annotation that I am looking for. - Annotated method argument: I HAVE NOTHING!
Any idea how I can get the annotations that are given to an argument in a method? When I print terms/symbols/trees/... I cannot even see "z" in this case.