• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala compileTimeOnly类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中scala.annotation.compileTimeOnly的典型用法代码示例。如果您正苦于以下问题:Scala compileTimeOnly类的具体用法?Scala compileTimeOnly怎么用?Scala compileTimeOnly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了compileTimeOnly类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: CoreMacros

//设置package包名称以及导入依赖的类
package com.outr.arango

import scala.annotation.compileTimeOnly
import scala.language.experimental.macros
import scala.reflect.macros.blackbox

@compileTimeOnly("Enable macro paradise to expand compile-time macros")
object CoreMacros {
  def updateIfModifiable[T](c: blackbox.Context)(value: c.Expr[T])(implicit t: c.WeakTypeTag[T]): c.Expr[T] = {
    import c.universe._

    if (t.tpe <:< typeOf[Modifiable]) {
      c.Expr[T](q"$value.copy(modified = System.currentTimeMillis())")
    } else {
      c.Expr[T](q"$value")
    }
  }
} 
开发者ID:outr,项目名称:scarango,代码行数:19,代码来源:CoreMacros.scala


示例2: Fields

//设置package包名称以及导入依赖的类
package com.scalagen.macros

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.meta._

@compileTimeOnly("@fields not expanded")
class Fields extends StaticAnnotation {
  inline def apply(defn: Any): Any = meta {
    defn match {
      case q"..$mods class SourceContainer (...$paramss) extends $template" =>
          template match {

            case template"{ ..$stats } with ..$ctorcalls { $param => ..$body }" =>

              val newBody = body :+ q"""def fields = this.length """
              val newTemplate = template"{ ..$stats } with ..$ctorcalls { $param => ..$newBody }"

              q"..$mods class SourceContainer (...$paramss) extends $newTemplate"

          }
      case _ => throw new Exception("Thing happened that not work")
    }
  }
} 
开发者ID:hntd187,项目名称:scalagen,代码行数:25,代码来源:Macros.scala


示例3: Macros

//设置package包名称以及导入依赖的类
package com.outr.uberterm

import scala.annotation.compileTimeOnly
import scala.reflect.macros.blackbox

@compileTimeOnly("Enable Macros for expansion")
object Macros {
  def module[M <: UberTermModule](context: blackbox.Context)
                                 (implicit m: context.WeakTypeTag[M]): context.Expr[M] = {
    import context.universe._

    val typeString = m.tpe.toString
    val (preType, postType) = if (typeString.indexOf('.') != -1) {
      val index = typeString.lastIndexOf('.')
      typeString.substring(0, index + 1) -> typeString.substring(index + 1)
    } else {
      "" -> typeString
    }

    val clientTypeString = s"${preType}Client$postType"
    val serverTypeString = s"${preType}Server$postType"
    val clientType = try {
      Some(context.universe.rootMirror.staticClass(clientTypeString))
    } catch {
      case _: ScalaReflectionException => None
    }
    val serverType = try {
      Some(context.universe.rootMirror.staticClass(serverTypeString))
    } catch {
      case exc: ScalaReflectionException => None
    }

    val communicationType = serverType match {
      case Some(t) => t
      case None => clientType match {
        case Some(t) => t
        case None => context.abort(context.enclosingPosition, s"Unable to find implementation trait $clientTypeString or $serverTypeString for $typeString.")
      }
    }

    val application = context.prefix.tree

    context.Expr[M](
      q"""
          val module = new $m()
          module.init()
          module
       """)
  }

  def help(context: blackbox.Context)(): context.Expr[ModuleHelp] = {
    import context.universe._

    val test = context.prefix.tree
    scribe.info(s"Module: ${test.tpe.members}")
//    module.symbol

    context.abort(context.enclosingPosition, "WIP")
  }
} 
开发者ID:outr,项目名称:uberterm,代码行数:61,代码来源:Macros.scala


示例4: Benchmark

//设置package包名称以及导入依赖的类
package io.flatmap.ml.macros

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.meta._

@compileTimeOnly("@Benchmark annotation not expanded")
class Benchmark extends StaticAnnotation {

  inline def apply(defn: Any): Any = meta {
    defn match {
      case q"..$mods def $name[..$tparams](...$argss): $tpeopt = $expr" =>
        println("Parameters: " + argss)
        q"""
          ..$mods def $name[..$tparams](...$argss): $tpeopt = {
           val start = System.nanoTime()
           val result = $expr
           val end = System.nanoTime()
           println(${name.toString} + " elapsed time: " + (end - start) + "ns")
           result
          }
        """
      case _ => abort("@Benchmark annotation works only on methods")
    }
  }

} 
开发者ID:ShokuninSan,项目名称:som,代码行数:27,代码来源:Benchmark.scala


示例5: make

//设置package包名称以及导入依赖的类
package example

import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
import scala.annotation.{StaticAnnotation, compileTimeOnly}

trait Goodbye {
  def make(): Unit
}

class GoodbyeTranslator[C <: Context](val context: C) {
  import context.universe._

  def translate(tree: Tree): Tree = {
    q"""
    new example.Goodbye {
      def make() {
        $tree
        System.exit(0)
      }
    }
    """
  }
}

object GoodbyeTranslator {
  def apply(c: Context): GoodbyeTranslator[c.type] = new GoodbyeTranslator(c)
}

object GoodbyeMacro {
  def impl(c: Context)(arg: c.Expr[Unit]): c.Expr[Goodbye] = {
    val translator = GoodbyeTranslator(c)
    val tree = translator.translate(arg.tree)
    c.Expr[Goodbye](tree)
  }
}

@compileTimeOnly("only for compile time expansion")
object goodbye {
  def apply(arg: Unit): Goodbye = macro GoodbyeMacro.impl
} 
开发者ID:cornerman,项目名称:macroni,代码行数:42,代码来源:Goodbye.scala


示例6: HelloTranslator

//设置package包名称以及导入依赖的类
package example

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

class HelloTranslator[C <: Context](val context: C) {
  import context.universe._

  case class ObjectPattern(name: TermName, parents: List[Tree], body: List[Tree])

  object ObjectPattern {
    def unapply(tree: Tree): Option[ObjectPattern] = tree match {
      case q"object $name extends ..$parents { ..$body }" => Some(ObjectPattern(name, parents, body))
      case _ => None
    }
  }

  def translate(tree: Tree): Tree = tree match {
    case ObjectPattern(pattern) => translate(pattern)
    case _ => context.abort(context.enclosingPosition, "Cannot match object pattern")
  }

  def translate(pattern: ObjectPattern): Tree = {
    import pattern._

    q"""
      object $name extends ..$parents {
        def hello: ${typeOf[String]} = "hello"
        ..$body
      }
    """
  }
}

object HelloTranslator {
  def apply(c: Context): HelloTranslator[c.type] = new HelloTranslator(c)
}

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

    val translator = HelloTranslator(c)
    val trees = annottees.map(_.tree).toList
    val translated = translator.translate(trees.head) :: trees.tail
    c.Expr[Any](q"..$translated")
  }
}

@compileTimeOnly("only for compile time expansion")
class hello extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro HelloMacro.impl
} 
开发者ID:cornerman,项目名称:macroni,代码行数:55,代码来源:Hello.scala


示例7: as

//设置package包名称以及导入依赖的类
package troy.dsl

import scala.annotation.compileTimeOnly

trait ParsingOps {
  type ParseAs[R]
  // $COVERAGE-OFF$
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[R](mapper: () => R): ParseAs[R] = ???
  // (1 to 22).map(1 to _).map(_.map(i => s"T$i").mkString(", ")).map(tstr => s"def as[$tstr, R](mapper: ($tstr) => R): MacroDSL[M[R]]").foreach(println)
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, R](mapper: (T1) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, R](mapper: (T1, T2) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, R](mapper: (T1, T2, T3) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, R](mapper: (T1, T2, T3, T4) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, R](mapper: (T1, T2, T3, T4, T5) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, R](mapper: (T1, T2, T3, T4, T5, T6) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, R](mapper: (T1, T2, T3, T4, T5, T6, T7) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R): ParseAs[R] = ???
  // $COVERAGE-ON$
} 
开发者ID:schemasafe,项目名称:troy,代码行数:57,代码来源:ParsingOps.scala


示例8: as

//设置package包名称以及导入依赖的类
package troy.meta

import scala.annotation.compileTimeOnly

trait ParsingOps {
  type ParseAs[R]

  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[R](mapper: () => R): ParseAs[R] = ???
  // (1 to 22).map(1 to _).map(_.map(i => s"T$i").mkString(", ")).map(tstr => s"def as[$tstr, R](mapper: ($tstr) => R): MacroDSL[M[R]]").foreach(println)
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, R](mapper: (T1) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, R](mapper: (T1, T2) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, R](mapper: (T1, T2, T3) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, R](mapper: (T1, T2, T3, T4) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, R](mapper: (T1, T2, T3, T4, T5) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, R](mapper: (T1, T2, T3, T4, T5, T6) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, R](mapper: (T1, T2, T3, T4, T5, T6, T7) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R): ParseAs[R] = ???
  @compileTimeOnly("as can be called only inside troy.dsl.withSchema block")
  def as[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](mapper: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R): ParseAs[R] = ???
} 
开发者ID:schemasafe,项目名称:troy,代码行数:56,代码来源:ParsingOps.scala


示例9: RichStringContext

//设置package包名称以及导入依赖的类
package troy

import com.datastax.driver.core.{ Row, ResultSet, Statement }

import scala.annotation.compileTimeOnly
import scala.concurrent.Future

package object meta {
  implicit class RichStringContext(val context: StringContext) extends AnyVal {
    @compileTimeOnly("cql Strings can be used only inside troy.dsl.withSchema block")
    def cql(args: Any*): MacroDSL.TroyCql = ???
  }

  implicit class MacroDsl_RichStatement(val statement: Statement) extends ParsingOps {
    type ParseAs[R] = Future[Seq[R]]
  }

  implicit class MacroDsl_RichFutureBoundStatement(val xxx: Future[Statement]) extends ParsingOps {
    type ParseAs[R] = Future[Seq[R]]
  }

  implicit class MacroDsl_RichResultSet(val xxx: ResultSet) extends ParsingOps {
    type ParseAs[R] = Seq[R]
  }

  implicit class MacroDsl_RichFutureOfResultSet(val xxx: Future[ResultSet]) extends ParsingOps {
    type ParseAs[R] = Future[Seq[R]]
  }

  implicit class MacroDsl_RichFutureOfSeqOfRow(val xxx: Future[Seq[Row]]) extends ParsingOps {
    type ParseAs[R] = Future[Seq[R]]
  }

  implicit class MacroDsl_RichFutureOfOptionOfRow(val xxx: Future[Option[Row]]) extends ParsingOps {
    type ParseAs[R] = Future[Option[R]]
  }

  implicit class MacroDsl_RichSeqOfRow(val xxx: Seq[Row]) extends ParsingOps {
    type ParseAs[R] = Seq[R]
  }

  implicit class MacroDsl_RichJavaListOfRow(val xxx: java.util.List[Row]) extends ParsingOps {
    type ParseAs[R] = Seq[R]
  }

  implicit class MacroDsl_RichOptionOfRow(val xxx: Option[Row]) extends ParsingOps {
    type ParseAs[R] = Option[R]
  }
} 
开发者ID:schemasafe,项目名称:troy,代码行数:50,代码来源:package.scala


示例10: Macros

//设置package包名称以及导入依赖的类
package com.qvantel.jsonapi

import scala.annotation.compileTimeOnly
import scala.reflect.macros.blackbox.Context

import com.qvantel.jsonapi.macrosupport.{JsonApiReaders, JsonApiWriters}


@compileTimeOnly("Macros can only be used at compile-time")
final class Macros(val c: Context) extends JsonApiWriters with JsonApiReaders {
  import c.universe._

  private[this] def createFormat(t: c.Type): c.Tree = {
    val rootParamName     = TermName(c.freshName("root"))
    val includedParamName = TermName(c.freshName("included"))
    val includePaths      = TermName(c.freshName("includePaths"))
    val includePath       = TermName(c.freshName("includePath"))
    q"""new _root_.com.qvantel.jsonapi.JsonApiFormat[$t] with _root_.spray.json.RootJsonFormat[$t] {
          import _root_.com.qvantel.jsonapi.PathJsonFormat
          override final def write($rootParamName: $t): _root_.spray.json.JsValue = ${primaryDataWriter(t,
                                                                                                        rootParamName)}
          override final def included($rootParamName: $t): _root_.scala.collection.immutable.Set[_root_.spray.json.JsObject] = ${includedWriter(
      t,
      rootParamName)}
          override final def read(
            $rootParamName: _root_.spray.json.JsValue,
            $includedParamName: _root_.scala.collection.immutable.Map[(String, String), _root_.spray.json.JsObject],
            $includePaths: _root_.scala.collection.immutable.Set[String],
            $includePath: String
          ): $t = ${reader(t, rootParamName, includedParamName, includePaths, includePath)}
        }"""
  }

  def createIncludes[A: c.WeakTypeTag]: c.Tree = {
    val t = weakTypeOf[A]

    val includeParamName    = TermName(c.freshName())
    val includeMapParamName = TermName(c.freshName())
    q"""
      new _root_.com.qvantel.jsonapi.Includes[$t] {
        private[this] final lazy val $includeMapParamName: Map[String, _root_.com.qvantel.jsonapi.Includes[_]] = ${includesMap(
      t)}
        override def includeAllowed($includeParamName: String): Boolean = ${includeAllowed(t,
                                                                                           includeParamName,
                                                                                           includeMapParamName)}
      }
      """
  }

  def jsonApiWriterWithNoNameManglingImpl[A: c.WeakTypeTag]: c.Tree = createWriter(weakTypeOf[A])
  def jsonApiFormatWithNoNameManglingImpl[A: c.WeakTypeTag]: c.Tree = createFormat(weakTypeOf[A])
} 
开发者ID:qvantel,项目名称:jsonapi-scala,代码行数:53,代码来源:Macros.scala


示例11: inl

//设置package包名称以及导入依赖的类
package com.qvantel.jsonapi.macrosupport

import scala.annotation.compileTimeOnly
import scala.reflect.macros.blackbox.Context
import shapeless.{CNil, Coproduct}

@compileTimeOnly("Macros can only be used at compile-time")
trait Tools {
  val c: Context
  import c.universe._

  private[this] val coproductType = typeOf[Coproduct]
  private[this] val coproductNil  = typeOf[CNil]

  private[this] def inl(name: TermName): c.Tree = {
    val bind = pq"$name"
    q"_root_.shapeless.Inl($bind)"
  }

  private[this] def inr(tree: c.Tree): c.Tree = q"_root_.shapeless.Inr($tree)"

  def coproductTypes(t: c.Type): List[c.Type] = {
    def go(ta: List[c.Type], acc: List[c.Type]): List[c.Type] =
      ta match {
        case Nil                                 => acc
        case l :: r :: Nil if r =:= coproductNil => acc :+ l
        case l :: r :: Nil                       => go(r.dealias.typeArgs, acc :+ l)
      }

    if (t <:< coproductType) {
      go(t.dealias.typeArgs, Nil)
    } else {
      c.abort(c.enclosingPosition, s"The type $t must be a shapeless.Coproduct")
    }
  }

  def coproductPattern(n: Int, name: TermName): c.Tree =
    (1 until n).foldLeft(inl(name))((tree, _) => inr(tree))

  def coproductPatterns(nTypes: Int, name: TermName): Seq[c.Tree] =
    (1 to nTypes).map(coproductPattern(_, name))
} 
开发者ID:qvantel,项目名称:jsonapi-scala,代码行数:43,代码来源:Tools.scala


示例12: BaseMacros

//设置package包名称以及导入依赖的类
package org.hyperscala

import com.outr.reactify.Channel

import scala.annotation.compileTimeOnly
import scala.reflect.macros.blackbox

@compileTimeOnly("Enable macro paradise to expand macro annotations")
object BaseMacros {
  def appPickler[T](c: blackbox.Context)(implicit t: c.WeakTypeTag[T]): c.Expr[Channel[T]] = {
    import c.universe._

    val app = q"${c.prefix.tree}"
    c.Expr[Channel[T]](
      q"""
          val pickler = new org.hyperscala.Pickler[$t]($app) {
            override def read(json: String): $t = upickle.default.read[$t](json)
            override def write(t: $t): String = upickle.default.write[$t](t)
          }
          pickler.channel
       """
    )
  }

  def screenPickler[T](c: blackbox.Context)(implicit t: c.WeakTypeTag[T]): c.Expr[Channel[T]] = {
    import c.universe._

    val app = q"${c.prefix.tree}.app"
    c.Expr[Channel[T]](
      q"""
          val pickler = new org.hyperscala.Pickler[$t]($app) {
            override def read(json: String): $t = upickle.default.read[$t](json)
            override def write(t: $t): String = upickle.default.write[$t](t)
          }
          pickler.channel
       """
    )
  }

  def communicationPickler[T](c: blackbox.Context)(implicit t: c.WeakTypeTag[T]): c.Expr[Channel[T]] = {
    import c.universe._

    val communication = q"${c.prefix.tree}"
    c.Expr[Channel[T]](
      q"""
          val pickler = new org.hyperscala.Pickler[$t]($communication) {
            override def read(json: String): $t = upickle.default.read[$t](json)
            override def write(t: $t): String = upickle.default.write[$t](t)
          }
          pickler.channel
       """
    )
  }
} 
开发者ID:outr,项目名称:hyperscala,代码行数:55,代码来源:BaseMacros.scala


示例13: helloMacro

//设置package包名称以及导入依赖的类
package codes.bytes.macros_intro.macros

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

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

    val result = {
      annottees.map(_.tree).toList match {
        case q"object $name extends ..$parents { ..$body }" :: Nil =>
          q"""
            object $name extends ..$parents {
              def hello: ${typeOf[String]} = "hello"
              ..$body
            }
          """
      }
    }
    c.Expr[Any](result)
  }
}

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

// vim: set ts=2 sw=2 sts=2 et: 
开发者ID:bwmcadams,项目名称:supreme-macro-adventure,代码行数:32,代码来源:AnnotationMacro.scala


示例14: Bootstrap

//设置package包名称以及导入依赖的类
package ng.macros

import be.doeraene.sjsreflect.Reflect

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.meta._


@compileTimeOnly("@Bootstrap not expanded")
class Bootstrap extends StaticAnnotation {
  inline def apply(defn: Any): Any = meta {

    val q"object $tname extends ..$parents { ..$stats }" = defn

    // should evaluate something like:
    // app.AppModule.annotations = app.AppModule_().annotations
    // for every class that extends NGAnnotations
    val propertyApplication =
      q"""
         be.doeraene.sjsreflect.Reflect
         .enumerateClasses
         // gets the fully qualified class-name
         .map(_.getName)
         .withFilter(_ != "ng.macros.NGAnnotation")
         .foreach(className => {
           val objName = "annots." + className.split('.').last + "_()"

           val expr =
           s"$$className.annotations = $$objName.annotations; $$className.parameters = $$objName.parameters"

           scalajs.js.eval(expr)
         })
       """


    q"object $tname extends ..$parents { $propertyApplication; ..$stats }"
  }
} 
开发者ID:AugustNagro,项目名称:scalajs-ng,代码行数:39,代码来源:Bootstrap.scala


示例15: before

//设置package包名称以及导入依赖的类
package nz.daved.elysium.core

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import nz.daved.elysium.manipulate.DefManipulation._

import scala.meta.Defn.Def
import scala.meta._

@compileTimeOnly("@before not expanded")
class before(fun: () => Unit) extends StaticAnnotation {
  inline def apply(defn: Any): Any = meta {
    val q"new $_(${apply: Term.Apply})" = this
    defn.asInstanceOf[Def].prependStat(apply)
  }
}

@compileTimeOnly("@after not expanded")
class after(fun: () => Unit) extends StaticAnnotation {
  inline def apply(defn: Any): Any = meta {
    val q"new $_(${apply: Term.Apply})" = this
    defn.asInstanceOf[Def].appendStat(apply)
  }
} 
开发者ID:DavidDudson,项目名称:Elysium,代码行数:24,代码来源:Decorator.scala



注:本文中的scala.annotation.compileTimeOnly类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala TException类代码示例发布时间:2022-05-23
下一篇:
Scala KafkaUtils类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap