NOTICE - This project has moved.
It is now part of Foursquare's open source monorepo Fsq.io and all future work will be published there.
The project lives on but this Github repo is deprecated.
simple-macros
A collection of simple Scala macros
Adding simple macros to your build
The project is compiled for Scala 2.10.4. In your build.sbt, add:
"com.foursquare" %% "simple-macros" % "0.6"
How to build
./sbt compile
./sbt test
How to use
CodeRef Example
import com.foursquare.macros.CodeRef
import com.foursquare.macros.CodeRef._
// Explicit call. here now contains the
// current file (path relative to compiler wd)
// and line number
val here: CodeRef = CODEREF
// Implicit reference to caller. Gives you the
// line from which the method was called without
// taking a stack trace.
def foo(bar: Int)(implicit caller: CodeRef) {
println("called foo(" + bar + ") at " + caller)
}
foo(1)
StackElement Example
import com.foursquare.macros.StackElement
import com.foursquare.macros.StackElement._
// Explicit call. here now contains the
// standard StackTraceElement (implicit from StackElement -> StackTraceElement)
scala> val here: StackTraceElement = STACKELEMENT
// Implicit reference to caller. Gives you the
// StackTraceElement from which the method was called without
// taking a stack trace.
def foo(bar: Int)(implicit caller: StackElement) {
println("called foo(" + bar + ") at " + caller)
}
foo(2)
Contributors
- Jeff Jenkins
- John Gallagher