All Downloads are FREE. Search and download functionalities are using the official Maven repository.

japgolly.microlibs.compiletime.WhiteboxMacros.scala Maven / Gradle / Ivy

The newest version!
package japgolly.microlibs.compiletime

import scala.annotation.nowarn

abstract class WhiteboxMacroUtils extends MacroUtils {
  val c: scala.reflect.macros.whitebox.Context
  import c.universe._

  def extractStaticAnnotationArgs: List[Tree] =
    c.macroApplication match  {
      case Apply(Select(Apply(_, args), _), _) => args
      case x => fail(s"Unable to determine annotation args.\n${showRaw(x)}")
    }

  @nowarn("cat=unused")
  def replaceEmptyBodyInAnnotatedObject(annottees: Seq[c.Expr[Any]])(newBody: List[Tree]): Tree =
    annottees.map(_.tree) match {
      case List(q"object $objName extends $parent { ..$body }") if body.isEmpty =>
        q"object $objName extends $parent { ..$newBody }"
      case _ => fail("You must annotate an object definition with an empty body.")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy