I have the following macro
object Example {
def doIt(s: String): String = macro doItImpl
def doItImpl(c: Context)(s: c.Expr[String]): c.Expr[String] = {
import c.{ universe => u }
import u._
???
}
}
Instead of the ???
I would like to inspect the line where the method doIt
was called to check if the result of the method was used (in an assignment, method call or whatever). If the result is not used I respond with an error-message.
Call-example:
val s: String = doIt("Hallo") // alright
doIt("Hallo") // ERROR!
Is there a simple way to get the Tree of the whole line?
For completeness, here's a lightly adapted version of the solution I mention above:
Now in a REPL:
And in the case that we don't have an definition:
As expected. See the comments on the question linked above for some caveats, but unless your real use case is much more complicated, this approach should work fine.