Scala Language Macro Annotation


This simple macro annotation outputs the annotated item as-is.

import scala.annotation.{compileTimeOnly, StaticAnnotation}
import scala.reflect.macros.whitebox.Context

@compileTimeOnly("enable macro paradise to expand macro annotations")
class noop extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro linkMacro.impl

object linkMacro {
  def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
    import c.universe._


The @compileTimeOnly annotation generates an error with a message indicating that the paradise compiler plugin must be included to use this macro. Instructions to include this via SBT are here.

You can use the above-defined macro like this:

case class Foo(a: String, b: Int)

object Bar {
  def f(): String = "hello"

def g(): Int = 10