I have a real beginners question using scala-meta
I want to add annotations to a subset of a case class’s fields based on the name of the the field. The classes and fields to annotate are defined as follows:
val classMapping = Map[String,String](
("com.example.employees","""OntologyContext("http://schema.org")"""),
("Employee.scala","""OntologyType("person")""")
)
val fieldMapping = Map[String,String](
("hello","""OntologyRef("name")"""),
("job","""OntologyRef("title")"""),("id","""Obfuscated""")
)
Before:
package com.example.employees
import java.time.LocalDate
case class Employee(
hello: String,
job:String,
id:String,
employmentDate: Date)
After:
package com.example.employees
import java.time.LocalDate
@OntologyContext(“http://schema.org”)
@OntologyType(“person”)
case class Employee(
@OntologyRef(“name”) hello: String,
@OntologyRef(“title”) job: String,
@Obfuscated() id:String,
employmentDate: Date
)
My question pertains to the syntax of the quasiquotes that are needed in the transform of the tree:
- selecting the indicated field; and
- inserting the annotations
Can you refer me to any examples that can point me in the right direction?