Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File
- import language.experimental.macros
- import scala.reflect.macros.Context
- object Macros {
- def L_ : Int = macro lineImpl
- def lineImpl( c: Context ): c.Expr[Int] = {
- import c.universe._
- val line = Literal( Constant( c.enclosingPosition.line ) )
- c.Expr[Int]( line )
- }
- def F_ : String = macro fileImpl
- def fileImpl( c: Context ): c.Expr[String] = {
- import c.universe._
- val absolute = c.enclosingPosition.source.file.file.toURI
- val base = new File( "." ).toURI
- val path = Literal( Constant( c.enclosingPosition.source.file.file.getName() ) )
- c.Expr[String]( path )
- }
- def C_ : String = macro classImpl
- def classImpl( c: Context ): c.Expr[String] = {
- import c.universe._
- val class_ = Literal( Constant( c.enclosingClass.toString.split(" ")( 1 ) ) )
- c.Expr[String]( class_ )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement