
os.web.angular.Injectable.scala Maven / Gradle / Ivy
The newest version!
// Copyright AGPL3 2015 ~ Optersoft SL
package os.web.angular
import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.scalajs.js
// Angular's @Injectable annotation
class Injectable extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro Injectable.Macro.impl
}
object Injectable {
private class Macro(val c: whitebox.Context) extends JsWhiteboxMacroTools {
import c.universe._
def impl(annottees: c.Expr[Any]*): c.Expr[Any] = annottees.map(_.tree).toList match {
case (classDecl: ClassDef) :: Nil => modifiedClassDecl(classDecl)
case _ => c.abort(c.enclosingPosition, "Invalid annottee for @Injectable")
}
def modifiedClassDecl(classDecl: ClassDef) = {
val parts = extractClassParts(classDecl)
import parts._
val tree =
q"""{@scalajs.js.annotation.JSExport($fullName)
@scalajs.js.annotation.JSExportAll
class $name ( ..$params ) extends ..$parents { ..$body }
}"""
c.Expr(tree)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy