1

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:

  1. selecting the indicated field; and
  2. inserting the annotations

Can you refer me to any examples that can point me in the right direction?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
iandebeer
  • 227
  • 2
  • 8

3 Answers3

0

If i understand correctly, this is not currently possible. Scala-meta annotation macros do not support parameters yet https://github.com/scalameta/paradise/issues/11

David Dudson
  • 116
  • 9
0

Now it's supported with scala.meta 1.1.0 and macro paradise 3.0.0-M5

Still having problems with named parameters

Community
  • 1
  • 1
-1

Note: the latest IntelliJ IDEA 2016.3 (Dec. 2016) should help using those quasiquotes, since they are now supported:

Another major plugin improvement is the support for scala.meta – the new metaprogramming toolkit designed to succeed scala.reflect.
IntelliJ IDEA supports new-style macro annotations and provides coding assistance for scala.meta quasiquotes.

https://d3nmt5vlzunoa1.cloudfront.net/scala/files/2016/11/image00.png

The new plugin version brings you gutter icons for scala.meta macro annotations. Clicking these icons expands the corresponding annotations.
IntelliJ IDEA automatically detects when annotations change and prompts you to recompile them via the gutter icon (or the standard Recompile action.)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250