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

mdoc.internal.sourcecode.Macros.scala Maven / Gradle / Ivy

There is a newer version: 2.6.3
Show newest version
package mdoc.internal.sourcecode

import scala.language.implicitConversions
import scala.quoted._

trait StatementMacro {
  inline implicit def generate[T](v: => T): SourceStatement[T] = ${ Macros.text('v) }
  inline def apply[T](v: => T): SourceStatement[T] = ${ Macros.text('v) }
}

object Macros {

  def text[T: Type](v: Expr[T])(using ctx: Quotes): Expr[SourceStatement[T]] = {
    import ctx.reflect.{_, given}
    val txt = v.asTerm.pos.sourceCode.getOrElse("")
    '{ SourceStatement[T]($v, ${ Expr(txt) }) }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy