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

minitest.macros.SourceLocationMacros.scala Maven / Gradle / Ivy

The newest version!
package minitest.macros

import scala.quoted._

import minitest.api.SourceLocation

object SourceLocationMacros {
  def impl()(using Quotes): Expr[SourceLocation] = {
    import quotes.reflect._
    val pos = Position.ofMacroExpansion
    val path = pos.sourceFile.jpath
    val startLine = pos.startLine + 1
    '{
      SourceLocation(
        ${Expr(Some(path.getFileName.toString))},
        ${Expr(Some(path.toString))},
        ${Expr(startLine)}
      )
    }
  }
}

trait SourceLocationMacros {
  inline implicit def fromContext: SourceLocation =
    ${ SourceLocationMacros.impl() }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy